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
- Variables
- func FieldByIndex(v reflect.Value, index []int) reflect.Value
- func FieldExists(i interface{}, f string) bool
- func FileExists(name string) bool
- func GetFuncName(i interface{}) string
- func GetRealString(v reflect.Value) string
- func GrepFile(patten string, filename string) (lines []string, err error)
- func HashSha1(i ...string) string
- func ImportValue(i interface{}, is map[string]string) (err error)
- func InSlice(v string, sl []string) bool
- func InSliceIface(v interface{}, sl []interface{}) bool
- func InSliceInt(v int, sl []int) bool
- func IntRange(min, max int) (int, error)
- func IsEmptyValue(v reflect.Value) bool
- func LengthenUUID(s string) (ls string)
- func NewShortUUID() string
- func NewShortUUID5(namespace, data string) string
- func NewUUID() string
- func NewUUID5(namespace, data string) string
- func ParseFloat(f float64) float64
- func ParseOTP(header http.Header, key string) (value, typ, sn string, err error)
- func ParseValueAndParams(header http.Header, key string) (value string, params map[string]string)
- func PurgeSlice(v string, sl []string) []string
- func RandomCreateBytes(n int, alphabets string) []byte
- func ReadIntFromBytes(bs []byte) (r int)
- func ReadLines(path string) ([]string, error)
- func Round(f float64, n int) float64
- func SearchFile(filename string, paths ...string) (fullpath string, err error)
- func SelfDir() string
- func SelfPath() string
- func ShortenUUID(s string) (ss string)
- func Shuffle(a []interface{})
- func ShuffleInt(a []int)
- func ShuffleString(a []string)
- func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})
- func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})
- func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})
- func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})
- func SliceMerge(slice1, slice2 []interface{}) (c []interface{})
- func SlicePad(slice []interface{}, size int, val interface{}) []interface{}
- func SliceRand(a []interface{}) (b interface{})
- func SliceRandList(min, max int) []int
- func SliceRange(start, end, step int64) (intslice []int64)
- func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})
- func SliceShuffle(slice []interface{}) []interface{}
- func SliceSum(intslice []int64) (sum int64)
- func SliceUnique(slice []interface{}) (uniqueslice []interface{})
- func Underscore(camelCaseWord string) string
- func WriteLines(lines []string, path string) error
- type Attachment
- type Auth
- type BitmapIndex
- func (bi *BitmapIndex) And(obi *BitmapIndex) (nbi *BitmapIndex)
- func (bi *BitmapIndex) AndBreak(obis []*BitmapIndex) (nbi *BitmapIndex)
- func (bi *BitmapIndex) Bytes() (ib []byte, err error)
- func (bi *BitmapIndex) Not(obi *BitmapIndex) (nbi *BitmapIndex)
- func (bi *BitmapIndex) Or(obi *BitmapIndex) (nbi *BitmapIndex)
- func (bi *BitmapIndex) Slices() (s []int, err error)
- type Choice
- type Email
- type SafeMap
- type StructColumn
- type TagOptions
- type WriterProxy
Constants ¶
const AuthTag = "dm"
Variables ¶
var MinMaxError = errors.New("Min cannot be greater than max.")
Functions ¶
func FieldByIndex ¶
{{{ func FieldByIndex(v reflect.Value, index []int) reflect.Value * 通过索引返回field
func FieldExists ¶
{{{ func FieldExists(i interface{},f string) bool * 判断一个结构变量是否有某个字段
func FileExists ¶
FileExists reports whether the named file or directory exists.
func GetRealString ¶
{{{ func GetRealString(v reflect.Value) string *
func GrepFile ¶
like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read
func ImportValue ¶
{{{ func ImportVal(i interface{}, import map[string]string) (err error) * 将tag匹配的值导入结构
func InSliceIface ¶
func InSliceIface(v interface{}, sl []interface{}) bool
InSliceIface checks given interface in interface slice.
func InSliceInt ¶
InSliceInt checks given int in int slice or not.
func IsEmptyValue ¶
{{{ func IsEmptyValue(v reflect.Value) bool *
func LengthenUUID ¶
func NewShortUUID ¶
func NewShortUUID() string
func NewShortUUID5 ¶
func ParseFloat ¶
func ParseValueAndParams ¶
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 RandomCreateBytes ¶
RandomCreateBytes generate random []byte by specify chars. func RandomCreateBytes(n int, alphabets ...byte) []byte {
func ReadIntFromBytes ¶
{{{ func ReadIntFromBytes(bs []byte) (r int) *
func SearchFile ¶
Search a file in paths. this is often used in search config file in /etc ~/
func ShortenUUID ¶
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 ¶
SliceRandList generate an int slice from min to max.
func SliceRange ¶
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 SliceUnique ¶
func SliceUnique(slice []interface{}) (uniqueslice []interface{})
SliceUnique cleans repeated values in slice.
func WriteLines ¶
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 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 ¶
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 ¶
NewEMail create new Email struct with config json. config json is followed from Email struct fields.
func (*Email) Attach ¶
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
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) Get ¶
func (m *SafeMap) Get(k interface{}) interface{}
Get from maps return the k's value
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.