utils

package
v0.0.0-...-fab8377 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package utils

string.go includes utils functions related string

Index

Constants

View Source
const (
	CodeOk = iota
	CodeParamRequired
	CodeParamInvalid
	CodeWrongDataType
	CodeUndefinedField

	CodeNoRegMobile
	CodeDupMobile
	CodeWrongPwd

	CodeSystemErr        = 500 + iota
	CodeResponseTimeout  = 503
	CodeNotFound         = 404
	CodeMethodNotAllowed = 405
)

Variables

View Source
var Messages = map[int]string{
	CodeOk:             "成功",
	CodeParamRequired:  "缺少参数",
	CodeParamInvalid:   "非法参数",
	CodeWrongDataType:  "错误的数据类型",
	CodeUndefinedField: "未定义的字段",

	CodeNoRegMobile: "手机号码尚未注册",
	CodeDupMobile:   "手机号码已经注册",
	CodeWrongPwd:    "密码错误",

	CodeSystemErr:        "系统错误",
	CodeResponseTimeout:  "响应超时",
	CodeNotFound:         "Api未找到",
	CodeMethodNotAllowed: "该方法不允许",
}
View Source
var TimeoutJsonResp string

Functions

func CopyRequest

func CopyRequest(req *http.Request) *http.Request

copy a new http.Request

func Fstring

func Fstring(format string, v ...interface{}) string

Fstring format string implement fmt.Sprintf

func GenPasswordHash

func GenPasswordHash(pwd, salt string) string

GenPasswordHash

func ParseRequest

func ParseRequest(req *http.Request)

parse Request from request

func RandStr

func RandStr(length int) string

RandStr make rand str with in length length

func Response

func Response(i interface{}, ci *CodeInfo)

to fill i with CodeInfo. i must hae Field CodeInfo

func StringEncMd5

func StringEncMd5(s string) string

str2hex md5

func UniqueId

func UniqueId() string

生成Guid字串

Types

type CodeInfo

type CodeInfo struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func NewCodeInfo

func NewCodeInfo(code int, message string) *CodeInfo

Jump to

Keyboard shortcuts

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