Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetreewu committed Dec 24, 2021
1 parent 429ab0b commit 2865f76
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ type OneOfstringprojectResponse interface{}
````

## Usage
### Build client by token
```go
// Build client
config := openapi.NewConfiguration()
client, err := keystone.NewClient(config)
client, err := keystone.NewDefaultClientByToken("a_keystone_token")
if err != nil {
panic(err)
}
// API Call
resp, r, err := client.DomainApi.ListDomains(context.TODO()).Execute()
```
### Build client by password
```go
// Build client
client, err := keystone.NewDefaultClient()
if err != nil {
panic(err)
}
Expand All @@ -47,21 +58,9 @@ resp, r, err := client.DomainApi.ListDomains(context.TODO()).Execute()
### How to change the server configuration?
#### Default
The client uses the first server (index=0) defined in OAS by default.

#### Change server index
By specifying the server index, client will use corresponding server configuration defined in OAS.
```go
// Build the client
serverIndex := 1
config := openapi.NewConfiguration()
client, err := keystone.NewClientWithServerIndex(config, serverIndex)
// Authentication is omitted.
// API Call
ctx := context.WithValue(context.TODO(), openapi.ContextServerIndex, serverIndex)
resp, r, err := client.DomainApi.ListDomains(ctx).Execute()
```yaml
- description: Service domain
url: http://keystone-api.openstack.svc.cluster.local
```

#### Change manually in code
Expand All @@ -70,8 +69,6 @@ Just edit the `config` object.
config := openapi.NewConfiguration()
config.Servers = openapi.ServerConfigurations{{
URL: "localhost:8000",
Description: "local test",
Variables: nil,
}}
client, err := keystone.NewClient(config)
```

0 comments on commit 2865f76

Please sign in to comment.