Categorygithub.com/gotuna/mysqlusers
modulepackage
0.0.0-20210421111528-bf7ba3a83bec
Repository: https://github.com/gotuna/mysqlusers.git
Documentation: pkg.go.dev

# README

Example Mysql User Provider

Example GoTuna UserProvider for Mysql

Create mysql table

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email_UNIQUE` (`email`)
)

Insert sample users with credentials

[email protected] / test123
[email protected] / test456
INSERT INTO `users` (`email`, `name`, `phone`, `password_hash`) VALUES
('[email protected]', 'John', '555-0001', '$2a$10$lafA0tVo8mV8yyNaOhs.J.XUzpwkEPVhJILPQeST14jbkbolPQCua');

INSERT INTO `users` (`email`, `name`, `phone`, `password_hash`) VALUES
('[email protected]', 'Bob', '555-2555', '$2a$10$fijHLI3sd4llYNMwyKxEjO3zygFRBRYDY8sEozmWmf6nqvwimRZbe');

Usage

go get github.com/gotuna/mysqlusers
// open mysql connection
client, err := sql.Open("mysql", "dbuser:dbpass@/dbname?charset=utf8")
if err != nil {
	panic(err)
}

// create repository instance
repo := mysqlusers.NewRepository(client)

// use in GoTuna application
app := gotuna.App{
	UserRepository: repo,
}

User type

type DBUser struct {
	ID           string
	Email        string
	Name         string
	Phone        string
	PasswordHash string
}

# Functions

NewRepository returns a new mysql implementation of gotuna.UserRepository.

# Structs

DBUser is a sample gotuna.User implementation used with mysql.