go-simple-auth

command module
v0.0.0-...-3e3b5ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: GPL-3.0 Imports: 16 Imported by: 0

README

SIMPLE AUTH

Packages

go get github.com/gin-gonic/gin
go get github.com/golang-jwt/jwt/v5
go get gorm.io/gorm
go get gorm.io/driver/sqlite
go get golang.org/x/crypto/bcrypt

Run

go run main.go

Build

GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) go build -o $(pwd)/dist/go_auth_$(go env GOOS)_$(go env GOARCH)
cd dist

export export JWT_TOKEN=mysecret; export PORT=8081 && ./go_auth_$(go env GOOS)_$(go env GOARCH)

Endpoints

Create token
curl -X POST http://localhost:8080/auth/login -d '{"username": "admin", "password": "admin"}' -H "Content-Type: application/json" | jq .token
Renew token
curl -X POST http://localhost:8080/auth/renew -H "Content-Type: application/json" -H "Authorization: <TOKEN>" | jq .
Validate token
curl -X POST http://localhost:8080/auth/validate -H "Content-Type: application/json" -H "Authorization: <TOKEN>" | jq .
Health check
curl -X GET http://localhost:8080/auth/health | jq .

Docker

Create image

docker build -t go_auth:dev .

Force build

docker build --no-cache -t go_auth:dev .

Run container

docker run --rm --name go_auth -d --network host -e MIGRATE=true -e PORT=8081 -e JWT_TOKEN=mysecret go_auth:dev

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL