diff options
| author | mo khan <mo@mokhan.ca> | 2024-05-18 11:26:42 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2024-05-18 11:26:42 -0600 |
| commit | 250ceb538b6bacea5cb0ee4c830ac6f5c03fbf6b (patch) | |
| tree | 088b6a30eba4c8f785e571d2efdb66e6f0b2cd3d | |
| parent | 56cee5390c71cd31bda902aa1ca484b13757a4b5 (diff) | |
feat: build request to REST API
| -rw-r--r-- | cmd/stanuki/main.go | 23 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 2 |
3 files changed, 25 insertions, 2 deletions
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)))) + } } @@ -1,3 +1,5 @@ module gitlab.com/mokhax/stanuki go 1.22 + +require github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 // indirect @@ -0,0 +1,2 @@ +github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1 h1:MIqcDqEAcr16QUq/kFJC3xbYoaAjjsxYEJLGtol2U58= +github.com/xlgmokha/x v0.0.0-20221023040112-0610463739d1/go.mod h1:Hf/0a9FveTBuVKvZ+Emmw6BlJyLGlhgjQwa4dFXp48s= |
