util

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package uniuri generates random strings good for use in URIs to identify unique objects.

Example usage:

s := util.UniUriNew() // s is now "apHCJBl7L1OmC57n"

A standard string created by New() is 16 bytes in length and consists of Latin upper and lowercase letters, and numbers (from the set of 62 allowed characters), which means that it has ~95 bits of entropy. To get more entropy, you can use NewLen(UUIDLen), which returns 20-byte string, giving ~119 bits of entropy, or any other desired length.

Functions read from crypto/rand random source, and panic if they fail to read from it.

Index

Constants

View Source
const (
	// StdLen is a standard length of uniuri string to achive ~95 bits of entropy.
	StdLen = 16
	// UUIDLen is a length of uniuri string to achive ~119 bits of entropy, closest
	// to what can be losslessly converted to UUIDv4 (122 bits).
	UUIDLen = 20
)

Variables

View Source
var (
	DefaultLimit = int(10)
	MinLimit     = int(1)
	MaxLimit     = int(500)
	LimitParam   = "page_size"
	DefaultPage  = int(1)
	PageParam    = "page"
)
View Source
var Config *configType
View Source
var InteractiveSetup bool
View Source
var (
	// OrderParam is the key of the url
	// order parameter
	OrderParam = "order_by"
)
View Source
var Secrets bool
View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars is a set of standard characters allowed in uniuri string.

View Source
var Version = "0.5.6"

Version is the current Tensor Version This must update with the VERSION file in the SCM root directory

View Source
var Wrapper = Wrap

Wrapper make sure we are backward compatible

Functions

func BlockHandler added in v0.4.0

func BlockHandler() gin.HandlerFunc

BlockHandler will pass the call from /debug/pprof/block to pprof

func Cipher added in v0.5.2

func Cipher(text string) string

CipherEncrypt encrypts string to base64 crypto using AES

func CmdlineHandler added in v0.4.0

func CmdlineHandler() gin.HandlerFunc

CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof

func Decipher added in v0.5.2

func Decipher(cryptoText string) []byte

CipherDecrypt from base64 to decrypted string

func GenerateSalt added in v0.0.12

func GenerateSalt()

func GoroutineHandler added in v0.4.0

func GoroutineHandler() gin.HandlerFunc

GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof

func HeapHandler added in v0.4.0

func HeapHandler() gin.HandlerFunc

HeapHandler will pass the call from /debug/pprof/heap to pprof

func IndexHandler added in v0.4.0

func IndexHandler() gin.HandlerFunc

IndexHandler will pass the call from /debug/pprof to pprof

func MutexHandler added in v0.5.2

func MutexHandler() gin.HandlerFunc

MutexHandler will pass the call from /debug/pprof/mutex to pprof

func ProfileHandler added in v0.4.0

func ProfileHandler() gin.HandlerFunc

ProfileHandler will pass the call from /debug/pprof/profile to pprof

func SymbolHandler added in v0.4.0

func SymbolHandler() gin.HandlerFunc

SymbolHandler will pass the call from /debug/pprof/symbol to pprof

func ThreadCreateHandler added in v0.4.0

func ThreadCreateHandler() gin.HandlerFunc

ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof

func TraceHandler added in v0.4.0

func TraceHandler() gin.HandlerFunc

TraceHandler will pass the call from /debug/pprof/trace to pprof

func UniqueNew added in v0.0.5

func UniqueNew() string

New returns a new random string of the standard length, consisting of standard characters.

func UniqueNewLen added in v0.0.5

func UniqueNewLen(length int) string

NewLen returns a new random string of the provided length, consisting of standard characters.

func UniqueNewLenChars added in v0.0.5

func UniqueNewLenChars(length int, chars []byte) string

NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).

func Wrap added in v0.4.0

func Wrap(router *gin.Engine)

Wrap adds several routes from package `net/http/pprof` to *gin.Engine object

func WrapGroup added in v0.5.2

func WrapGroup(router *gin.RouterGroup)

WrapGroup adds several routes from package `net/http/pprof` to *gin.RouterGroup object

Types

type MongoDBConfig

type MongoDBConfig struct {
	Hosts      []string `yaml:"hosts"`
	Username   string   `yaml:"user"`
	Password   string   `yaml:"pass"`
	DbName     string   `yaml:"name"`
	ReplicaSet string   `yaml:"replica_set"`
}

type Pagination

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

func NewPagination

func NewPagination(c *gin.Context, n int) *Pagination

func (*Pagination) End

func (p *Pagination) End() int

for slices

func (*Pagination) HasPage

func (p *Pagination) HasPage() bool

func (*Pagination) Limit

func (p *Pagination) Limit() int

func (*Pagination) NextPage

