utils

package
v0.0.0-...-ec88339 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(condition bool, msg string, code ...int)

Assert 条件断言 当断言条件为 假 时触发 panic 对于当前请求不会再执行接下来的代码,并且返回指定格式的错误信息和错误码

func AssertErr

func AssertErr(err error, msg string, code ...int)

AssertErr 错误断言 当 error 不为 nil 时触发 panic 对于当前请求不会再执行接下来的代码,并且返回指定格式的错误信息和错误码 若 msg 为空,则默认为 error 中的内容

func CheckDateDuring

func CheckDateDuring(start, end int64)

CheckDateDuring 判断是否为合法日期区间

func CheckReward

func CheckReward(reward, rewardObject string, rewardValue float32)

CheckReward 判断是否为合法酬劳

func GetFileHash

func GetFileHash(file multipart.File) (string, error)

GetFileHash 获取文件 Hash

func GetHash

func GetHash(data string) string

GetHash 获取字符串的 Hash

func GetRandomString

func GetRandomString(l int) string

GetRandomString 获取随机字符串

func IsEmail

func IsEmail(email string) bool

IsEmail 判断是否为合法邮箱

func IsGender

func IsGender(gender string) bool

IsGender 判断是否为合法性别

func IsTaskStatus

func IsTaskStatus(status string) bool

IsTaskStatus 判断是否为合法任务状态

func IsUserType

func IsUserType(userType string) bool

IsUserType 判断是否为合法用户类型

func JSON

func JSON(ctx context.Context, v interface{})

JSON 格式化结构体为 JSON 并写入 Response Body 自动将 Golang 中的驼峰命名法转换为 下划线命名法

func NewErrorHandler

func NewErrorHandler() context.Handler

NewErrorHandler 错误捕获处理 Handler

Types

type COSConfig

type COSConfig struct {
	AppID     string `yaml:"id"`
	AppSecret string `yaml:"secret"`
	URL       string `yaml:"url"`
}

COSConfig 腾讯云 对象存储配置

type Config

type Config struct {
	Dev    bool         `yaml:"dev"`    // 开发模式
	HTTP   HTTPConfig   `yaml:"http"`   // HTTP 配置
	Db     DBConfig     `yaml:"db"`     // 数据库配置
	Redis  RedisConfig  `yaml:"redis"`  // Redis 配置
	Violet VioletConfig `yaml:"violet"` // Violet 配置
	Wechat WechatConfig `yaml:"wechat"` // 微信小程序 配置
	COS    COSConfig    `yaml:"cos"`
	Email  EmailConfig  `yaml:"email"`
}

Config 应用配置

func GetConf

func GetConf() *Config

GetConf 获取全局配置

func (*Config) LoadConf

func (c *Config) LoadConf(path string) *Config

LoadConf 从文件读取配置信息

type DBConfig

type DBConfig struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	DBName   string `yaml:"db"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

DBConfig 数据库配置

type EmailConfig

type EmailConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	From     string `yaml:"from"`
}

EmailConfig 邮件服务配置

type ErrorRes

type ErrorRes struct {
	Message string
}

ErrorRes 错误回复

type HTTPConfig

type HTTPConfig struct {
	Host    string        `yaml:"host"`    // 监听地址
	Port    string        `yaml:"port"`    // 监听端口
	Session SessionConfig `yaml:"session"` // Session 配置
}

HTTPConfig 服务器配置

type RedisConfig

type RedisConfig struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
	Session  string `yaml:"session"`
}

RedisConfig 缓存配置

type SessionConfig

type SessionConfig struct {
	Key     string `yaml:"key"`     // Cookies 名字
	Expires int    `yaml:"expires"` // 过期天数
}

SessionConfig Session 配置

type VioletConfig

type VioletConfig struct {
	ClientID   string `yaml:"id"`
	ClientKey  string `yaml:"key"`
	ServerHost string `yaml:"host"`
	Callback   string `yaml:"callback"`
}

VioletConfig Violet 配置

type WechatConfig

type WechatConfig struct {
	AppID     string `yaml:"id"`
	AppSecret string `yaml:"secret"`
}

WechatConfig 微信小程序配置

Jump to

Keyboard shortcuts

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