Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdockerty/onetimesecret-go
Golang API client for OneTimeSecret
https://github.com/jdockerty/onetimesecret-go
api-client api-wrapper go golang golang-api onetimesecret
Last synced: 29 days ago
JSON representation
Golang API client for OneTimeSecret
- Host: GitHub
- URL: https://github.com/jdockerty/onetimesecret-go
- Owner: jdockerty
- License: mit
- Created: 2021-01-01T09:18:55.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-03T10:26:22.000Z (almost 4 years ago)
- Last Synced: 2024-10-13T09:21:26.935Z (2 months ago)
- Topics: api-client, api-wrapper, go, golang, golang-api, onetimesecret
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OneTimeSecret (OTS) - Go Client Library
This serves as a Golang API client for [onetimesecret](https://onetimesecret.com/).
## Installation
As this is a Go package, it is easiest to install via `go get`
As such, you can retrieve this package by running the command
go get -u "github.com/jdockerty/onetimesecret-go/ots"
## Usage
Prior to using the package, you must have an account with OTS as this gives you a username, which is your email, to use and an API token. Various functions are exposed which match to the naming conventions of the OTS API.
A simple use case for checking the status of the OTS API and creating a secret is shown below
```go
package mainimport (
"log"
"github.com/jdockerty/onetimesecret-go/ots"
)func main() {
client := ots.New("YOUR_EMAIL", "API_TOKEN")
err := client.Status() // Get the status of the OTS API
if err != nil {
return // If the API is offline, an error is returned.
}// Send a secret to your friend's email address, it is destroyed within 60 seconds.
// They must enter the passphrase to view it.
secretResp, err := client.Create(
"my super secret value",
"very secret passphrase",
"[email protected]",
60)
if err != nil {
// Handling errors from sending requests and dealing with JSON go here
log.Fatal(err)
}// Log the Secret struct response with various information to stdout in an easy to read format.
secretResp.PrettyPrint()}
```The other exported functions can return a `Secret` or `Secrets` type, which is struct that contains the expected responses from the API, such as a list of recipients for the secret or it's time-to-live value. Which fields are used is left to the user and further details on the various functions are available via the [godoc](https://godoc.org/github.com/jdockerty/onetimesecret-go/ots) page.