Go Api Client for onetimesecret.com
This is a Go implementation of the onetimesecret.com api api. The module aims to provide a developer friendly interface for all endpoints exposed by the api.
Installation
go get github.com/chelnak/onetimesecret-go
Usage
package main
import (
"context"
"fmt"
ots "github.com/chelnak/onetimesecret-go/onetimesecret"
)
func main() {
// Build a new client
client := ots.NewClient(
ots.WithUsername("otsuser@domain.com"),
ots.WithAPIKey("xxxxxxxx"),
)
// Send a request with context
ctx := context.Background()
response, err := client.GetStatus(ctx)
if err != nil {
panic(err)
}
fmt.Println(response.Status)
}
Using a custom http.Client instance
package main
import (
ots "github.com/chelnak/onetimesecret-go/onetimesecret"
"context"
)
func main() {
// Create a custom http client instance
customHttpClient := &http.Client{ ... }
// Build a new ots client and use WithHttpClient option
client := ots.NewClient(
ots.WithUsername("otsuser@domain.com"),
ots.WithApiKey("xxxxxxxx"),
ots.WithHttpClient(customHttpClient)
)
// Send a request with context
ctx := context.Background()
response, err := client.GetStatus(ctx)
if err != nil {
panic(err)
}
fmt.Println(response.Status)
}
Note: By default, a default http.Client instance is used if one is not passed when creating a client instance.
More documentation can be found here.
Unit testing
go test -tags unit ./... -v
Examples
export OTS_USERNAME=otsuser@domain.com
export OTS_APIKEY=xxxxx
go test -tags example ./... -v
Releasing
Releases are tag based. From the main branch do the following:
git tag -a vX.X.X -m "Release vX.X.X some reason"
git push --follow-tags