|
| 1 | +# Go API client for {{packageName}} |
| 2 | + |
| 3 | +Use this documentation to learn how to use the ArvanCloud SDK. |
| 4 | + |
| 5 | +**API version**: {{appVersion}} |
| 6 | + |
| 7 | +## Dependencies |
| 8 | + |
| 9 | +Install the following packages: |
| 10 | + |
| 11 | +```shell |
| 12 | +go get github.com/stretchr/testify/assert |
| 13 | +{{#hasOAuthMethods}} |
| 14 | +go get golang.org/x/oauth2 |
| 15 | +{{/hasOAuthMethods}} |
| 16 | +go get golang.org/x/net/context |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Get the package: |
| 22 | + |
| 23 | +```bash |
| 24 | +go get github.com/arvancloud/cdn-go |
| 25 | +``` |
| 26 | + |
| 27 | +Put the package under your project folder and add the following in import: |
| 28 | + |
| 29 | +```golang |
| 30 | +import {{packageName}} "github.com/arvancloud/cdn-go" |
| 31 | +``` |
| 32 | + |
| 33 | +## Configuration of Server URL |
| 34 | + |
| 35 | +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. |
| 36 | + |
| 37 | +### Select Server Configuration |
| 38 | + |
| 39 | +For using other server than the one defined on index 0 set context value `sw.ContextServerIndex` of type `int`. |
| 40 | + |
| 41 | +```golang |
| 42 | +ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerIndex, 1) |
| 43 | +``` |
| 44 | + |
| 45 | +### Templated Server URL |
| 46 | + |
| 47 | +Templated server URL is formatted using default variables from configuration or from context value `sw.ContextServerVariables` of type `map[string]string`. |
| 48 | + |
| 49 | +```golang |
| 50 | +ctx := context.WithValue(context.Background(), {{packageName}}.ContextServerVariables, map[string]string{ |
| 51 | + "basePath": "v2", |
| 52 | +}) |
| 53 | +``` |
| 54 | + |
| 55 | +Note, enum values are always validated and all unused variables are silently ignored. |
| 56 | + |
| 57 | +### URLs Configuration per Operation |
| 58 | + |
| 59 | +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. |
| 60 | +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. |
| 61 | +Similar rules for overriding default operation server index and variables applies by using `sw.ContextOperationServerIndices` and `sw.ContextOperationServerVariables` context maps. |
| 62 | + |
| 63 | +```golang |
| 64 | +ctx := context.WithValue(context.Background(), {{packageName}}.ContextOperationServerIndices, map[string]int{ |
| 65 | + "{classname}Service.{nickname}": 2, |
| 66 | +}) |
| 67 | +ctx = context.WithValue(context.Background(), {{packageName}}.ContextOperationServerVariables, map[string]map[string]string{ |
| 68 | + "{classname}Service.{nickname}": { |
| 69 | + "port": "8443", |
| 70 | + }, |
| 71 | +}) |
| 72 | +``` |
| 73 | + |
| 74 | +## Documentation for API Endpoints |
| 75 | + |
| 76 | +All URIs are relative to *{{basePath}}* |
| 77 | + |
| 78 | +Class | Method | HTTP request | Description |
| 79 | +------------ | ------------- | ------------- | ------------- |
| 80 | +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{summary}} |
| 81 | +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} |
| 82 | + |
| 83 | +## Documentation For Models |
| 84 | + |
| 85 | +{{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) |
| 86 | +{{/model}}{{/models}} |
| 87 | + |
| 88 | +## Documentation For Authorization |
| 89 | + |
| 90 | +{{^authMethods}}Endpoints do not require authorization.{{/authMethods}} |
| 91 | +{{#hasAuthMethods}}Authentication schemes defined for the API:{{/hasAuthMethods}} |
| 92 | +{{#authMethods}} |
| 93 | +### {{{name}}} |
| 94 | + |
| 95 | +{{#isApiKey}} |
| 96 | +- **Type**: API key |
| 97 | +- **API key parameter name**: {{{keyParamName}}} |
| 98 | +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} |
| 99 | + |
| 100 | +Note, each API key must be added to a map of `map[string]APIKey` where the key is: {{keyParamName}} and passed in as the auth context for each request. |
| 101 | + |
| 102 | +Example |
| 103 | + |
| 104 | +```golang |
| 105 | +auth := context.WithValue( |
| 106 | + context.Background(), |
| 107 | + sw.ContextAPIKeys, |
| 108 | + map[string]sw.APIKey{ |
| 109 | + "{{keyParamName}}": {Key: "API_KEY_STRING"}, |
| 110 | + }, |
| 111 | + ) |
| 112 | +r, err := client.Service.Operation(auth, args) |
| 113 | +``` |
| 114 | + |
| 115 | +{{/isApiKey}} |
| 116 | +{{#isBasic}} |
| 117 | +{{#isBasicBearer}} |
| 118 | +- **Type**: HTTP Bearer token authentication |
| 119 | + |
| 120 | +Example |
| 121 | + |
| 122 | +```golang |
| 123 | +auth := context.WithValue(context.Background(), sw.ContextAccessToken, "BEARER_TOKEN_STRING") |
| 124 | +r, err := client.Service.Operation(auth, args) |
| 125 | +``` |
| 126 | + |
| 127 | +{{/isBasicBearer}} |
| 128 | +{{#isBasicBasic}} |
| 129 | +- **Type**: HTTP basic authentication |
| 130 | + |
| 131 | +Example |
| 132 | + |
| 133 | +```golang |
| 134 | +auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{ |
| 135 | + UserName: "username", |
| 136 | + Password: "password", |
| 137 | +}) |
| 138 | +r, err := client.Service.Operation(auth, args) |
| 139 | +``` |
| 140 | + |
| 141 | +{{/isBasicBasic}} |
| 142 | +{{#isHttpSignature}} |
| 143 | +- **Type**: HTTP signature authentication |
| 144 | + |
| 145 | +Example |
| 146 | + |
| 147 | +```golang |
| 148 | + authConfig := client.HttpSignatureAuth{ |
| 149 | + KeyId: "my-key-id", |
| 150 | + PrivateKeyPath: "rsa.pem", |
| 151 | + Passphrase: "my-passphrase", |
| 152 | + SigningScheme: sw.HttpSigningSchemeHs2019, |
| 153 | + SignedHeaders: []string{ |
| 154 | + sw.HttpSignatureParameterRequestTarget, // The special (request-target) parameter expresses the HTTP request target. |
| 155 | + sw.HttpSignatureParameterCreated, // Time when request was signed, formatted as a Unix timestamp integer value. |
| 156 | + "Host", // The Host request header specifies the domain name of the server, and optionally the TCP port number. |
| 157 | + "Date", // The date and time at which the message was originated. |
| 158 | + "Content-Type", // The Media type of the body of the request. |
| 159 | + "Digest", // A cryptographic digest of the request body. |
| 160 | + }, |
| 161 | + SigningAlgorithm: sw.HttpSigningAlgorithmRsaPSS, |
| 162 | + SignatureMaxValidity: 5 * time.Minute, |
| 163 | + } |
| 164 | + var authCtx context.Context |
| 165 | + var err error |
| 166 | + if authCtx, err = authConfig.ContextWithValue(context.Background()); err != nil { |
| 167 | + // Process error |
| 168 | + } |
| 169 | + r, err = client.Service.Operation(auth, args) |
| 170 | + |
| 171 | +``` |
| 172 | +{{/isHttpSignature}} |
| 173 | +{{/isBasic}} |
| 174 | +{{#isOAuth}} |
| 175 | + |
| 176 | +- **Type**: OAuth |
| 177 | +- **Flow**: {{{flow}}} |
| 178 | +- **Authorization URL**: {{{authorizationUrl}}} |
| 179 | +- **Scopes**: {{^scopes}}N/A{{/scopes}} |
| 180 | +{{#scopes}} - **{{{scope}}}**: {{{description}}} |
| 181 | +{{/scopes}} |
| 182 | + |
| 183 | +Example |
| 184 | + |
| 185 | +```golang |
| 186 | +auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING") |
| 187 | +r, err := client.Service.Operation(auth, args) |
| 188 | +``` |
| 189 | + |
| 190 | +Or via OAuth2 module to automatically refresh tokens and perform user authentication. |
| 191 | + |
| 192 | +```golang |
| 193 | +import "golang.org/x/oauth2" |
| 194 | + |
| 195 | +/* Perform OAuth2 round trip request and obtain a token */ |
| 196 | + |
| 197 | +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) |
| 198 | +auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) |
| 199 | +r, err := client.Service.Operation(auth, args) |
| 200 | +``` |
| 201 | + |
| 202 | +{{/isOAuth}} |
| 203 | +{{/authMethods}} |
| 204 | + |
| 205 | +## Documentation for Utility Methods |
| 206 | + |
| 207 | +Due to the fact that model structure members are all pointers, this package contains |
| 208 | +a number of utility functions to easily obtain pointers to values of basic types. |
| 209 | +Each of these functions takes a value of the given basic type and returns a pointer to it: |
| 210 | + |
| 211 | +* `PtrBool` |
| 212 | +* `PtrInt` |
| 213 | +* `PtrInt32` |
| 214 | +* `PtrInt64` |
| 215 | +* `PtrFloat` |
| 216 | +* `PtrFloat32` |
| 217 | +* `PtrFloat64` |
| 218 | +* `PtrString` |
| 219 | +* `PtrTime` |
| 220 | + |
| 221 | +## Author |
| 222 | + |
| 223 | +{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}} |
| 224 | +{{/-last}}{{/apis}}{{/apiInfo}} |
0 commit comments