Skip to content

Simple user local authentication and organisation management written in Golang for sql drivers.

License

Notifications You must be signed in to change notification settings

rjarmstrong/gus

Repository files navigation

gus

gus

A simple user authentication and account management library with go/sql compatible implementations.

Benefits

  • No http or UI dependencies
  • Ideal for lightweight applications
  • Can use default sqlite3 driver without setting up a database
  • Low resource requirements
  • Easily compose in an existing application or extend to add additional functionality

Features

  • Local user authentication
    • Sign-up, Sign-in
    • Change and reset password
    • PLANNED: Locking with Rate limit locking
  • User management
  • Basic Organisation management

Get started

go get github.com/rjarmstrong/gus 

Set-up database

docker run --rm --name mysql -e MYSQL_ROOT_PASSWORD=rootPassword -p 127.0.0.1:3306:3306 -d mysql:5.7.18

Once the local instance is running create a new database:

docker exec mysql mysql -u root -prootPassword -e "CREATE DATABASE gus2"

| Note: In production don't use the password on the CLI and create a web user with a good password.

Integrate with package

 // Min config
 dsn := fmt.Sprintf("%s:%s@tcp(127.0.0.1:%s)/gus?parseTime=true&multiStatements=true", "root", "", "3306")
 o := gus.DbOptions{DataSourceName: dsn, Seed: true}
 db = gus.GetDb(o)
 users := gus.NewUsers(db)
	
 // Create user
 p := CreateUserParams{Email:"some@email.com"}
 user, tempPass, err := users.Create(p)
	
 // Sign-in
 p := &gus.SignInParams{Email:user.Email, Password:tempPass}
 u, err := users.Authenticate(*p)

Logging

By default debug logging is enabled you can either provide your own implementation *log.Logger

gus.DebugLogger = log.New(os.Stdout, "GUS: ", log.Ldate|log.Lmicroseconds|log.Lshortfile)

Or set it to nil to disable logging

gus.DebugLogger = nil

The same goes for gus.ErrorLogger

About

Simple user local authentication and organisation management written in Golang for sql drivers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages