utils

package
v0.0.0-...-861d2e8 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2016 License: BSD-2-Clause Imports: 32 Imported by: 6

Documentation

Overview

这里实现bitmap索引

Package serving provides ...

Package utils provides ...

Package utils provides ...

Package utils provides ... copy from http://golang.org/src/pkg/encoding/json/tags.go

copy from github.com/zenazn/goji/web/util

Index

Constants

View Source
const AuthTag = "dm"

Variables

View Source
var MinMaxError = errors.New("Min cannot be greater than max.")

Functions

func FieldByIndex

func FieldByIndex(v reflect.Value, index []int) reflect.Value

{{{ func FieldByIndex(v reflect.Value, index []int) reflect.Value * 通过索引返回field

func FieldExists

func FieldExists(i interface{}, f string) bool

{{{ func FieldExists(i interface{},f string) bool * 判断一个结构变量是否有某个字段

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func GetFuncName

func GetFuncName(i interface{}) string

get function name

func GetRealString

func GetRealString(v reflect.Value) string

{{{ func GetRealString(v reflect.Value) string *

func GrepFile

func GrepFile(patten string, filename string) (lines []string, err error)

like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read

func HashSha1

func HashSha1(i ...string) string

{{{ func HashSha1(orig, salt string) string * 密码加密

func ImportValue

func ImportValue(i interface{}, is map[string]string) (err error)

{{{ func ImportVal(i interface{}, import map[string]string) (err error) * 将tag匹配的值导入结构

func InSlice

func InSlice(v string, sl []string) bool

InSlice checks given string in string slice or not.

func InSliceIface

func InSliceIface(v interface{}, sl []interface{}) bool

InSliceIface checks given interface in interface slice.

func InSliceInt

func InSliceInt(v int, sl []int) bool

InSliceInt checks given int in int slice or not.

func IntRange

func IntRange(min, max int) (int, error)

{{{ func IntRange(min, max int) (int, error) *

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

{{{ func IsEmptyValue(v reflect.Value) bool *

func LengthenUUID

func LengthenUUID(s string) (ls string)

func NewShortUUID

func NewShortUUID() string

func NewShortUUID5

func NewShortUUID5(namespace, data string) string

func NewUUID

func NewUUID() string

default, version 4

func NewUUID5

func NewUUID5(namespace, data string) string

generate uuid v5 namespace直接写域名或者url

func ParseFloat

func ParseFloat(f float64) float64

func ParseOTP

func ParseOTP(header http.Header, key string) (value, typ, sn string, err error)

ParseOTP parses x-qh-otp headers.

func ParseValueAndParams

func ParseValueAndParams(header http.Header, key string) (value string, params map[string]string)

ParseValueAndParams parses a comma separated list of values with optional semicolon separated name-value pairs. Content-Type and Content-Disposition headers are in this format.

func PurgeSlice

func PurgeSlice(v string, sl []string) []string

Purge Slice

func RandomCreateBytes

func RandomCreateBytes(n int, alphabets string) []byte

RandomCreateBytes generate random []byte by specify chars. func RandomCreateBytes(n int, alphabets ...byte) []byte {

func ReadIntFromBytes

func ReadIntFromBytes(bs []byte) (r int)

{{{ func ReadIntFromBytes(bs []byte) (r int) *

func ReadLines

func ReadLines(path string) ([]string, error)

readLines reads a whole file into memory and returns a slice of its lines.

func Round

func Round(f float64, n int) float64

func SearchFile

func SearchFile(filename string, paths ...string) (fullpath string, err error)

Search a file in paths. this is often used in search config file in /etc ~/

func SelfDir

func SelfDir() string

SelfDir gets compiled executable file directory

func SelfPath

func SelfPath() string

SelfPath gets compiled executable file absolute path

func ShortenUUID

func ShortenUUID(s string) (ss string)

func Shuffle

func Shuffle(a []interface{})

func ShuffleInt

func ShuffleInt(a []int)

func ShuffleString

func ShuffleString(a []string)

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})

SliceChuck separates one slice to some sized slice.

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

SliceFilter generates a new slice after filter function.

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns diff slice of slice2 - slice1.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

SlicePad prepends size number of val into slice.

func SliceRand

func SliceRand(a []interface{}) (b interface{})

SliceRand returns random one from slice.

func SliceRandList

func SliceRandList(min, max int) []int

SliceRandList generate an int slice from min to max.

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

SliceRange generates a new slice from begin to end with step duration of int64 number.

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

SliceReduce generates a new slice after parsing every value by reduce function

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

SliceShuffle shuffles a slice.

func SliceSum

func SliceSum(intslice []int64) (sum int64)

SliceSum sums all values in int64 slice.

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueslice []interface{})

SliceUnique cleans repeated values in slice.

func Underscore

func Underscore(camelCaseWord string) string

{{{ Underscore * 小程序, 把驼峰式转化为匈牙利式

func WriteLines

func WriteLines(lines []string, path string) error

writeLines writes the lines to the given file.

Types

type Attachment

type Attachment struct {
	Filename string
	Header   textproto.MIMEHeader
	Content  []byte
}

Attachment is a struct representing an email attachment. Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question

type Auth

type Auth struct {
	SecretKeyID    string
	SecretKey      string
	Signature      string
	StringToSign   string
	ClientUniqueID string
	Path           string
	Date           string
	ExpectedSign   string
}

func (*Auth) CheckAuth

func (a *Auth) CheckAuth(r *http.Request) error

{{{ CheckAuth

type BitmapIndex

type BitmapIndex struct {
	Data  []byte //数据用[]byte存放,一个元素(block)8bit
	Ext   []byte //扩展数据,也是[]byte
	Start int    //开始的block
	End   int    //结束的block
}

func NewBitmapIndex

func NewBitmapIndex(s []int) *BitmapIndex

{{{ func NewBitmapIndex(s []int) *BitmapIndex * 根据一个整数slice建立索引

func OR

func OR(bis []*BitmapIndex) (obi *BitmapIndex)

{{{ func OR(bis []*BitmapIndex) *BitmapIndex * 求所有索引并集

func ReadBitmapIndex

func ReadBitmapIndex(ib []byte) (bi *BitmapIndex, err error)

{{{ func ReadBitmapIndex(ib []byte) (*BitmapIndex,error) * 从[]byte里读取BitmapIndex,应用场景为从文件或者内存中拿到[]byte,转化为索引

func (*BitmapIndex) And

func (bi *BitmapIndex) And(obi *BitmapIndex) (nbi *BitmapIndex)

{{{ func (bi *BitmapIndex) And(obi *BitmapIndex) *BitmapIndex * 求交集

func (*BitmapIndex) AndBreak

func (bi *BitmapIndex) AndBreak(obis []*BitmapIndex) (nbi *BitmapIndex)

{{{ func (bi *BitmapIndex) AndBreak(obis []*BitmapIndex) *BitmapIndex * 第一个交集不为空

func (*BitmapIndex) Bytes

func (bi *BitmapIndex) Bytes() (ib []byte, err error)

{{{ func (bi *BitmapIndex) Bytes() ([]byte, error) * 将BitmapIndex转化为[]byte,方便存放到文件或者内存中去

func (*BitmapIndex) Not

func (bi *BitmapIndex) Not(obi *BitmapIndex) (nbi *BitmapIndex)

{{{ func (bi *BitmapIndex) Not(obi *BitmapIndex) *BitmapIndex * 求差集

func (*BitmapIndex) Or

func (bi *BitmapIndex) Or(obi *BitmapIndex) (nbi *BitmapIndex)

{{{ func (bi *BitmapIndex) Or(obi *BitmapIndex) *BitmapIndex * 求合集

func (*BitmapIndex) Slices

func (bi *BitmapIndex) Slices() (s []int, err error)

{{{ func (bi *BitmapIndex) Slices() ([]int, error) * 将BitmapIndex转化为[]int

type Choice

type Choice struct {
	Weight int
	Item   interface{}
}

A Choice contains a generic item and a weight controlling the frequency with which it will be selected.

func WeightedChoice

func WeightedChoice(choices []Choice) (Choice, error)

WeightedChoice used weighted random selection to return one of the supplied choices. Weights of 0 are never selected. All other weight values are relative. E.g. if you have two choices both weighted 3, they will be returned equally often; and each will be returned 3 times as often as a choice weighted 1.

type Email

type Email struct {
	Auth        smtp.Auth
	Identity    string `json:"identity"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	Host        string `json:"host"`
	Port        int    `json:"port"`
	From        string `json:"from"`
	To          []string
	Bcc         []string
	Cc          []string
	Subject     string
	Text        string // Plaintext message (optional)
	HTML        string // Html message (optional)
	Headers     textproto.MIMEHeader
	Attachments []*Attachment
	ReadReceipt []string
}

Email is the type used for email messages

func NewEMail

func NewEMail(config string) *Email

NewEMail create new Email struct with config json. config json is followed from Email struct fields.

func (*Email) Attach

func (e *Email) Attach(r io.Reader, filename string, c string) (a *Attachment, err error)

Attach is used to attach content from an io.Reader to the email. Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type.

func (*Email) AttachFile

func (e *Email) AttachFile(filename string) (a *Attachment, err error)

Add attach file to the send mail

func (*Email) Bytes

func (e *Email) Bytes() ([]byte, error)

Make all send information to byte

func (*Email) Send

func (e *Email) Send() error

type SafeMap

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

func NewSafeMap

func NewSafeMap(i ...map[interface{}]interface{}) *SafeMap

NewSafeMap return new safemap 可传入一个存在的map作为初始map

func (*SafeMap) Check

func (m *SafeMap) Check(k interface{}) bool

Returns true if k is exist in the map.

func (*SafeMap) Delete

func (m *SafeMap) Delete(k interface{})

Delete the given key and value.

func (*SafeMap) Get

func (m *SafeMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*SafeMap) Items

func (m *SafeMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*SafeMap) Set

func (m *SafeMap) Set(k interface{}, v interface{}) bool

Maps the given key and value. Returns false if the key is already in the map and changes nothing.

type StructColumn

type StructColumn struct {
	Tag        string
	Name       string
	TagOptions TagOptions
	ExtTag     string
	ExtOptions TagOptions
	Type       reflect.Type
	Index      []int
}

func ReadStructColumns

func ReadStructColumns(i interface{}, underscore bool, tags ...string) (cols []StructColumn)

{{{ func ReadStructColumns(i interface{}, tag string, underscore bool) (cols []string) * 从struct type中读取字段名 * 默认从struct的FieldName读取, 如果tag里有db, 则以db为准

type TagOptions

type TagOptions string

tagOptions is the string following a comma in a struct field's "json" tag, or the empty string. It does not include the leading comma.

func ParseTag

func ParseTag(tag string) (string, TagOptions)

parseTag splits a struct field's json tag into its name and comma-separated options. 第一个逗号之前的为tag, 之后为Options

func (TagOptions) Contains

func (o TagOptions) Contains(optionName string) bool

Contains reports whether a comma-separated list of options contains a particular substr flag. substr must be surrounded by a string boundary or commas.

type WriterProxy

type WriterProxy interface {
	http.ResponseWriter
	// Status returns the HTTP status of the request, or 0 if one has not
	// yet been sent.
	Status() int
	// BytesWritten returns the total number of bytes sent to the client.
	BytesWritten() int
	// Tee causes the response body to be written to the given io.Writer in
	// addition to proxying the writes through. Only one io.Writer can be
	// tee'd to at once: setting a second one will overwrite the first.
	// Writes will be sent to the proxy before being written to this
	// io.Writer. It is illegal for the tee'd writer to be modified
	// concurrently with writes.
	Tee(io.Writer)
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

WriterProxy is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

func WrapWriter

func WrapWriter(w http.ResponseWriter) WriterProxy

WrapWriter wraps an http.ResponseWriter into a proxy that allows you to hook into various parts of the response process.

Jump to

Keyboard shortcuts

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