LoginSignup
0
0

More than 5 years have passed since last update.

Domo のデータセットの一覧を取得する (go)

Last updated at Posted at 2018-02-25

こちらのプログラムを go で書きました。
Python で Domo のデータセットの一覧を取得する

get_list.go
// ----------------------------------------------------------------
/*
    get_list.go

                    Feb/25/2018
*/
// ----------------------------------------------------------------
package main
import (
    "fmt"
    "os"
    "log"
    "io/ioutil"
    "net/http"
)

// ----------------------------------------------------------------
func list_dataset_proc (access_token string) {
    fmt.Fprintf (os.Stderr,"*** list_dataset_proc ***\n")

    url_datasets :="https://api.domo.com/v1/datasets"
    url_datasets += "?sort=name&offset=0&limit=50"

    req, _ := http.NewRequest("GET", url_datasets, nil)
    req.Header.Set("Authorization", "Bearer " +  access_token)

    client := new(http.Client)
    resp, err := client.Do(req)

    if err != nil {
        log.Fatalln(err)
        fmt.Printf("%s", err)
        os.Exit(1) 
    } else {
        defer resp.Body.Close()
        contents, err := ioutil.ReadAll(resp.Body)
        if err != nil {
            fmt.Printf("%s", err)
            os.Exit(1)
            }

        json_str := string(contents)
        fmt.Printf("%s\n", json_str)
        }
}

// ----------------------------------------------------------------
func main() {
    fmt.Fprintf (os.Stderr,"*** 開始 ***\n")

    access_token := get_token_proc ()

    fmt.Fprintf(os.Stderr,"%s\n", access_token)

    list_dataset_proc (access_token)

    fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}

// ----------------------------------------------------------------

get_token.go はこちらです。
Domo の アクセストークンを取得する (go)

Makefile
get_list: get_list.go get_token.go
    go build get_list.go get_token.go
clean:
    rm -f get_list
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0