utils

package
v0.0.0-...-e31a138 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SUCCESS        = 200
	ERROR          = 500
	INVALID_PARAMS = 400

	ERROR_EXIST_TAG       = 10001
	ERROR_EXIST_TAG_FAIL  = 10002
	ERROR_NOT_EXIST_TAG   = 10003
	ERROR_GET_TAGS_FAIL   = 10004
	ERROR_COUNT_TAG_FAIL  = 10005
	ERROR_ADD_TAG_FAIL    = 10006
	ERROR_EDIT_TAG_FAIL   = 10007
	ERROR_DELETE_TAG_FAIL = 10008
	ERROR_EXPORT_TAG_FAIL = 10009
	ERROR_IMPORT_TAG_FAIL = 10010

	ERROR_NOT_EXIST_ARTICLE        = 10011
	ERROR_CHECK_EXIST_ARTICLE_FAIL = 10012
	ERROR_ADD_ARTICLE_FAIL         = 10013
	ERROR_DELETE_ARTICLE_FAIL      = 10014
	ERROR_EDIT_ARTICLE_FAIL        = 10015
	ERROR_COUNT_ARTICLE_FAIL       = 10016
	ERROR_GET_ARTICLES_FAIL        = 10017
	ERROR_GET_ARTICLE_FAIL         = 10018
	ERROR_GEN_ARTICLE_POSTER_FAIL  = 10019

	ERROR_AUTH_CHECK_TOKEN_FAIL    = 20001
	ERROR_AUTH_CHECK_TOKEN_TIMEOUT = 20002
	ERROR_AUTH_TOKEN               = 20003
	ERROR_AUTH                     = 20004

	ERROR_UPLOAD_SAVE_IMAGE_FAIL    = 30001
	ERROR_UPLOAD_CHECK_IMAGE_FAIL   = 30002
	ERROR_UPLOAD_CHECK_IMAGE_FORMAT = 30003
)
View Source
const (
	TimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var MsgFlags = map[int]string{
	SUCCESS:                         "ok",
	ERROR:                           "fail",
	INVALID_PARAMS:                  "请求参数错误",
	ERROR_EXIST_TAG:                 "已存在该标签名称",
	ERROR_EXIST_TAG_FAIL:            "获取已存在标签失败",
	ERROR_NOT_EXIST_TAG:             "该标签不存在",
	ERROR_GET_TAGS_FAIL:             "获取所有标签失败",
	ERROR_COUNT_TAG_FAIL:            "统计标签失败",
	ERROR_ADD_TAG_FAIL:              "新增标签失败",
	ERROR_EDIT_TAG_FAIL:             "修改标签失败",
	ERROR_DELETE_TAG_FAIL:           "删除标签失败",
	ERROR_EXPORT_TAG_FAIL:           "导出标签失败",
	ERROR_IMPORT_TAG_FAIL:           "导入标签失败",
	ERROR_NOT_EXIST_ARTICLE:         "该文章不存在",
	ERROR_ADD_ARTICLE_FAIL:          "新增文章失败",
	ERROR_DELETE_ARTICLE_FAIL:       "删除文章失败",
	ERROR_CHECK_EXIST_ARTICLE_FAIL:  "检查文章是否存在失败",
	ERROR_EDIT_ARTICLE_FAIL:         "修改文章失败",
	ERROR_COUNT_ARTICLE_FAIL:        "统计文章失败",
	ERROR_GET_ARTICLES_FAIL:         "获取多个文章失败",
	ERROR_GET_ARTICLE_FAIL:          "获取单个文章失败",
	ERROR_GEN_ARTICLE_POSTER_FAIL:   "生成文章海报失败",
	ERROR_AUTH_CHECK_TOKEN_FAIL:     "Token鉴权失败",
	ERROR_AUTH_CHECK_TOKEN_TIMEOUT:  "Token已超时",
	ERROR_AUTH_TOKEN:                "Token生成失败",
	ERROR_AUTH:                      "Token错误",
	ERROR_UPLOAD_SAVE_IMAGE_FAIL:    "保存图片失败",
	ERROR_UPLOAD_CHECK_IMAGE_FAIL:   "检查图片失败",
	ERROR_UPLOAD_CHECK_IMAGE_FORMAT: "校验图片错误,图片格式或大小有问题",
}

Functions

func Contains

func Contains(str string, substr string) bool

func CurrentDirectory

func CurrentDirectory() string

*

  • 获取执行可执行文件的目录

func CurrentPath

func CurrentPath() string

*

  • 当前文件目录

func Date

func Date(format string) string

*

  • 格式化日期

func Delete

func Delete()

func Equals

func Equals(str1 string, str2 string) bool

func Error

func Error(str string) error

*

  • 声明 errors 类型

func FloatToInt

func FloatToInt(v float64) int

*

  • float64 to int

func Get

func Get(url string, headers map[string]string) (string, error)

func GetMsg

func GetMsg(code int) string

GetMsg get error information based on Code

func IntToString

func IntToString(v int) string

*

  • int to string

func Ip

func Ip(str string) bool

func IpAddr

func IpAddr(str string) bool

func IpV4

func IpV4(str string) bool

func IpV4Addr

func IpV4Addr(str string) bool

func IpV6

func IpV6(str string) bool

func IpV6Addr

func IpV6Addr(str string) bool

func IsDir

func IsDir(str string) bool

func IsEmail

func IsEmail(email string) bool

func IsExist

func IsExist(f string) bool

*

  • 判断 文件/文件夹 是否存在

func IsFile

func IsFile(str string) bool

func IsMobile

func IsMobile(mobile string) bool

func IsNumeric

func IsNumeric(num int) bool

func IsURL

func IsURL(url string) bool

func IsUnique

func IsUnique(arr []rune) bool

func JsonToMap

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

*

  • json to map

func MapToJson

func MapToJson(obj map[string]interface{}) string

*

  • map to json

func Max

func Max(num int, max int) bool

func Md5

func Md5(str string) string

*

  • md5 加密

func Min

func Min(num int, max int) bool

func NotEqual

func NotEqual(str1 string, str2 string) bool

func OneOf

func OneOf(value interface{}, arr []rune) bool

func Patch

func Patch()

func Post

func Post(url string, headers map[string]string, requestData string) (string, error)

func Put

func Put()

func Required

func Required(str string) bool

func SendMail

func SendMail(to, subject, body, mailType string, conf *goconf.Config) error

*

  • 发送邮件

func StringToInt

func StringToInt(str string) int

*

  • string to int

func StructToJson

func StructToJson(obj interface{}) string

*

  • struct to json

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

*

  • struct to map

func TcpAddr

func TcpAddr(str string) bool

func TcpV4Addr

func TcpV4Addr(str string) bool

func TcpV6Addr

func TcpV6Addr(str string) bool

func TrimS

func TrimS(str string) string

*

  • 去除空格

func TypeOf

func TypeOf(v interface{}) string

*

  • 获取变量类型

func UdpAddr

func UdpAddr(str string) bool

func UdpV4Addr

func UdpV4Addr(str string) bool

func UdpV6Addr

func UdpV6Addr(str string) bool

Types

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

*

  • String 格式化输出

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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