{"id":19653683,"url":"https://github.com/brevdev/nvcf-go","last_synced_at":"2025-02-27T01:41:54.974Z","repository":{"id":254346214,"uuid":"846246838","full_name":"brevdev/nvcf-go","owner":"brevdev","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-12T04:35:45.000Z","size":66,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-10T00:18:28.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brevdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T20:12:01.000Z","updated_at":"2024-10-11T17:09:09.000Z","dependencies_parsed_at":"2024-09-10T20:14:16.473Z","dependency_job_id":"5c6a90d7-af87-4270-a4d4-15170baaf984","html_url":"https://github.com/brevdev/nvcf-go","commit_stats":null,"previous_names":["brevdev/nvcf-go"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brevdev%2Fnvcf-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brevdev%2Fnvcf-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brevdev%2Fnvcf-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brevdev%2Fnvcf-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brevdev","download_url":"https://codeload.github.com/brevdev/nvcf-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240962203,"owners_count":19885448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T15:14:51.130Z","updated_at":"2025-02-27T01:41:54.942Z","avatar_url":"https://github.com/brevdev.png","language":"Go","readme":"# Nvidia Cloud Functions Go API Library\n\n\u003ca href=\"https://pkg.go.dev/github.com/brevdev/nvcf-go\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/brevdev/nvcf-go.svg\" alt=\"Go Reference\"\u003e\u003c/a\u003e\n\nThe Nvidia Cloud Functions Go library provides convenient access to [the Nvidia Cloud Functions REST\nAPI](https://www.nvidia.com/) from applications written in Go. The full API of this library can be found in [api.md](api.md).\n\nIt is generated with [Stainless](https://www.stainlessapi.com/).\n\n## Installation\n\n\u003c!-- x-release-please-start-version --\u003e\n\n```go\nimport (\n\t\"github.com/brevdev/nvcf-go\" // imported as nvidiacloudfunctions\n)\n```\n\n\u003c!-- x-release-please-end --\u003e\n\nOr to pin the version:\n\n\u003c!-- x-release-please-start-version --\u003e\n\n```sh\ngo get -u 'github.com/brevdev/nvcf-go@v0.0.1-alpha.0'\n```\n\n\u003c!-- x-release-please-end --\u003e\n\n## Requirements\n\nThis library requires Go 1.18+.\n\n## Usage\n\nThe full API of this library can be found in [api.md](api.md).\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/brevdev/nvcf-go\"\n)\n\nfunc main() {\n\tclient := nvidiacloudfunctions.NewClient()\n\tcreateFunctionResponse, err := client.Nvcf.Functions.New(context.TODO(), nvidiacloudfunctions.NvcfFunctionNewParams{\n\t\tInferenceURL: nvidiacloudfunctions.F(\"https://example.com\"),\n\t\tName:         nvidiacloudfunctions.F(\"x\"),\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", createFunctionResponse.Function)\n}\n\n```\n\n### Request fields\n\nAll request parameters are wrapped in a generic `Field` type,\nwhich we use to distinguish zero values from null or omitted fields.\n\nThis prevents accidentally sending a zero value if you forget a required parameter,\nand enables explicitly sending `null`, `false`, `''`, or `0` on optional parameters.\nAny field not specified is not sent.\n\nTo construct fields with values, use the helpers `String()`, `Int()`, `Float()`, or most commonly, the generic `F[T]()`.\nTo send a null, use `Null[T]()`, and to send a nonconforming value, use `Raw[T](any)`. For example:\n\n```go\nparams := FooParams{\n\tName: nvidiacloudfunctions.F(\"hello\"),\n\n\t// Explicitly send `\"description\": null`\n\tDescription: nvidiacloudfunctions.Null[string](),\n\n\tPoint: nvidiacloudfunctions.F(nvidiacloudfunctions.Point{\n\t\tX: nvidiacloudfunctions.Int(0),\n\t\tY: nvidiacloudfunctions.Int(1),\n\n\t\t// In cases where the API specifies a given type,\n\t\t// but you want to send something else, use `Raw`:\n\t\tZ: nvidiacloudfunctions.Raw[int64](0.01), // sends a float\n\t}),\n}\n```\n\n### Response objects\n\nAll fields in response structs are value types (not pointers or wrappers).\n\nIf a given field is `null`, not present, or invalid, the corresponding field\nwill simply be its zero value.\n\nAll response structs also include a special `JSON` field, containing more detailed\ninformation about each property, which you can use like so:\n\n```go\nif res.Name == \"\" {\n\t// true if `\"name\"` is either not present or explicitly null\n\tres.JSON.Name.IsNull()\n\n\t// true if the `\"name\"` key was not present in the repsonse JSON at all\n\tres.JSON.Name.IsMissing()\n\n\t// When the API returns data that cannot be coerced to the expected type:\n\tif res.JSON.Name.IsInvalid() {\n\t\traw := res.JSON.Name.Raw()\n\n\t\tlegacyName := struct{\n\t\t\tFirst string `json:\"first\"`\n\t\t\tLast  string `json:\"last\"`\n\t\t}{}\n\t\tjson.Unmarshal([]byte(raw), \u0026legacyName)\n\t\tname = legacyName.First + \" \" + legacyName.Last\n\t}\n}\n```\n\nThese `.JSON` structs also include an `Extras` map containing\nany properties in the json response that were not specified\nin the struct. This can be useful for API features not yet\npresent in the SDK.\n\n```go\nbody := res.JSON.ExtraFields[\"my_unexpected_field\"].Raw()\n```\n\n### RequestOptions\n\nThis library uses the functional options pattern. Functions defined in the\n`option` package return a `RequestOption`, which is a closure that mutates a\n`RequestConfig`. These options can be supplied to the client or at individual\nrequests. For example:\n\n```go\nclient := nvidiacloudfunctions.NewClient(\n\t// Adds a header to every request made by the client\n\toption.WithHeader(\"X-Some-Header\", \"custom_header_info\"),\n)\n\nclient.Nvcf.Functions.New(context.TODO(), ...,\n\t// Override the header\n\toption.WithHeader(\"X-Some-Header\", \"some_other_custom_header_info\"),\n\t// Add an undocumented field to the request body, using sjson syntax\n\toption.WithJSONSet(\"some.json.path\", map[string]string{\"my\": \"object\"}),\n)\n```\n\nSee the [full list of request options](https://pkg.go.dev/github.com/brevdev/nvcf-go/option).\n\n### Pagination\n\nThis library provides some conveniences for working with paginated list endpoints.\n\nYou can use `.ListAutoPaging()` methods to iterate through items across all pages:\n\nOr you can use simple `.List()` methods to fetch a single page and receive a standard response object\nwith additional helper methods like `.GetNextPage()`, e.g.:\n\n### Errors\n\nWhen the API returns a non-success status code, we return an error with type\n`*nvidiacloudfunctions.Error`. This contains the `StatusCode`, `*http.Request`, and\n`*http.Response` values of the request, as well as the JSON of the error body\n(much like other response objects in the SDK).\n\nTo handle errors, we recommend that you use the `errors.As` pattern:\n\n```go\n_, err := client.Nvcf.Functions.New(context.TODO(), nvidiacloudfunctions.NvcfFunctionNewParams{\n\tInferenceURL: nvidiacloudfunctions.F(\"https://example.com\"),\n\tName:         nvidiacloudfunctions.F(\"x\"),\n})\nif err != nil {\n\tvar apierr *nvidiacloudfunctions.Error\n\tif errors.As(err, \u0026apierr) {\n\t\tprintln(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request\n\t\tprintln(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response\n\t}\n\tpanic(err.Error()) // GET \"/v2/nvcf/functions\": 400 Bad Request { ... }\n}\n```\n\nWhen other errors occur, they are returned unwrapped; for example,\nif HTTP transport fails, you might receive `*url.Error` wrapping `*net.OpError`.\n\n### Timeouts\n\nRequests do not time out by default; use context to configure a timeout for a request lifecycle.\n\nNote that if a request is [retried](#retries), the context timeout does not start over.\nTo set a per-retry timeout, use `option.WithRequestTimeout()`.\n\n```go\n// This sets the timeout for the request, including all the retries.\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()\nclient.Nvcf.Functions.New(\n\tctx,\n\tnvidiacloudfunctions.NvcfFunctionNewParams{\n\t\tInferenceURL: nvidiacloudfunctions.F(\"https://example.com\"),\n\t\tName:         nvidiacloudfunctions.F(\"x\"),\n\t},\n\t// This sets the per-retry timeout\n\toption.WithRequestTimeout(20*time.Second),\n)\n```\n\n### File uploads\n\nRequest parameters that correspond to file uploads in multipart requests are typed as\n`param.Field[io.Reader]`. The contents of the `io.Reader` will by default be sent as a multipart form\npart with the file name of \"anonymous_file\" and content-type of \"application/octet-stream\".\n\nThe file name and content-type can be customized by implementing `Name() string` or `ContentType()\nstring` on the run-time type of `io.Reader`. Note that `os.File` implements `Name() string`, so a\nfile returned by `os.Open` will be sent with the file name on disk.\n\nWe also provide a helper `nvidiacloudfunctions.FileParam(reader io.Reader, filename string, contentType string)`\nwhich can be used to wrap any `io.Reader` with the appropriate file name and content type.\n\n### Retries\n\nCertain errors will be automatically retried 2 times by default, with a short exponential backoff.\nWe retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit,\nand \u003e=500 Internal errors.\n\nYou can use the `WithMaxRetries` option to configure or disable this:\n\n```go\n// Configure the default for all requests:\nclient := nvidiacloudfunctions.NewClient(\n\toption.WithMaxRetries(0), // default is 2\n)\n\n// Override per-request:\nclient.Nvcf.Functions.New(\n\tcontext.TODO(),\n\tnvidiacloudfunctions.NvcfFunctionNewParams{\n\t\tInferenceURL: nvidiacloudfunctions.F(\"https://example.com\"),\n\t\tName:         nvidiacloudfunctions.F(\"x\"),\n\t},\n\toption.WithMaxRetries(5),\n)\n```\n\n### Making custom/undocumented requests\n\nThis library is typed for convenient access to the documented API. If you need to access undocumented\nendpoints, params, or response properties, the library can still be used.\n\n#### Undocumented endpoints\n\nTo make requests to undocumented endpoints, you can use `client.Get`, `client.Post`, and other HTTP verbs.\n`RequestOptions` on the client, such as retries, will be respected when making these requests.\n\n```go\nvar (\n    // params can be an io.Reader, a []byte, an encoding/json serializable object,\n    // or a \"…Params\" struct defined in this library.\n    params map[string]interface{}\n\n    // result can be an []byte, *http.Response, a encoding/json deserializable object,\n    // or a model defined in this library.\n    result *http.Response\n)\nerr := client.Post(context.Background(), \"/unspecified\", params, \u0026result)\nif err != nil {\n    …\n}\n```\n\n#### Undocumented request params\n\nTo make requests using undocumented parameters, you may use either the `option.WithQuerySet()`\nor the `option.WithJSONSet()` methods.\n\n```go\nparams := FooNewParams{\n    ID:   nvidiacloudfunctions.F(\"id_xxxx\"),\n    Data: nvidiacloudfunctions.F(FooNewParamsData{\n        FirstName: nvidiacloudfunctions.F(\"John\"),\n    }),\n}\nclient.Foo.New(context.Background(), params, option.WithJSONSet(\"data.last_name\", \"Doe\"))\n```\n\n#### Undocumented response properties\n\nTo access undocumented response properties, you may either access the raw JSON of the response as a string\nwith `result.JSON.RawJSON()`, or get the raw JSON of a particular field on the result with\n`result.JSON.Foo.Raw()`.\n\nAny fields that are not present on the response struct will be saved and can be accessed by `result.JSON.ExtraFields()` which returns the extra fields as a `map[string]Field`.\n\n### Middleware\n\nWe provide `option.WithMiddleware` which applies the given\nmiddleware to requests.\n\n```go\nfunc Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) {\n\t// Before the request\n\tstart := time.Now()\n\tLogReq(req)\n\n\t// Forward the request to the next handler\n\tres, err = next(req)\n\n\t// Handle stuff after the request\n\tend := time.Now()\n\tLogRes(res, err, start - end)\n\n    return res, err\n}\n\nclient := nvidiacloudfunctions.NewClient(\n\toption.WithMiddleware(Logger),\n)\n```\n\nWhen multiple middlewares are provided as variadic arguments, the middlewares\nare applied left to right. If `option.WithMiddleware` is given\nmultiple times, for example first in the client then the method, the\nmiddleware in the client will run first and the middleware given in the method\nwill run next.\n\nYou may also replace the default `http.Client` with\n`option.WithHTTPClient(client)`. Only one http client is\naccepted (this overwrites any previous client) and receives requests after any\nmiddleware has been applied.\n\n## Semantic versioning\n\nThis package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:\n\n1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.\n2. Changes that we do not expect to impact the vast majority of users in practice.\n\nWe take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.\n\nWe are keen for your feedback; please open an [issue](https://www.github.com/brevdev/nvcf-go/issues) with questions, bugs, or suggestions.\n\n## Contributing\n\nSee [the contributing documentation](./CONTRIBUTING.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrevdev%2Fnvcf-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrevdev%2Fnvcf-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrevdev%2Fnvcf-go/lists"}