utils

package
v0.0.0-...-320587e Latest Latest
Warning

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

Go to latest
Published: May 27, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

公共组件提供的服务列表 1. 把interface{}转化为map[string]string 2. 把string转化为int型 3. 模糊查找服务列表 4. 获取随机大小的字符串 5. 获取子串 6. 两个整数列表,求并集 7. 根据url,获取正则表达式字符串 例如: input: /v1/accounts/:id/invalid output: <2, :id> 8. 两个整数列表,求差积

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEmailPattern

func CheckEmailPattern(str string) bool

func CheckMobilePattern

func CheckMobilePattern(str string) bool

func ConvertInterfaceToMap

func ConvertInterfaceToMap(src interface{}) (dest map[string]interface{}, isMap bool)

interface{} 转化为 map

func ConvertStrToInt

func ConvertStrToInt(str string) (result int)

func FindServer

func FindServer(server string, servers []string) (name string, exist bool)

readme 通用处理方法列表 * 1. 获取Http请求头header部分的user_id和company_id * 2 读取服务

func GetCompanyIdFromHeader

func GetCompanyIdFromHeader(input *http.Request) (companyId int, retCode int, err error)

func GetCompanyNameFromHeader

func GetCompanyNameFromHeader(input *http.Request) (companyName string, retCode int, err error)

func GetDiffsInt

func GetDiffsInt(src []int, minuend []int) (dest []int)

8. 两个整数列表,求差积 param src=减数 param minuend=被减数

func GetEarliestDate

func GetEarliestDate(now *time.Time) (ret time.Time, err error)

早上凌晨时间

func GetRandomString

func GetRandomString(size int) string

生成随机字符串

func GetRegexpPairByUrl

func GetRegexpPairByUrl(url string) (position int, regTarget string)

7. 根据url,获取正则表达式字符串 例如: input: /v1/accounts/:id/invalid output: <2, :id>

func GetUnionByInts

func GetUnionByInts(slice1 []int, slice2 []int) (dest []int)

6. 两个整数列表,求并集

func GetUserCodeFromHeader

func GetUserCodeFromHeader(input *http.Request) (userCode string, retCode int, err error)

func GetUserIdFromHeader

func GetUserIdFromHeader(input *http.Request) (userId int, retCode int, err error)

func GetUserIdFromSessionStore

func GetUserIdFromSessionStore(userIdKey string, sess *session.Store) (userId int, retCode int, err error)

func GetUserMobileFromHeader

func GetUserMobileFromHeader(input *http.Request) (userMobile string, retCode int, err error)

func GetUserNameFromHeader

func GetUserNameFromHeader(input *http.Request) (userName string, retCode int, err error)

func Md5String

func Md5String(str string) (md5Str string)

func SubString

func SubString(str string, begin, length int) (substr string)

Types

type HeaderParamInfo

type HeaderParamInfo struct {
	UserId    int
	CompanyId int
}

func GetHeaderParams

func GetHeaderParams(input *http.Request) (headerParamInfo *HeaderParamInfo, retcode int, err error)

type HeaderUser

type HeaderUser struct {
	UserId      int
	UserName    string
	UserCode    string
	UserMobile  string
	CompanyId   int
	CompanyName string
	Positions   []*HeaderUserPosition // string format: id1,code1,name1;id2,code2,name2;id3,code3,name3
}

func GetUserFromHeader

func GetUserFromHeader(input *http.Request) (headerUser HeaderUser, retCode int, err error)

type HeaderUserConf

type HeaderUserConf struct {
	KeyUserId      string
	KeyUserName    string
	KeyUserMobile  string
	KeyCompanyId   string
	KeyCompanyName string
	KeyPositions   string
}

type HeaderUserPosition

type HeaderUserPosition struct {
	PositionId   int
	PositionCode string
	PositionName string
}

func GetPositionsFromHeader

func GetPositionsFromHeader(input *http.Request) (positions []*HeaderUserPosition, retCode int, err error)

type RedisV5Client

type RedisV5Client struct {
	Options *redis.Options
	Client  *redis.Client
}

func (*RedisV5Client) Conn

func (s *RedisV5Client) Conn() (err error)

func (*RedisV5Client) Del

func (s *RedisV5Client) Del(key string) (err error)

func (*RedisV5Client) DelKeys

func (s *RedisV5Client) DelKeys(keys []string) (err error)

func (*RedisV5Client) Get

func (s *RedisV5Client) Get(key string) (value string, err error)

func (*RedisV5Client) Keys

func (s *RedisV5Client) Keys(pattern string) (keys []string, err error)

func (*RedisV5Client) SAdd

func (s *RedisV5Client) SAdd(key string, members ...interface{}) (err error)

func (*RedisV5Client) SIsMember

func (s *RedisV5Client) SIsMember(key string, member interface{}) (boolCmd *redis.BoolCmd)

func (*RedisV5Client) SRem

func (s *RedisV5Client) SRem(key string, members ...interface{}) (err error)

func (*RedisV5Client) Set

func (s *RedisV5Client) Set(key string, value interface{}, expiration time.Duration) (err error)

Jump to

Keyboard shortcuts

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