common

package
v0.0.0-...-2fddd97 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorWrongOTPCode           = "Wrong OTP Code"
	ErrorWrongLoginInfo         = "Wrong Email/Phonenumber or Password"
	ErrorIdentifierAlreadyExist = "Email/Phonenumber Already Registered on Your Company"
	ErrorNotUpdateRowNotExist   = "Cannot Update, Row is Not Existed"
)

Variables

This section is empty.

Functions

func ContextWithDuration

func ContextWithDuration() (context.Context, context.CancelFunc)

ContextWithDuration creates context with timeout

func OTP

func OTP(digit int) (string, error)

func RandomBase64

func RandomBase64() string

func SHA256

func SHA256(s string) string

Types

type DBTx

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

DBTx is used as an interface for sqlx.Tx and sqlx.DB

type Pagination

type Pagination struct {
	Page  int
	Limit int
}

Pagination is the structure data for pagination

func ParsePaginationForm

func ParsePaginationForm(r *http.Request) (Pagination, error)

ParsePaginationForm is used to Parse Pagination Form from request

type PaginationRepo

type PaginationRepo struct {
	Offset int
	Limit  int
}

PaginationRepo is used as pagination when listing data Why using lastID instead of offset? Because in mysql, using limit X, Y will read X + Y rows, instead of only Y rows. Mysql reads all X + Y rows, then drop rows before X. Read this for more explanation: https://stackoverflow.com/questions/3799193/mysql-data-best-way-to-implement-paging#comment4027585_3799223

Jump to

Keyboard shortcuts

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