backends

package
v0.0.0-...-92711a6 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATUS_ACTIVE   = 1
	STATUS_INACTIVE = 0
)

Variables

View Source
var PREPARE_MYSQL = []string{
	fmt.Sprintf(`CREATE TABLE IF NOT EXISTS Users (
		uid INTEGER PRIMARY KEY AUTO_INCREMENT,
		name VARCHAR(255) NOT NULL,
		password VARCHAR(255) NOT NULL,
		state INTEGER DEFAULT %d,
		CONSTRAINT SingleKeys UNIQUE (name)
	) ENGINE=InnoDB;`, STATUS_ACTIVE),
	`CREATE TABLE IF NOT EXISTS Groups (
		gid INTEGER PRIMARY KEY AUTO_INCREMENT,
		name VARCHAR(255) NOT NULL,
		CONSTRAINT SingleKeys UNIQUE (name)
	) ENGINE=InnoDB;`,
	`CREATE TABLE IF NOT EXISTS UserGroups (
		uid INTEGER NOT NULL,
		gid INTEGER NOT NULL,
		CONSTRAINT SingleKeys UNIQUE (uid, gid),
		CONSTRAINT FOREIGN KEY (uid) REFERENCES Users(uid) ON DELETE CASCADE,
		CONSTRAINT FOREIGN KEY (gid) REFERENCES Groups(gid) ON DELETE CASCADE
	) ENGINE=InnoDB;`,
	fmt.Sprintf(`CREATE TABLE IF NOT EXISTS UserValues (
		uid INTEGER,
		%s VARCHAR(255) NOT NULL,
		value LONGTEXT NOT NULL,
		CONSTRAINT SingleKeys UNIQUE (uid, %s),
		CONSTRAINT FOREIGN KEY (uid) REFERENCES Users(uid) ON DELETE CASCADE
	) ENGINE=InnoDB;`, "`key`", "`key`"),
}
View Source
var PREPARE_POSTGRES = []string{
	fmt.Sprintf(`CREATE TABLE IF NOT EXISTS Users (
		uid INTEGER PRIMARY KEY DEFAULT nextval('UsersSeq'),
		name TEXT NOT NULL,
		password TEXT NOT NULL,
		state INTEGER DEFAULT %d,
		CONSTRAINT UniqueUserNames UNIQUE (name)
	);`, STATUS_ACTIVE),
	`CREATE TABLE IF NOT EXISTS Groups (
		gid INTEGER PRIMARY KEY DEFAULT nextval('GroupsSeq'),
		name TEXT NOT NULL,
		CONSTRAINT UniqueGroupNames UNIQUE (name)
	);`,
	`CREATE TABLE IF NOT EXISTS UserGroups (
		uid INTEGER NOT NULL REFERENCES Users(uid) ON DELETE CASCADE,
		gid INTEGER NOT NULL REFERENCES Groups(gid) ON DELETE CASCADE,
		CONSTRAINT UniqueUidGidPairs UNIQUE (uid, gid)
	);`,
	`CREATE TABLE IF NOT EXISTS UserValues (
		uid INTEGER REFERENCES Users(uid) ON DELETE CASCADE,
		key TEXT NOT NULL,
		value TEXT NOT NULL,
		CONSTRAINT UniqueUidKeyPairs UNIQUE (uid, key)
	);`,
}
View Source
var PREPARE_SQLITE = []string{
	`PRAGMA encoding = "UTF-8";`,
	"PRAGMA foreign_keys = ON;",
	"PRAGMA journal_mode;",
	"PRAGMA integrity_check;",
	"PRAGMA busy_timeout = 60000;",
	"PRAGMA auto_vacuum = INCREMENTAL;",
	fmt.Sprintf(`CREATE TABLE IF NOT EXISTS Users (
		uid INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		password TEXT NOT NULL,
		state INTEGER DEFAULT %d,
		CONSTRAINT UniqueUserNames UNIQUE (name) ON CONFLICT ROLLBACK
	);`, STATUS_ACTIVE),
	`CREATE TABLE IF NOT EXISTS Groups (
		gid INTEGER PRIMARY KEY AUTOINCREMENT,
		name TEXT NOT NULL,
		CONSTRAINT UniqueGroupNames UNIQUE (name) ON CONFLICT ROLLBACK
	);`,
	`CREATE TABLE IF NOT EXISTS UserGroups (
		uid INTEGER NOT NULL REFERENCES Users(uid) ON DELETE CASCADE,
		gid INTEGER NOT NULL REFERENCES Groups(gid) ON DELETE CASCADE,
		CONSTRAINT UniqueUidGidPairs UNIQUE (uid, gid) ON CONFLICT IGNORE
	);`,
	`CREATE TABLE IF NOT EXISTS UserValues (
		uid INTEGER REFERENCES Users(uid) ON DELETE CASCADE,
		key TEXT NOT NULL,
		value BLOB NOT NULL,
		CONSTRAINT UniqueUidKeyPairs UNIQUE (uid, key) ON CONFLICT REPLACE
	);`,
}

