mysqlusers

package module
v0.0.0-...-bf7ba3a Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 8 Imported by: 0

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

john@example.com / test123
bob@example.com / test456
INSERT INTO `users` (`email`, `name`, `phone`, `password_hash`) VALUES
('john@example.com', 'John', '555-0001', '$2a$10$lafA0tVo8mV8yyNaOhs.J.XUzpwkEPVhJILPQeST14jbkbolPQCua');

INSERT INTO `users` (`email`, `name`, `phone`, `password_hash`) VALUES
('bob@example.com', '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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRepository

func NewRepository(db *sql.DB) gotuna.UserRepository

NewRepository returns a new mysql implementation of gotuna.UserRepository

Types

type DBUser

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

DBUser is a sample gotuna.User implementation used with mysql

func (DBUser) GetID

func (u DBUser) GetID() string

GetID should return auto-incremented, unique "id" field from mysql database for this user

Jump to

Keyboard shortcuts

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