Golang Token
A simple library to validate and generate token in GO
Installation
Use go get
to retrieve the SDK to add it to your project's Go module dependencies.
go get gitlab.com/token-library/golang-token
To update the SDK use go get -u to retrieve the latest version of the SDK.
go get -u gitlab.com/token-library/golang-token
Example
Seamless 1.1 Token
The following example would help you to validate or generate the X-API-TOKEN
. The token generation rule refers to the Seamless Wallet 1.1 Doc
Validate X-API-TOKEN
package main
import (
liveCasino "gitlab.com/token-library/golang-token"
)
func main() {
key := "<your agent ID>"
secret := "<your agent key>"
seamlessWalletToken, err := liveCasino.NewSeamlessWalletToken(key, secret)
if err != nil {
panic(err)
}
payload := "{\"requestId\":\"test-123\",\"user\":\"member\"}"
token := "the-X-API-TOKEN-form-header"
seamlessWalletToken.Validate(payload, token)
}
Generate X-API-TOKEN
package main
import (
"fmt"
liveCasino "gitlab.com/token-library/golang-token"
)
func main() {
key := "<your agent ID>"
secret := "<your agent key>"
seamlessWalletToken, err := liveCasino.NewSeamlessWalletToken(key, secret)
if err != nil {
panic(err)
}
payload := "{\"requestId\":\"test-123\",\"status\":\"ok\",\"user\":\"member\",\"currency\":\"USD\",\"balance\":100}"
token, err := seamlessWalletToken.GenerateToken(payload)
if err != nil {
panic(err)
}
fmt.Println(token)
}
API Key(For keno-api)
The following example would help you to generate the Key
in request parameters. The token generation rule refers to the Encryption Flow
Generate key
package main
import (
"fmt"
liveCasino "gitlab.com/token-library/golang-token"
)
func main() {
key := "<your agent ID>"
secret := "<your agent key>"
apiToken, err := liveCasino.NewApiToken(key, secret)
if err != nil {
panic(err)
}
// need to sort by key
type request struct {
AgentId string
Account string
LimitStake string
}
params := request{
Account: "member",
AgentId: key,
LimitStake: "1,2,3",
}
payload, _ := json.Marshal(params)
fmt.Println(liveCasino.GenerateKey(string(payload)))
}
HMAC Signature(For v2 api)
The following example would help you to generate the Signature
in the request header.
Query String(GET)
package main
import (
"fmt"
liveCasino "gitlab.com/token-library/golang-token"
)
func main() {
key := "<your agent ID>"
secret := "<your agent key>"
apiV2Signature, err := liveCasino.NewApiV2Signature(key, secret)
if err != nil {
panic(err)
}
// TODO
}
Request Body(POST, PATCH)
package main
import (
"fmt"
liveCasino "gitlab.com/token-library/golang-token"
)
func main() {
key := "<your agent ID>"
secret := "<your agent key>"
apiV2Signature, err := liveCasino.NewApiV2Signature(key, secret)
if err != nil {
panic(err)
}
// TODO
}
Tests
Please install the golangci-lint if you want to lint the code
golangci-lint run -v
go test -v
License
Please see MIT License File for more information.