Last active
July 28, 2021 00:01
-
-
Save jayco/489aeb1fe447c0202b4205eeeaf0e505 to your computer and use it in GitHub Desktop.
test-buildkite-go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go run test.go --token=$YOUR_TOKEN