Example GoTuna UserProvider for Mysql
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`)
)
[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');
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,
}
type DBUser struct {
ID string
Email string
Name string
Phone string
PasswordHash string
}