Skip to content

Instantly share code, notes, and snippets.

@jayco
Last active July 28, 2021 00:01
Show Gist options
  • Save jayco/489aeb1fe447c0202b4205eeeaf0e505 to your computer and use it in GitHub Desktop.
Save jayco/489aeb1fe447c0202b4205eeeaf0e505 to your computer and use it in GitHub Desktop.
test-buildkite-go
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/buildkite/go-buildkite/v2/buildkite"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
apiToken = kingpin.Flag("token", "API token").Required().String()
debug = kingpin.Flag("debug", "Enable debugging").Bool()
)
func main() {
kingpin.Parse()
config, err := buildkite.NewTokenConfig(*apiToken, *debug)
if err != nil {
log.Fatalf("client config failed: %s", err)
}
client := buildkite.NewClient(config.Client())
token, _, err := client.AccessTokens.Get()
// b, _ := ioutil.ReadAll(resp.Body)
// var pretty bytes.Buffer
// json.Indent(&pretty, b, "", "\t")
if err != nil {
log.Fatalf("json encode failed: %s", err)
}
data, err := json.MarshalIndent(token, "", "\t")
fmt.Fprintf(os.Stdout, "%s", string(data))
// fmt.Fprintf(os.Stdout, "%s", &pretty)
}
@jayco
Copy link
Author

jayco commented Jul 28, 2021

go run test.go --token=$YOUR_TOKEN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment