tools

package module
v0.0.0-...-ed70592 Latest Latest
Warning

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

Go to latest
Published: May 2, 2018 License: Apache-2.0 Imports: 27 Imported by: 1

README

tools

Documentation

Index

Constants

View Source
const (
	VariantNCS = iota
	VariantRFC4122
	VariantMicrosoft
	VariantFuture
)

UUID layout variants.

View Source
const (
	DomainPerson = iota
	DomainGroup
	DomainOrg
)

UUID DCE domains.

Variables

View Source
var (
	NamespaceDNS, _  = FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	NamespaceURL, _  = FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
	NamespaceOID, _  = FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
	NamespaceX500, _ = FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
)

Predefined namespace UUIDs.

View Source
var FirstDayMonday bool
View Source
var Nil = UUID{}

The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.

View Source
var TimeFormats = []string{"1/2/2006", "1/2/2006 15:4:5", "2006-1-2 15:4:5", "2006-1-2 15:4", "2006-1-2", "1-2", "15:4:5", "15:4", "15", "15:4:5 Jan 2, 2006 MST", "2006-01-02 15:04:05.999999999 -0700 MST"}

Functions

func BeginningOfDay

func BeginningOfDay() time.Time

func BeginningOfHour

func BeginningOfHour() time.Time

func BeginningOfMinute

func BeginningOfMinute() time.Time

func BeginningOfMonth

func BeginningOfMonth() time.Time

func BeginningOfQuarter

func BeginningOfQuarter() time.Time

func BeginningOfWeek

func BeginningOfWeek() time.Time

func BeginningOfYear

func BeginningOfYear() time.Time

func Between

func Between(time1, time2 string) bool

func CheckMobilePhoneValid

func CheckMobilePhoneValid(phone string) bool

*

  • 校验手机号

func CheckPriceFormat

func CheckPriceFormat(fee string) error

func ConvertFTOY

func ConvertFTOY(fen string) (yuan string, err error)

func ConvertGBK2UTF

func ConvertGBK2UTF(gbk string) (utf string)

* gbk转换为 utf8 *

func ConvertUTF2GBK

func ConvertUTF2GBK(utf string) (gbk string)

* utf8转换为 gbk *

func ConvertYTOF

func ConvertYTOF(yuan string) (fen string, err error)

func EndOfDay

func EndOfDay() time.Time

func EndOfHour

func EndOfHour() time.Time

func EndOfMinute

func EndOfMinute() time.Time

func EndOfMonth

func EndOfMonth() time.Time

func EndOfQuarter

func EndOfQuarter() time.Time

func EndOfSunday

func EndOfSunday() time.Time

func EndOfWeek

func EndOfWeek() time.Time

func EndOfYear

func EndOfYear() time.Time

func Equal

func Equal(u1 UUID, u2 UUID) bool

Equal returns true if u1 and u2 equals, otherwise returns false.

func GeoCodes

func GeoCodes(address string) (string, error)

根据具体的地理位置信息和城市.得到经纬度 使用高德地图 API

func GetLocalIp

func GetLocalIp() string

func HMAC_SHA1

func HMAC_SHA1(data, KEY string) string

func IsEmail

func IsEmail(str ...string) bool

*

  • 校验邮箱

func IsStructPtr

func IsStructPtr(t reflect.Type) bool

* 判断是否为指针

func JsonToMap

func JsonToMap(a interface{}) map[string]interface{}

* 把json 的struct 转换为 map

func MD5

func MD5(data string) string

func Monday

func Monday() time.Time

func MustParse

func MustParse(strs ...string) time.Time

func Parse

func Parse(strs ...string) (time.Time, error)

func ParseFormToJsonBean

func ParseFormToJsonBean(form url.Values, obj interface{}) error

*

func RandomAlphaOrNumeric

func RandomAlphaOrNumeric(count uint, letters, numbers bool) string

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

Param count - the length of random string to create Param letters - if true, generated string will include

alphabetic characters

Param numbers - if true, generated string will include

numeric characters

func RandomAlphabetic

func RandomAlphabetic(count uint) string

Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alphabetic characters.

func RandomAlphanumeric

func RandomAlphanumeric(count uint) string

Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alpha-numeric characters.

func RandomAscii

func RandomAscii(count uint) string

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of characters whose ASCII value is between 32 and 126 (inclusive).

func RandomNumeric

func RandomNumeric(count uint) string

Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of numeric characters.

func RandomSpec0

func RandomSpec0(count uint, start, end int, letters, numbers bool,
	chars []rune, rand *rand.Rand) string

Creates a random string based on a variety of options, using supplied source of randomness.

If start and end are both 0, start and end are set to ' ' and 'z', the ASCII printable characters, will be used, unless letters and numbers are both false, in which case, start and end are set to 0 and math.MaxInt32.

If set is not nil, characters between start and end are chosen.

This method accepts a user-supplied rand.Rand instance to use as a source of randomness. By seeding a single rand.Rand instance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.

func RandomSpec1

func RandomSpec1(count uint, start, end int, letters, numbers bool) string

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.

Param count - the length of random string to create Param start - the position in set of chars to start at Param end - the position in set of chars to end before Param letters - if true, generated string will include

alphabetic characters

Param numbers - if true, generated string will include

numeric characters

func RandomString

func RandomString(count uint) string

func RandomStringSpec0

func RandomStringSpec0(count uint, set []rune) string

func RandomStringSpec1

func RandomStringSpec1(count uint, set string) string

func SHA1

func SHA1(data string) string

func Sunday

func Sunday() time.Time

Types

type Now

type Now struct {
	time.Time
}

func New

func New(t time.Time) *Now

func (*Now) BeginningOfDay

func (now *Now) BeginningOfDay() time.Time

func (*Now) BeginningOfHour

func (now *Now) BeginningOfHour() time.Time

func (*Now) BeginningOfMinute

func (now *Now) BeginningOfMinute() time.Time

func (*Now) BeginningOfMonth

func (now *Now) BeginningOfMonth() time.Time

func (*Now) BeginningOfQuarter

func (now *Now) BeginningOfQuarter() time.Time

func (*Now) BeginningOfWeek

func (now *Now) BeginningOfWeek() time.Time

func (*Now) BeginningOfYear

func (now *Now) BeginningOfYear() time.Time

func (*Now) Between

func (now *Now) Between(time1, time2 string) bool

func (*Now) EndOfDay

func (now *Now) EndOfDay() time.Time

func (*Now) EndOfHour

func (now *Now) EndOfHour() time.Time

func (*Now) EndOfMinute

func (now *Now) EndOfMinute() time.Time

func (*Now) EndOfMonth

func (now *Now) EndOfMonth() time.Time

func (*Now) EndOfQuarter

func (now *Now) EndOfQuarter() time.Time

func (*Now) EndOfSunday

func (now *Now) EndOfSunday() time.Time

func (*Now) EndOfWeek

func (now *Now) EndOfWeek() time.Time

func (*Now) EndOfYear

func (now *Now) EndOfYear() time.Time

func (*Now) Monday

func (now *Now) Monday() time.Time

func (*Now) MustParse

func (now *Now) MustParse(strs ...string) (t time.Time)

func (*Now) Parse

func (now *Now) Parse(strs ...string) (t time.Time, err error)

func (*Now) Sunday

func (now *Now) Sunday() time.Time

type NullUUID

type NullUUID struct {
	UUID  UUID
	Valid bool
}

NullUUID can be used with the standard sql package to represent a UUID value that can be NULL in the database

func (*NullUUID) Scan

func (u *NullUUID) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (NullUUID) Value

func (u NullUUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type UUID

type UUID [16]byte

UUID representation compliant with specification described in RFC 4122.

func And

func And(u1 UUID, u2 UUID) UUID

And returns result of binary AND of two UUIDs.

func FromBytes

func FromBytes(input []byte) (u UUID, err error)

FromBytes returns UUID converted from raw byte slice input. It will return error if the slice isn't 16 bytes long.

func FromBytesOrNil

func FromBytesOrNil(input []byte) UUID

FromBytesOrNil returns UUID converted from raw byte slice input. Same behavior as FromBytes, but returns a Nil UUID on error.

func FromString

func FromString(input string) (u UUID, err error)

FromString returns UUID parsed from string input. Input is expected in a form accepted by UnmarshalText.

func FromStringOrNil

func FromStringOrNil(input string) UUID

FromStringOrNil returns UUID parsed from string input. Same behavior as FromString, but returns a Nil UUID on error.

func Or

func Or(u1 UUID, u2 UUID) UUID

Or returns result of binary OR of two UUIDs.

func UUID_NewV1

func UUID_NewV1() UUID

NewV1 returns UUID based on current timestamp and MAC address.

func UUID_NewV2

func UUID_NewV2(domain byte) UUID

NewV2 returns DCE Security UUID based on POSIX UID/GID.

func UUID_NewV3

func UUID_NewV3(ns UUID, name string) UUID

NewV3 returns UUID based on MD5 hash of namespace UUID and name.

func UUID_NewV4

func UUID_NewV4() UUID

NewV4 returns random generated UUID.

func UUID_NewV5

func UUID_NewV5(ns UUID, name string) UUID

NewV5 returns UUID based on SHA-1 hash of namespace UUID and name.

func (UUID) Bytes

func (u UUID) Bytes() []byte

Bytes returns bytes slice representation of UUID.

func (UUID) MarshalBinary

func (u UUID) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (UUID) MarshalText

func (u UUID) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by String.

func (*UUID) Scan

func (u *UUID) Scan(src interface{}) error

Scan implements the sql.Scanner interface. A 16-byte slice is handled by UnmarshalBinary, while a longer byte slice or a string is handled by UnmarshalText.

func (*UUID) SetVariant

func (u *UUID) SetVariant()

SetVariant sets variant bits as described in RFC 4122.

func (*UUID) SetVersion

func (u *UUID) SetVersion(v byte)

SetVersion sets version bits.

func (UUID) String

func (u UUID) String() string

Returns canonical string representation of UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

func (*UUID) UnmarshalBinary

func (u *UUID) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. It will return error if the slice isn't 16 bytes long.

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(text []byte) (err error)

UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"

func (UUID) Value

func (u UUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

func (UUID) Variant

func (u UUID) Variant() uint

Variant returns UUID layout variant.

func (UUID) Version

func (u UUID) Version() uint

Version returns algorithm version used to generate UUID.

Directories

Path Synopsis
code.google.com
p/mahonia
This package is a character-set conversion library for Go.
This package is a character-set conversion library for Go.
Package httplib is used as http.Client Usage: import "github.com/astaxie/beego/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md
Package httplib is used as http.Client Usage: import "github.com/astaxie/beego/httplib" b := httplib.Post("http://beego.me/") b.Param("username","astaxie") b.Param("password","123456") b.PostFile("uploadfile1", "httplib.pdf") b.PostFile("uploadfile2", "httplib.txt") str, err := b.String() if err != nil { t.Fatal(err) } fmt.Println(str) more docs http://beego.me/docs/module/httplib.md

Jump to

Keyboard shortcuts

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