func (p *Pagination) NextPage() interface{}

func (*Pagination) Offset

func (p *Pagination) Offset() int

func (*Pagination) Page

func (p *Pagination) Page() int

func (*Pagination) PreviousPage

func (p *Pagination) PreviousPage() interface{}

func (*Pagination) Skip

func (p *Pagination) Skip() int

for slices

type QueryParser

type QueryParser struct {
	From url.Values
	// contains filtered or unexported fields
}

QueryParser used to store the context and gin request form

func NewQueryParser

func NewQueryParser(c *gin.Context) QueryParser

NewQueryParser initialize a new QueryParser

func (*QueryParser) Contains added in v0.0.4

func (p *QueryParser) Contains(fields []string, query bson.M) bson.M

Contains adds regex to mgo query to check a field contain a value accepting fields must pass to fields parameter

func (*QueryParser) Endswith added in v0.0.4

func (p *QueryParser) Endswith(fields []string, query bson.M) bson.M

Endswith adds regex to mgo query to check a field endswith a value accepting fields must pass to fields parameter

func (*QueryParser) Eq added in v0.0.4

func (p *QueryParser) Eq(fields []string, query bson.M) bson.M

Eq check the given field or related object is equel to given value

func (*QueryParser) Exact added in v0.0.4

func (p *QueryParser) Exact(fields []string, query bson.M) bson.M

Exact adds regex to mgo query to check a field is an exact match accepting fields must pass to fields parameter

func (*QueryParser) Gt added in v0.0.4

func (p *QueryParser) Gt(fields []string, query bson.M) bson.M

Gt adds $gt to mgo query to check a field greater than the comparison value accepting fields must pass to fields parameter

func (*QueryParser) Gte added in v0.0.4

func (p *QueryParser) Gte(fields []string, query bson.M) bson.M

Gte adds $gte to mgo query to check a field greater or equal to the comparison value accepting fields must pass to fields parameter

func (*QueryParser) IContains

func (p *QueryParser) IContains(s []string, query bson.M) bson.M

IContains adds regex to mgo query to check a field contain a value this is the case insensitive version of contains accepting fields must pass to fields parameter

func (*QueryParser) IEndswith added in v0.0.4

func (p *QueryParser) IEndswith(s []string, query bson.M) bson.M

IEndswith adds regex to mgo query to check a field endswith a value this is the case insensitive version of endswith accepting fields must pass to fields parameter

func (*QueryParser) IExact added in v0.0.4

func (p *QueryParser) IExact(s []string, query bson.M) bson.M

IExact adds regex to mgo query to check a field is an exact match this is the case insensitive version of Exact accepting fields must pass to fields parameter

func (*QueryParser) IStartswith added in v0.0.4

func (p *QueryParser) IStartswith(s []string, query bson.M) bson.M

IStartswith adds regex to mgo query to check a field startswith a value this is the case insensitive version of startswith accepting fields must pass to fields parameter

func (*QueryParser) In added in v0.0.4

func (p *QueryParser) In(fields []string, query bson.M) bson.M

In Check the given field's value is present in the list provide accepting fields must pass to fields parameter

func (*QueryParser) IsNull added in v0.0.4

func (p *QueryParser) IsNull(fields []string, query bson.M) bson.M

IsNull check the given field or related object is null

func (*QueryParser) Lookups added in v0.0.4

func (p *QueryParser) Lookups(fields []string, query bson.M) bson.M

Lookups calls all lookup functions

func (*QueryParser) Lt added in v0.0.4

func (p *QueryParser) Lt(fields []string, query bson.M) bson.M

Lt adds $lt to mgo query to check a field less than the comparison value accepting fields must pass to fields parameter

func (*QueryParser) Lte added in v0.0.4

func (p *QueryParser) Lte(fields []string, query bson.M) bson.M

Lte adds $lte to mgo query to check a field less than or equal to the comparison value accepting fields must pass to fields parameter

func (*QueryParser) Match

func (p *QueryParser) Match(s []string, query bson.M) bson.M

Match adds equality condition to match an exact match

func (*QueryParser) Ne added in v0.0.4

func (p *QueryParser) Ne(fields []string, query bson.M) bson.M

Ne check the given field or related object is not equal to given value

func (*QueryParser) OrderBy

func (p *QueryParser) OrderBy() string

OrderBy appends order_by clause to mongodb query

func (*QueryParser) Startswith added in v0.0.4

func (p *QueryParser) Startswith(fields []string, query bson.M) bson.M

Startswith adds regex to mgo query to check a field startswith a value accepting fields must pass to fields parameter

type RedisConfig added in v0.2.0

type RedisConfig struct {
	Host string `yaml:"host"`
}

Jump to

Keyboard shortcuts

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