util

package module
v0.0.0-...-580ff5b Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2016 License: MIT Imports: 14 Imported by: 3

README

util

Utilities for Go.

Documentation

Index

Constants

View Source
const JSONTimeLayout string = "\"2006-01-02T15:04:05.000Z\""
View Source
const MaxNumOfFilterValue int = 5
View Source
const MaxTake uint64 = 30

Variables

This section is empty.

Functions

func IndexOfString

func IndexOfString(slice []string, item string) int

Types

type BaseProvider

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

func NewBaseProvider

func NewBaseProvider() *BaseProvider

func (*BaseProvider) AddFilter

func (p *BaseProvider) AddFilter(k, v string)

func (*BaseProvider) GetFilters

func (p *BaseProvider) GetFilters() Filters

func (*BaseProvider) GetSkip

func (p *BaseProvider) GetSkip() uint64

func (*BaseProvider) GetSort

func (p *BaseProvider) GetSort() string

func (*BaseProvider) GetStat

func (p *BaseProvider) GetStat() bool

func (*BaseProvider) GetTake

func (p *BaseProvider) GetTake() uint64

func (*BaseProvider) LimitFilterKeys

func (p *BaseProvider) LimitFilterKeys(keys ...string)

func (*BaseProvider) LimitSortKeys

func (p *BaseProvider) LimitSortKeys(keys ...string)

func (*BaseProvider) ParseRequest

func (p *BaseProvider) ParseRequest(r *http.Request)

func (*BaseProvider) SetSkip

func (p *BaseProvider) SetSkip(v uint64)

func (*BaseProvider) SetSort

func (p *BaseProvider) SetSort(k string)

func (*BaseProvider) SetStat

func (p *BaseProvider) SetStat(v bool)

func (*BaseProvider) SetTake

func (p *BaseProvider) SetTake(v uint64)

type Delegate

type Delegate struct {
	Data interface{}
	// contains filtered or unexported fields
}

func (*Delegate) Add

func (d *Delegate) Add(f func())

func (Delegate) Invoke

func (d Delegate) Invoke()

type Filter

type Filter interface {
	LimitFilterKeys(keys ...string)
	AddFilter(key, value string)
	GetFilters() Filters
}

type Filters

type Filters map[string][]string

type JSONTime

type JSONTime time.Time

func (JSONTime) Equal

func (t JSONTime) Equal(t2 JSONTime) bool

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

func (JSONTime) String

func (t JSONTime) String() string

func (JSONTime) Time

func (t JSONTime) Time() time.Time

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(data []byte) error

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

func (NullTime) MarshalJSON

func (nt NullTime) MarshalJSON() ([]byte, error)

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NullTime) UnmarshalJSON

func (nt *NullTime) UnmarshalJSON(data []byte) error

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Pager

type Pager interface {
	SetTake(v uint)
	SetSkip(v uint)
}

type Provider

type Provider interface {
	Pager
	Filter
	Sorter
	ParseRequest(r *http.Request)

	Read(dst interface{}) (*ProviderResponse, error)
}

type ProviderResponse

type ProviderResponse struct {
	Stat map[string]int `json:"stat"`
	Data interface{}    `json:"data"`
}

type RequestWrapper

type RequestWrapper struct {
	*http.Request
}

func Request

func Request(r *http.Request) RequestWrapper

func (RequestWrapper) DecodeBody

func (r RequestWrapper) DecodeBody(to interface{}) error

type ResponseWrapper

type ResponseWrapper struct {
	http.ResponseWriter
}

func (ResponseWrapper) Error

func (r ResponseWrapper) Error(message interface{}, args ...interface{})

func (ResponseWrapper) RawError

func (r ResponseWrapper) RawError(message interface{}, args ...interface{})

func (ResponseWrapper) Send

func (r ResponseWrapper) Send(status int, data ...interface{})

type Sorter

type Sorter interface {
	LimitSortKeys(keys ...string)
	SetSort(key string)
	GetSort() string
}

type SqlProvider

type SqlProvider struct {
	*BaseProvider
	// contains filtered or unexported fields
}

func NewSqlProvider

func NewSqlProvider(dbx *sqlx.DB, table string, s interface{}) *SqlProvider

func (*SqlProvider) ParseStruct

func (p *SqlProvider) ParseStruct(s interface{})

func (*SqlProvider) Read

func (p *SqlProvider) Read(dst interface{}) (*ProviderResponse, error)

func (*SqlProvider) SetWhere

func (p *SqlProvider) SetWhere(where map[string]interface{})

type SquirrelDBProxy

type SquirrelDBProxy struct {
	*sql.DB
}

func (*SquirrelDBProxy) QueryRow

func (p *SquirrelDBProxy) QueryRow(sql string, args ...interface{}) squirrel.RowScanner

type Txx

type Txx struct {
	*sql.Tx
	AfterCommit    Delegate
	BeforeRollback Delegate
}

func (Txx) Commit

func (tx Txx) Commit() error

func (Txx) Rollback

func (tx Txx) Rollback() error

func (Txx) RollbackWithErrorf

func (tx Txx) RollbackWithErrorf(f string, args ...interface{}) error

type ValidationContext

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

func NewValidationContext

func NewValidationContext() *ValidationContext

func (*ValidationContext) AddError

func (v *ValidationContext) AddError(key, message string)

func (*ValidationContext) Errors

func (v *ValidationContext) Errors() ValidationErrors

func (*ValidationContext) HasError

func (v *ValidationContext) HasError() bool

func (*ValidationContext) ToError

func (v *ValidationContext) ToError() *ValidationError

type ValidationError

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

func NewValidationError

func NewValidationError(v *ValidationContext) *ValidationError

func (*ValidationError) Error

func (ve *ValidationError) Error() string

func (*ValidationError) ToResponseData

func (ve *ValidationError) ToResponseData() map[string]interface{}

func (*ValidationError) ValidationErrors

func (ve *ValidationError) ValidationErrors() ValidationErrors

type ValidationErrorInterface

type ValidationErrorInterface interface {
	ValidationErrors() ValidationErrors
	ToResponseData() map[string]interface{}
}

type ValidationErrors

type ValidationErrors map[string][]string

Jump to

Keyboard shortcuts

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