https://github.com/dendavidov/go-utils
Small Go module and CLI: RS256 JWT helpers (pkg/jwt) and jwt-token for local/dev signing.
https://github.com/dendavidov/go-utils
go golang jwt utilities
Last synced: 2 months ago
JSON representation
Small Go module and CLI: RS256 JWT helpers (pkg/jwt) and jwt-token for local/dev signing.
- Host: GitHub
- URL: https://github.com/dendavidov/go-utils
- Owner: dendavidov
- License: mit
- Created: 2023-04-02T08:05:43.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2026-04-21T22:31:22.000Z (2 months ago)
- Last Synced: 2026-04-22T00:16:33.546Z (2 months ago)
- Topics: go, golang, jwt, utilities
- Language: Go
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# go-utils
Small Go utilities with a versioned module and conventional releases.
[](https://github.com/dendavidov/go-utils/actions/workflows/ci.yml)
[](https://github.com/dendavidov/go-utils/releases)
[](https://pkg.go.dev/github.com/dendavidov/go-utils)
[](https://goreportcard.com/report/github.com/dendavidov/go-utils)
[](LICENSE)
## Install
Library:
```bash
go get github.com/dendavidov/go-utils@latest
```
CLI (requires a recent Go toolchain):
```bash
go install github.com/dendavidov/go-utils/cmd/jwt-token@latest
```
Prebuilt binaries appear on [GitHub Releases](https://github.com/dendavidov/go-utils/releases) when a tag is published.
## Package `pkg/jwt`
Mint and verify RS256 JWTs with custom claims (`id`, `email`, `isAccessToken`) and standard registered claims (`exp`, `iat`, `nbf`).
```go
import "github.com/dendavidov/go-utils/pkg/jwt"
priv, err := jwt.ParsePrivateKeyFromBase64(os.Getenv("JWT_PRIVATE_KEY_B64"))
if err != nil { /* ... */ }
token, err := jwt.GenerateToken(priv, jwt.Claims{
ID: "user-1", Email: "a@example.com", IsAccess: true,
}, 24*time.Hour)
claims, err := jwt.ParseToken(token, &priv.PublicKey)
```
## CLI `jwt-token`
Prints a signed JWT to stdout (no trailing newline beyond what `fmt.Print` does for the token string).
```text
jwt-token -id USER -email user@example.com -key "$JWT_PRIVATE_KEY_B64"
jwt-token -id USER -email user@example.com -key-file ./private.pem -ttl 720h
```
Environment variables: `JWT_SUBJECT_ID`, `JWT_EMAIL`, `JWT_PRIVATE_KEY_B64`.
Flags override env when set. Use `-version` to print the release version (set at link time by GoReleaser).
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md). This project uses [Conventional Commits](https://www.conventionalcommits.org/) and [release-please](https://github.com/googleapis/release-please) for changelog and tags.
## License
MIT — see [LICENSE](LICENSE).