utils

package
v0.0.0-...-e0474ae Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const LOG_CONFIG = "logconfig.ini" //用于存放当前正在写入的日志文件名

Variables

View Source
var (
	ServerErr                  = NewMeanError("ServerErr", -1, 500, ErrorTypeInternal)
	RequestParamsErr           = NewMeanError("Request parameter invalid", 999, 400, ErrorTypePublic)
	StringConversionErr        = NewMeanError("string conversion invalid", 999, 400, ErrorTypePublic)
	AuthErr                    = NewMeanError("Un Auth Access", 1, 401, ErrorTypePublic)
	InsufficientPermissionsErr = NewMeanError("Insufficient permissions", 2, 403, ErrorTypePublic)
	DeviceErr                  = NewMeanError("Device Token Error", 3, 401, ErrorTypePublic)
)
View Source
var (
	UserNotFoundErr       = NewMeanError("user not found", 1000, 403, ErrorTypePublic)
	InvalidEmailAdressErr = NewMeanError("Invalid Email", 1001, 403, ErrorTypePublic)
	InvalidPhoneNumberErr = NewMeanError("Invalid Phone Number", 1002, 403, ErrorTypePublic)
	InvalidUserNameErr    = NewMeanError("Invalid User name", 1003, 403, ErrorTypePublic)
	InvalidPasswordErr    = NewMeanError("Wrong Password", 1004, 403, ErrorTypePublic)
	NameFormatErr         = NewMeanError("name format error", 1005, 403, ErrorTypePublic)
	InvalidSecretCodeErr  = NewMeanError("secret code error", 1006, 401, ErrorTypePublic)
	InvalidOpenIDErr      = NewMeanError("Invalid OpenID", 1001, 403, ErrorTypePublic)
)

Account

View Source
var (
	InvalidRelationActionErr     = NewMeanError("invalid relation action", 2001, 403, ErrorTypePublic)
	DuplicateFriendApplyErr      = NewMeanError("already in friendship", 2002, 403, ErrorTypePublic)
	FriendApplicationNotFoundErr = NewMeanError("not applying friend yet", 2003, 403, ErrorTypePublic)
	NoRelationFoundErr           = NewMeanError("no relation", 2004, 403, ErrorTypePublic)
)

Relations

View Source
var (
	//InvalidPhotoTypeErr    = NewMeanError("image type already is", 3000, 403, ErrorTypePublic)
	//PhotoExistErr          = NewMeanError("image exist", 3001, 403, ErrorTypePublic)
	InvalidPhotoEditParams = NewMeanError("invalid photo params", 3001, 403, ErrorTypePublic)
	PhotoNotFound          = NewMeanError("image not found ", 3002, 403, ErrorTypePublic)
)

Photo

View Source
var (
	PhotoCommentAlreadyCommentedErr = NewMeanError("Photo comment already commented", 4000, 403, ErrorTypePublic)
	PhotoCommentNotFoundErr         = NewMeanError("can't found image comment", 4001, 403, ErrorTypePublic)
	NewsCommentNotFoundErr          = NewMeanError("can't found News comment", 4002, 403, ErrorTypePublic)
	DeletePhotoCommentLimitReachErr = NewMeanError("delete comment time out", 4003, 403, ErrorTypePublic)
)

Comment

View Source
var (
	PhotoNoteMustHaveTitleErr = NewMeanError("image note must have title", 5000, 403, ErrorTypePublic)
	NoteExistErr              = NewMeanError("Note aleady exist on image and it's complete", 5001, 400, ErrorTypePublic)
	TooManyPhotoLinkNoteErr   = NewMeanError("note has linked 9 image ", 5002, 403, ErrorTypePublic)
	NoteUpdateTimeOutErr      = NewMeanError("update note time out ", 5003, 403, ErrorTypePublic)
	NoteNotFoundErr           = NewMeanError("note not found", 5005, 400, ErrorTypePublic)
	NoteCharacterErr          = NewMeanError("note character out of limit", 5006, 403, ErrorTypePublic)
)

Note

