diff --git a/README.md b/README.md index 781ecbf..127b6b2 100644 --- a/README.md +++ b/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. diff --git a/auth.go b/auth.go index 488c258..f041862 100644 --- a/auth.go +++ b/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) +} diff --git a/client_test.go b/client_test.go index c3d84a3..512da64 100644 --- a/client_test.go +++ b/client_test.go @@ -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{