Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelfredrickson committed Apr 10, 2024
0 parents commit 7a70851
Show file tree
Hide file tree
Showing 8 changed files with 51,659 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.idea
*.new
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

.PHONY: all
all: castai/generated.go

castai/generated.go: openapi.json
@echo Generating castai package...
@oapi-codegen -package castai -generate types,client $< >$@

openapi.json: FORCE
@echo -n Checking for newer $@ file...
@wget -q -O $@.new https://api.cast.ai/v1/spec/openapi.json
@if ! cmp -s $@ $@.new; then \
echo " found!";\
mv $@.new $@ ;\
else \
echo " up-to-date" ;\
fi
@$(RM) $@.new

FORCE: ;
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CastAI API Client for Go

This client is built using [oapi-codegen](https://github.com/deepmap/oapi-codegen)
against the [CastAI OpenAPI specification](https://api.cast.ai/v1/spec/openapi.json).
The provided `Makefile` will download the latest specification and re-run the
code generator if there are any changes.

```sh
$ go install github.com/deepmap/oapi-codegen/v2/cmd/[email protected]
$ make
Checking for newer openapi.json file... found!
Generating castai package...
$ make
Checking for newer openapi.json file... up-to-date
$
```
51,555 changes: 51,555 additions & 0 deletions castai/generated.go

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions castai/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package castai

import (
"strings"

"github.com/deepmap/oapi-codegen/pkg/securityprovider"
)

// NewDefaultClient returns a CastAI client with typed responses and configured
// to use the provided API key.
func NewDefaultClient(
apiKey string, opts ...ClientOption,
) (*ClientWithResponses, error) {
apiKey = strings.TrimSpace(apiKey)
apiKeyProvider, err := securityprovider.NewSecurityProviderApiKey(
"header", "X-API-Key", apiKey,
)
if err != nil {
return nil, err
}
opts = append(opts,
WithRequestEditorFn(apiKeyProvider.Intercept),
)
client, err := NewClientWithResponses(DefaultServer, opts...)
return client, err
}

const DefaultServer = "https://api.cast.ai"
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/socotra/castai-api-go

go 1.22.2

require (
github.com/deepmap/oapi-codegen v1.16.2
github.com/oapi-codegen/runtime v1.1.1
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen v1.16.2 h1:xGHx0dNqYfy9gE8a7AVgVM8Sd5oF9SEgePzP+UPAUXI=
github.com/deepmap/oapi-codegen v1.16.2/go.mod h1:rdYoEA2GE+riuZ91DvpmBX9hJbQpuY9wchXpfQ3n+ho=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 1 addition & 0 deletions openapi.json

Large diffs are not rendered by default.

0 comments on commit 7a70851

Please sign in to comment.