Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joemiller/prefixed-api-key
Go implementation of seamapi/prefixed-api-key
https://github.com/joemiller/prefixed-api-key
Last synced: 13 days ago
JSON representation
Go implementation of seamapi/prefixed-api-key
- Host: GitHub
- URL: https://github.com/joemiller/prefixed-api-key
- Owner: joemiller
- License: mit
- Created: 2022-05-12T02:04:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T23:44:52.000Z (8 months ago)
- Last Synced: 2024-06-21T03:15:40.449Z (5 months ago)
- Language: Go
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prefixed-api-key
[![Go Doc](https://pkg.go.dev/badge/github.com/joemiller/prefixed-api-key.svg)](https://pkg.go.dev/github.com/joemiller/prefixed-api-key)
![go report card](https://goreportcard.com/badge/github.com/joemiller/prefixed-api-key)
![github actions status](https://github.com/joemiller/prefixed-api-key/actions/workflows/main.yaml/badge.svg)Go implementation of [seamapi/prefixed-api-key](https://github.com/seamapi/prefixed-api-key).
## Usage
```
go get github.com/joemiller/prefixed-api-key
``````go
package mainimport (
"log"apikey "github.com/joemiller/prefixed-api-key"
)func main() {
generator, err := apikey.NewGenerator("mycompany")
if err != nil {
log.Fatal(err)
}key, err := generator.GenerateAPIKey()
log.Println(key.Token())ok, err := apikey.CheckAPIKey(key.Token(), key.LongTokenHash())
if err != nil {
log.Fatal(err)
}
if ok {
log.Println("token matches hash")
}key, err = apikey.ParseAPIKey("mycompany_5TJMbnP3thd_DjzvCr9MQLaKcaMisJuyUntS7Jpk61ZMp")
log.Println(key.LongTokenHash())
}
```