utils

package
v0.0.0-...-a39f7dd Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2016 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	GENDER_UNKNOWN = 0
	GENDER_MALE    = 1 << iota
	GENDER_FEMALE
)
View Source
const (
	SNS_PLATFORM_WEIXIN = iota
	SNS_PLATFORM_WEIBO
	SNS_PLATFORM_QQ
)
View Source
const (
	// system level
	ERROR_CODE_SYSTEM_ERROR = 10001
	ERROR_CODE_PARAM_ERROR  = 10002

	// users
	ERROR_CODE_USERS_USER_NOT_EXISTS      = 20101
	ERROR_CODE_USERS_PHONE_REGISTERED     = 20102
	ERROR_CODE_USERS_INVALID_NICKNAME     = 20103
	ERROR_CODE_USERS_INVALID_GENDER_VALUE = 20104
	ERROR_CODE_USERS_INVALID_AVATAR       = 20105

	// verify code
	ERROR_CODE_VERIFY_CODE_MISMATCH = 20201

	// tokens
	ERROR_CODE_TOKENS_PASSWORD_MISMATCH = 20301
	ERROR_CODE_TOKENS_INVALID_TOKEN     = 20302

	// auth
	ERROR_CODE_AUTH_WEIXIN_AUTH_FAIL = 20401
	ERROR_CODE_AUTH_WEIBO_AUTH_FAIL  = 20402
	ERROR_CODE_AUTH_QQ_AUTH_FAIL     = 20403

	// basic auth
	ERROR_CODE_BASIC_AUTH_FAIL = 20801
)

error code definition, three part, [level][function][number] [level], 1: system level, 2: service level [function] 01: tokens; 02: verify code; ... [number] detailed error number

View Source
const USER_AVATAR_MEX_LEN int = 255
View Source
const USER_MIN_UID int64 = 1000000000
View Source
const USER_NICKNAME_MEX_LEN int = 20
View Source
const VERIFY_CODE_EXPIRE_IN_SECONDS int64 = 10 * 60
View Source
const VERIFY_CODE_LEN int = 6

Variables

View Source
var (
	ERROR_MESSAGES = map[int]string{

		ERROR_CODE_SYSTEM_ERROR: "Oops, System error",
		ERROR_CODE_PARAM_ERROR:  "Param error, see doc for more info",

		ERROR_CODE_USERS_USER_NOT_EXISTS:      "Queried user not exists",
		ERROR_CODE_USERS_PHONE_REGISTERED:     "Phone has registered",
		ERROR_CODE_USERS_INVALID_NICKNAME:     "Nickname invalid",
		ERROR_CODE_USERS_INVALID_GENDER_VALUE: "Invalid gender value, should only be 1 or 2",
		ERROR_CODE_USERS_INVALID_AVATAR:       "Avatar url invalid",

		ERROR_CODE_VERIFY_CODE_MISMATCH: "Verify code mismatch",

		ERROR_CODE_TOKENS_PASSWORD_MISMATCH: "Password mismatch",
		ERROR_CODE_TOKENS_INVALID_TOKEN:     "Invalid token",

		ERROR_CODE_AUTH_WEIXIN_AUTH_FAIL: "Weixin auth fail",
		ERROR_CODE_AUTH_WEIBO_AUTH_FAIL:  "Weibo auth fail",
		ERROR_CODE_AUTH_QQ_AUTH_FAIL:     "QQ auth fail",

		ERROR_CODE_BASIC_AUTH_FAIL: "Basic auth fail",
	}
)

Functions

func AreStringEquals

func AreStringEquals(str1, str2 *string) bool

func AssertNotEmptyString

func AssertNotEmptyString(str *string)

func Base64

func Base64(input string) string

func GenToken

func GenToken() string

40 characters random token

func GenUid

func GenUid() int64

func GenVerifyCode

func GenVerifyCode() string

func GetCharCount

func GetCharCount(input string) (count int)

func GetTimeMillis

func GetTimeMillis() int64

func IsEmptyString

func IsEmptyString(str *string) bool

func IsLegalFreeStringWithLength

func IsLegalFreeStringWithLength(input string, length int) bool

func IsLegalRestrictedStringWithLength

func IsLegalRestrictedStringWithLength(input string, length int) bool

func IsValidPhone

func IsValidPhone(phone string) bool

func Secret2Password

func Secret2Password(username, secret string) string

func Sha1

func Sha1(input string) string

func UrlEncode

func UrlEncode(input string) string

Types

type ApiError

type ApiError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Request string `json:"request"`
}

func Issue

func Issue(code int, request string) ApiError

type AuthUserInfo

type AuthUserInfo struct {
	Openid   string
	Nickname string
	Gender   int
	Avatar   string
}

func AuthWithQQ

func AuthWithQQ(qq_openid, qq_token, qq_oauth_consumer_key string) (*AuthUserInfo, int)

func AuthWithWeiBo

func AuthWithWeiBo(wb_token string) (*AuthUserInfo, int)

func AuthWithWeiXin

func AuthWithWeiXin(wx_openid, wx_token string) (*AuthUserInfo, int)

Jump to

Keyboard shortcuts

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