View Source
var (
	TooManyPhotoErr      = NewMeanError("News can't sending with more than 9 image", 6001, 403, ErrorTypePublic)
	PhotoPermissionErr   = NewMeanError("News image type can't be private", 6002, 403, ErrorTypePublic)
	NewsStarrNotFoundErr = NewMeanError("cant found starred record on News", 6003, 400, ErrorTypePublic)
	NewsStarForbidden    = NewMeanError("News can't starred", 6004, 403, ErrorTypePublic)
	NewsNotFoundErr      = NewMeanError("News not found", 6005, 400, ErrorTypePublic)
	NewsPhotoIsNil       = NewMeanError("News images is not found", 6006, 400, ErrorTypeInternal)
)

News

View Source
var (
	FilterNotFoundErr       = NewMeanError("Filter not found", 8000, 403, ErrorTypePublic)
	PreferFilterOutLimitErr = NewMeanError("prefer filter out of limit", 8001, 403, ErrorTypePublic)
)

Filter

View Source
var (
	DiaryNotFoundErr = NewMeanError("Diary not found", 7000, 403, ErrorTypePublic)
)

Diary

View Source
var (
	JsonConversionErrorErr = NewMeanError("json conversino fail", 2, 500, ErrorTypePublic)
)

Functions

func ByteAarray2Obj

func ByteAarray2Obj(b []byte, obj interface{})

func GetFinalPwdBySalt

func GetFinalPwdBySalt(password string, salts string) (pwd string)

GetFinalPwdBySalt 根据密码和盐获取最终密码

func GetFinalPwdWithSalt

func GetFinalPwdWithSalt(password string) (pwd string, salts string)

GetFinalPwdWithSalt 根据输入密码获取 最终密码和盐

func IsEmail

func IsEmail(s string) bool

func IsMobile

func IsMobile(s string) bool

func IsPassword

func IsPassword(s string) bool

func ItoStr

func ItoStr(i int) string

func Obj2ByteAarray

func Obj2ByteAarray(obj interface{}) []byte

func ObjectIds2Strs

func ObjectIds2Strs(ids []*bson.ObjectId) []string

func RandBirth

func RandBirth(ageStart, ageEnd int) time.Time

产生(ageStart, ageEnd)的生日

func RandInt

func RandInt(intStart, intEnd int) int

产生[start, end)的随机整数

func RandomNumberString

func RandomNumberString(n int) string

func RandomString

func RandomString(n int) string

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(s []string) (ret []string)

RemoveDuplicatesAndEmpty 去除重复和空字符串

func StoB

func StoB(s string) (bool, error)

func StoI

func StoI(s string) (int, error)

func StoI64

func StoI64(s string) (int64, error)

func Str2ObjectId

func Str2ObjectId(id string) bson.ObjectId

func Str2Time

func Str2Time(ts string) time.Time

func Str2UUID

func Str2UUID(a string) uuid.UUID

func Strs2ObjectIds

func Strs2ObjectIds(ids []string) []*bson.ObjectId

func Strs2UUIDs

func Strs2UUIDs(as []string) []uuid.UUID

func Time2Str

func Time2Str(t time.Time) string

func ToEchoLogFile

func ToEchoLogFile(path string, log []byte, fileSizeLimit int64)

ToEchoLogFile 将日志打印到文件

func UUIDs2Strs

func UUIDs2Strs(us []uuid.UUID) []string

Types

type ErrorType

type ErrorType int
const (
	ErrorTypeInternal ErrorType = 1 + iota
	ErrorTypePublic
)

type LogEntry

type LogEntry struct {
	*log.Entry
}

type MeanError

type MeanError struct {
	HttpCode  int       `json:"-"`
	ErrorType ErrorType `json:"-"`

	ErrorCode int    `json:"code"`
	Message   string `json:"message"`
}

func NewErrDBFail

func NewErrDBFail(err error) *MeanError

func NewMeanError

func NewMeanError(message string, errorCode, httpCode int, errorType ErrorType) *MeanError

func (MeanError) Error

func (p MeanError) Error() string

type MeanLogger

type MeanLogger struct {
	RequestID uuid.UUID
}

func NewLogger

func NewLogger() *MeanLogger

func NewMeanLogger

func NewMeanLogger() *MeanLogger

func (*MeanLogger) Print

func (l *MeanLogger) Print(values ...interface{})

func (*MeanLogger) Println

func (l *MeanLogger) Println(v ...interface{})

func (*MeanLogger) WithFields

func (l *MeanLogger) WithFields(fields log.Fields) *LogEntry

Jump to

Keyboard shortcuts

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