From 250ceb538b6bacea5cb0ee4c830ac6f5c03fbf6b Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 18 May 2024 11:26:42 -0600 Subject: feat: build request to REST API --- cmd/stanuki/main.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'cmd/stanuki') diff --git a/cmd/stanuki/main.go b/cmd/stanuki/main.go index bd6e00f..ea7c5d2 100644 --- a/cmd/stanuki/main.go +++ b/cmd/stanuki/main.go @@ -1,7 +1,26 @@ package main -import "fmt" +import ( + "context" + "fmt" + "io" + "net/http" + + "github.com/xlgmokha/x/pkg/env" + "github.com/xlgmokha/x/pkg/x" +) func main() { - fmt.Println("Hello, Stanuki!") + token := env.Fetch("GITLAB_TOKEN", "") + url := "https://gitlab.com/api/v4/groups/4/issues" + client := http.Client{} + request := x.Must(http.NewRequestWithContext(context.TODO(), "GET", url, nil)) + request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", token)) + response := x.Must(client.Do(request)) + + if response.StatusCode == http.StatusOK { + } else { + fmt.Println(response.Status) + fmt.Println(string(x.Must(io.ReadAll(response.Body)))) + } } -- cgit v1.2.3