blamewarrior

package
v0.0.0-...-8200843 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2017 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Copyright (C) 2017 The BlameWarrior Authors.

This file is a part of BlameWarrior service.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	GetUserByNicknameQuery = "SELECT token, uid, nickname, avatar_url, name FROM users WHERE nickname = $1"
	SaveUserQuery          = `` /* 286-byte string literal not displayed */

)

Variables

View Source
var UserNotFound = errors.New("User not found")

Functions

func ConnectDatabase

func ConnectDatabase(dbName string, opts ...*DatabaseOptions) (*sql.DB, error)

func SaveUser

func SaveUser(runner SQLRunner, u *User) (err error)

Types

type DatabaseOptions

type DatabaseOptions struct {
	// Host is PostgreSQL database host
	Host string
	// Port is PostgreSQL database port
	Port string
	// User is connection user
	User string
	// Password is connection password to authenticate with
	Password string
}

DatabaseOptions is a configuration object type to pass PostgreSQL connection options.

func (*DatabaseOptions) ConnectionString

func (opts *DatabaseOptions) ConnectionString() string

ConnectionString returns a connection string suitable to for sql.DB().

type SQLRunner

type SQLRunner interface {
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	Prepare(string) (*sql.Stmt, error)
	Exec(string, ...interface{}) (sql.Result, error)
}

type User

type User struct {
	ID        int    `json:"-"`
	Token     string `json:"token"`
	UID       string `json:"uid"`
	Nickname  string `json:"nickname"`
	AvatarURL string `json:"avatar_url"`
	Name      string `json:"name"`
}

func GetUserByNickname

func GetUserByNickname(runner SQLRunner, nickname string) (*User, error)

func (User) Valid

func (u User) Valid() *Validator

type Validator

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

func (*Validator) ErrorMessages

func (v *Validator) ErrorMessages() []string

func (*Validator) IsValid

func (v *Validator) IsValid() bool

func (*Validator) MustNotBeEmpty

func (v *Validator) MustNotBeEmpty(value string, msgArgs ...interface{}) bool

Jump to

Keyboard shortcuts

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