Functions

This section is empty.

Types

type Abstract

type Abstract interface {
	CreateUser(name string, password string) (int64, *Error)
	DisableUser(nameuid string) *Error
	EnableUser(nameuid string) *Error
	SetUserData(nameuid string, key string, value string) *Error
	GetUserData(nameuid string, key string) (string, *Error)
	GetUserDataKeys(nameuid string) ([]string, *Error)
	LoginUser(name string, password string) (int64, *Error)
	ChangeUserPassword(nameuid string, password string, newpassword string) *Error
	ChangeUserName(nameuid string, password string, newname string) *Error
	UserGroups(nameuid string) ([]Group, *Error)
	DeleteUser(nameuid string) *Error
	Users() ([]User, *Error)
	CreateGroup(name string) (int64, *Error)
	AddUserToGroup(nameuid string, groupgid string) *Error
	RemoveUserFromGroup(nameuid string, groupgid string) *Error
	DeleteGroup(groupgid string) *Error
	Groups() ([]Group, *Error)
	GroupUsers(groupgid string) ([]User, *Error)
	Stats() (stats map[string]int64, err *Error)
	Close()
}

type Error

type Error struct {
	Code    string
	Message string
}

func (*Error) Error

func (e *Error) Error() string

type Group

type Group struct {
	Gid  int64
	Name string
}

func (Group) String

func (g Group) String() string

type MysqlBackend

type MysqlBackend struct {
	SqlBackend
}

func NewMysqlBackend

func NewMysqlBackend(url string) (MysqlBackend, error)

type NilBackend

type NilBackend struct {
}

func (*NilBackend) AddUserToGroup

func (backend *NilBackend) AddUserToGroup(nameuid string, groupgid string) *Error

func (*NilBackend) ChangeUserName

func (backend *NilBackend) ChangeUserName(nameuid string, password string, newname string) *Error

func (*NilBackend) ChangeUserPassword

func (backend *NilBackend) ChangeUserPassword(nameuid string, password string, newpassword string) *Error

func (*NilBackend) Close

func (backend *NilBackend) Close()

func (*NilBackend) CreateGroup

func (backend *NilBackend) CreateGroup(name string) (int64, *Error)

func (*NilBackend) CreateUser

func (backend *NilBackend) CreateUser(name string, password string) (int64, *Error)

func (*NilBackend) DeleteGroup

func (backend *NilBackend) DeleteGroup(groupgid string) *Error

func (*NilBackend) DeleteUser

func (backend *NilBackend) DeleteUser(nameuid string) *Error

func (*NilBackend) DisableUser

func (backend *NilBackend) DisableUser(nameuid string) *Error

func (*NilBackend) EnableUser

func (backend *NilBackend) EnableUser(nameuid string) *Error

func (*NilBackend) GetUserData

func (backend *NilBackend) GetUserData(nameuid string, key string) (string, *Error)

func (*NilBackend) GetUserDataKeys

func (backend *NilBackend) GetUserDataKeys(nameuid string) (keys []string, err *Error)

func (*NilBackend) GroupUsers

func (backend *NilBackend) GroupUsers(groupgid string) ([]User, *Error)

func (*NilBackend) Groups

func (backend *NilBackend) Groups() ([]Group, *Error)

func (*NilBackend) LoginUser

func (backend *NilBackend) LoginUser(name string, password string) (int64, *Error)

func (*NilBackend) RemoveUserFromGroup

func (backend *NilBackend) RemoveUserFromGroup(nameuid string, groupgid string) *Error

