Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 1.28 KB

README.md

File metadata and controls

64 lines (52 loc) · 1.28 KB

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

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
}