Go client
The server repository ships a Go client generated from the OpenAPI spec with
oapi-codegen:
github.com/entrepotproj/entrepot/pkg/client. The Terraform provider
is built on the same spec.
go get github.com/entrepotproj/entrepot/pkg/clientCreate a client
Section titled “Create a client”The server URL includes the /api/v1 prefix. Authentication is a request
editor that adds the bearer token:
package main
import ( "context" "fmt" "log" "net/http" "os"
"github.com/entrepotproj/entrepot/pkg/client")
func main() { token := os.Getenv("ENTREPOT_TOKEN") c, err := client.NewClientWithResponses( "https://entrepot.example.com/api/v1", client.WithRequestEditorFn(func(_ context.Context, req *http.Request) error { req.Header.Set("Authorization", "Bearer "+token) return nil }), ) if err != nil { log.Fatal(err) }
ctx := context.Background() res, err := c.ListRepositoriesWithResponse(ctx, &client.ListRepositoriesParams{}) if err != nil { log.Fatal(err) } if res.JSON200 == nil { log.Fatalf("list repositories: %s", res.Status()) } for _, r := range *res.JSON200 { fmt.Printf("%-24s %-7s %-7s %s\n", r.Name, r.Format, r.Kind, r.Url) }}Create a repository
Section titled “Create a repository”anon := truecreated, err := c.CreateRepositoryWithResponse(ctx, client.CreateRepositoryJSONRequestBody{ Name: "npm-proxy", Format: client.Npm, Kind: client.RepositoryKindProxy, BlobStore: "default", AnonymousRead: &anon, Proxy: &client.ProxySettings{RemoteUrl: "https://registry.npmjs.org"},})if err != nil { log.Fatal(err)}switch {case created.JSON201 != nil: fmt.Println("created", created.JSON201.Url)case created.JSONDefault != nil: log.Fatalf("%s: %s", created.JSONDefault.Code, created.JSONDefault.Message)}Conventions
Section titled “Conventions”- Every operation has a
…WithResponsemethod returning a typed response withJSON200/JSON201/JSONDefault(the error body) fields and the rawHTTPResponse. - Optional fields are pointers; enums are typed constants (
client.Npm,client.RepositoryKindHosted,client.ActionWrite, …). - Method names follow the spec’s
operationIds —CreateRoleBinding,PreviewCleanupPolicy,TestRoutingRule,GetMetricsOverview, … — so the API reference doubles as the client’s documentation. - Uploads (
UploadComponentWithBodyWithResponse) take amultipart/form-databody you build withmime/multipart.
Other languages: generate a client from /api/openapi.yaml with your
favourite OpenAPI generator.