func (*NilBackend) SetUserData

func (backend *NilBackend) SetUserData(nameuid string, key string, value string) *Error

func (*NilBackend) Stats

func (backend *NilBackend) Stats() (map[string]int64, *Error)

func (*NilBackend) UserGroups

func (backend *NilBackend) UserGroups(nameuid string) ([]Group, *Error)

func (*NilBackend) Users

func (backend *NilBackend) Users() ([]User, *Error)

type PostgresBackend

type PostgresBackend struct {
	SqlBackend
}

func NewPostgresBackend

func NewPostgresBackend(url string) (PostgresBackend, error)

func (*PostgresBackend) CreateGroup

func (backend *PostgresBackend) CreateGroup(name string) (int64, *Error)

func (*PostgresBackend) CreateUser

func (backend *PostgresBackend) CreateUser(name string, password string) (int64, *Error)

type SqlBackend

type SqlBackend struct {
	// contains filtered or unexported fields
}

func (*SqlBackend) AddUserToGroup

func (backend *SqlBackend) AddUserToGroup(nameuid string, groupgid string) *Error

func (*SqlBackend) ChangeUserName

func (backend *SqlBackend) ChangeUserName(nameuid string, password string, newname string) *Error

func (*SqlBackend) ChangeUserPassword

func (backend *SqlBackend) ChangeUserPassword(nameuid string, password string, newpassword string) *Error

func (*SqlBackend) Close

func (backend *SqlBackend) Close()

func (*SqlBackend) CreateGroup

func (backend *SqlBackend) CreateGroup(name string) (int64, *Error)

func (*SqlBackend) CreateUser

func (backend *SqlBackend) CreateUser(name string, password string) (int64, *Error)

func (*SqlBackend) DeleteGroup

func (backend *SqlBackend) DeleteGroup(groupgid string) *Error

func (*SqlBackend) DeleteUser

func (backend *SqlBackend) DeleteUser(nameuid string) *Error

func (*SqlBackend) DisableUser

func (backend *SqlBackend) DisableUser(nameuid string) *Error

func (*SqlBackend) EnableUser

func (backend *SqlBackend) EnableUser(nameuid string) *Error

func (*SqlBackend) GetUserData

func (backend *SqlBackend) GetUserData(nameuid string, key string) (string, *Error)

func (*SqlBackend) GetUserDataKeys

func (backend *SqlBackend) GetUserDataKeys(nameuid string) (keys []string, err *Error)

func (*SqlBackend) GroupUsers

func (backend *SqlBackend) GroupUsers(groupgid string) ([]User, *Error)

func (*SqlBackend) Groups

func (backend *SqlBackend) Groups() ([]Group, *Error)

func (*SqlBackend) IncFailCount

func (backend *SqlBackend) IncFailCount(nameuid string) (err *Error)

func (*SqlBackend) LoginUser

func (backend *SqlBackend) LoginUser(name string, password string) (uid int64, err *Error)

func (*SqlBackend) RemoveUserFromGroup

func (backend *SqlBackend) RemoveUserFromGroup(nameuid string, groupgid string) *Error

func (*SqlBackend) SaveLastLogin

func (backend *SqlBackend) SaveLastLogin(nameuid string) (err *Error)

func (*SqlBackend) SetUserData

func (backend *SqlBackend) SetUserData(nameuid string, key string, value string) *Error

func (*SqlBackend) Stats

func (backend *SqlBackend) Stats() (stats map[string]int64, err *Error)

func (*SqlBackend) UserGroups

func (backend *SqlBackend) UserGroups(nameuid string) ([]Group, *Error)

func (*SqlBackend) Users

func (backend *SqlBackend) Users() ([]User, *Error)

type SqliteBackend

type SqliteBackend struct {
	SqlBackend
}

func NewSqliteBackend

func NewSqliteBackend(url string) (SqliteBackend, error)

func (*SqliteBackend) CreateGroup

func (backend *SqliteBackend) CreateGroup(name string) (gid int64, err *Error)

func (*SqliteBackend) CreateUser

func (backend *SqliteBackend) CreateUser(name string, password string) (uid int64, err *Error)

type User

type User struct {
	Uid    int64
	Name   string
	Active bool
}

func (User) String

func (u User) String() string

Jump to

Keyboard shortcuts

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