feat: add K2V_ENDPOINT env var
This commit is contained in:
parent
97bedfe1aa
commit
231423cd0b
3 changed files with 20 additions and 6 deletions
17
README.md
17
README.md
|
@ -11,11 +11,14 @@ import k2v "code.notaphish.fyi/milas/garage-k2v-go"
|
|||
|
||||
## Create API client
|
||||
```go
|
||||
endpoint := "http://localhost:3904"
|
||||
// Read K2V_ENDPOINT from OS environment variable, e.g. http://localhost:3904.
|
||||
endpoint := k2v.EndpointFromEnv()
|
||||
|
||||
// Read K2V_KEY_ID and K2V_SECRET_KEY from OS environment variables.
|
||||
// Read K2V_KEY_ID and K2V_KEY_SECRET from OS environment variables.
|
||||
key := k2v.KeyFromEnv()
|
||||
// key := k2v.Key{ID: "GK49e661847883e4813993a0db", Secret: "..."}
|
||||
|
||||
// Alternatively, construct a key by initializing the ID and secret fields on a k2v.Key.
|
||||
// key := k2v.Key{ID: "GK...", Secret: "..."}
|
||||
|
||||
client := k2v.NewClient(endpoint, key)
|
||||
```
|
||||
|
@ -36,6 +39,14 @@ type Client
|
|||
func (c *Client) ReadItemSingle(ctx context.Context, b Bucket, pk string, sk string) (Item, CausalityToken, error)
|
||||
```
|
||||
|
||||
## Integration Tests
|
||||
```shell
|
||||
K2V_ENDPOINT="http://[::1]:3904" \
|
||||
K2V_KEY_ID="GK..." \
|
||||
K2V_KEY_SECRET="..." \
|
||||
go test ./...
|
||||
```
|
||||
|
||||
## Usage
|
||||
Review the [K2V API spec][k2v-api] and the integration tests in this module for complete examples.
|
||||
|
||||
|
|
5
auth.go
5
auth.go
|
@ -4,6 +4,7 @@ import "os"
|
|||
|
||||
const EnvVarKeyID = "K2V_KEY_ID"
|
||||
const EnvVarKeySecret = "K2V_KEY_SECRET"
|
||||
const EnvVarEndpoint = "K2V_ENDPOINT"
|
||||
|
||||
func KeyFromEnv() Key {
|
||||
return Key{
|
||||
|
@ -11,3 +12,7 @@ func KeyFromEnv() Key {
|
|||
Secret: os.Getenv(EnvVarKeySecret),
|
||||
}
|
||||
}
|
||||
|
||||
func EndpointFromEnv() string {
|
||||
return os.Getenv(EnvVarEndpoint)
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import (
|
|||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
const endpoint = "http://127.0.0.1:3904"
|
||||
|
||||
type fixture struct {
|
||||
t testing.TB
|
||||
ctx context.Context
|
||||
|
@ -31,7 +29,7 @@ func newFixture(t testing.TB) (*fixture, context.Context) {
|
|||
|
||||
ctx := testContext(t)
|
||||
|
||||
cli := k2v.NewClient(endpoint, k2v.KeyFromEnv())
|
||||
cli := k2v.NewClient(k2v.EndpointFromEnv(), k2v.KeyFromEnv())
|
||||
t.Cleanup(cli.Close)
|
||||
|
||||
f := &fixture{
|
||||
|
|
Loading…
Add table
Reference in a new issue