|
1 | 1 | # Cycle API Go Client |
2 | 2 |
|
3 | | -_This is an auto-generated API client based on the [OpenAPI Spec for Cycle](https://github.com/cycleplatform/api-spec). Please do not open any PRs for the generated code under /client. If you have any questions on what changes are made in the latest version, please refer to the spec above._ |
| 3 | +_This is an auto-generated API client based on the [OpenAPI Spec for Cycle](https://github.com/cycleplatform/api-spec). Please do not open any PRs for the generated code in `generated.go`. If you have any questions on what changes are made in the latest version, please refer to the spec above._ |
4 | 4 |
|
5 | | -## Setup |
6 | 5 |
|
7 | | -Install Ogen |
| 6 | +## Usage |
8 | 7 |
|
9 | | -`go install -v github.com/ogen-go/ogen/cmd/ogen@latest` |
| 8 | +`go get github.com/cycleplatform/api-client-go` |
10 | 9 |
|
11 | | -## Generating |
| 10 | +Create a client |
12 | 11 |
|
13 | | -### Updating the spec |
| 12 | +```go |
| 13 | +package main |
| 14 | + |
| 15 | +import ( |
| 16 | + cycle "github.com/cycleplatform/api-client-go" |
| 17 | +) |
| 18 | + |
| 19 | +func main() { |
| 20 | + apiKey := os.Getenv("CYCLE_API_KEY") |
| 21 | + if apiKey == "" { |
| 22 | + log.Fatal("missing env var CYCLE_API_KEY") |
| 23 | + } |
| 24 | + |
| 25 | + hubId := os.Getenv("CYCLE_HUB_ID") |
| 26 | + if hubId == "" { |
| 27 | + log.Fatal("missing env var CYCLE_HUB_ID") |
| 28 | + } |
| 29 | + |
| 30 | + c, err := cycle.NewAuthenticatedClient(cycle.ClientConfig{ |
| 31 | + APIKey: apiKey, |
| 32 | + HubID: hubId, |
| 33 | + }) |
| 34 | + |
| 35 | + if err != nil { |
| 36 | + log.Fatal(err) |
| 37 | + } |
| 38 | + |
| 39 | + // Get list of environments |
| 40 | + resp, err := c.GetEnvironmentsWithResponse(context.TODO(), &cycle.GetEnvironmentsParams{}) |
| 41 | + if err != nil { |
| 42 | + log.Fatal(err) |
| 43 | + } |
| 44 | + |
| 45 | + if resp.StatusCode() != http.StatusOK { |
| 46 | + log.Fatalf("Expected HTTP 200 but received %d %s", resp.StatusCode(), *resp.JSONDefault.Error.Title) |
| 47 | + } |
| 48 | + |
| 49 | + for _, v := range resp.JSON200.Data { |
| 50 | + fmt.Printf("ID: %s - Name: %s\n", v.Id, v.Name) |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Development |
| 56 | + |
| 57 | +### Updating the API spec |
| 58 | + |
| 59 | +Update the API spec to the latest version: |
14 | 60 |
|
15 | 61 | `git submodule update --recursive --remote` |
16 | 62 |
|
17 | | -Using `npm`, run `(cd api-spec; npm run build:public && npm run build:internal)` |
| 63 | +Using `npm`, run `(cd api-spec; npm run build:platform && npm run downconvert:platform)` |
18 | 64 |
|
19 | 65 | ### Generating the client |
20 | 66 |
|
|
0 commit comments