utils

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Overview

*

  • 日期处理类
  • @author
  • @since 2021/11/12
  • @File : date

*

  • 数据库连接工具
  • @author
  • @since 2021/9/8
  • @File : db

*

  • 支付工具类
  • @author
  • @since 2021/8/12
  • @File : pay

*

  • Jwt工具类
  • @author
  • @since 2021/8/12
  • @File : jwt

*

  • 支付工具类
  • @author
  • @since 2021/8/12
  • @File : pay

*

  • 数据库连接工具
  • @author
  • @since 2021/9/8
  • @File : db

*

  • 常规常量
  • @author
  • @since 2021/11/12
  • @File : user

*

  • 系统工具类
  • @author
  • @since 2021/8/25
  • @File : utils

Index

Constants

View Source
const (
	LQAppKey             = "2838498"
	LQAppSecret          = "f988a360af90413d8f0dd2b43d70501f"
	MethodOrderDirectAdd = "order.direct.add"
	TimeFormat           = "2006-01-02 15:04:05"
	Version              = "2.0"
	Format               = "json"
	Charset              = "utf-8"
	SignType             = "md5"
	HostTest             = "https://api.lqivip.net/api/getway"
	Host                 = "https://api.lqivip.com/api/getway"
)
View Source
const LocalDateTimeFormat string = "2006-01-02 15:04:05"

Variables

View Source
var GENDER_LIST = map[int]string{
	1: "男",
	2: "女",
	3: "保密",
}

性别

View Source
var HttpClient *http.Client
View Source
var Mongodb *mongo.Database
View Source
var SelfNetTransport *http.Transport
View Source
var XormDb *xorm.Engine

Functions

func AppDebug

func AppDebug() bool

调试模式

func CheckDirExist

func CheckDirExist(dir string) (bool, error)

func CheckDirWithCreate

func CheckDirWithCreate(dir string) error

CheckDirWithCreate 检查目录是否存在,不存在创建

func CheckSign

func CheckSign(ctx *gin.Context) bool

检测用户签名

func CreateDir

func CreateDir(path string) bool

创建文件夹并设置权限

func FilePath

func FilePath() string

文件目录(非图片目录)

func FloatToInt

func FloatToInt(f float64) int

func GenerateToken

func GenerateToken(userId int, username, password string) (string, error)

根据用户的用户名和密码产生token

func GetAppSecret

func GetAppSecret(ctx *gin.Context, appId string) string

根据 appid 获取 appSecret

func GetClientIp

func GetClientIp(ctx *gin.Context) string

获取客户端IP

func GetDatabase

func GetDatabase() (string, error)

获取数据库表

func GetDir

func GetDir(fp string) string

func GetImageUrl

func GetImageUrl(path string) string

获取文件地址

func GetLogDir

func GetLogDir(s string) string

func GetNewSign

func GetNewSign(dataMap map[string]string, keyArray *garray.StrArray, secret string) string

获取签名

func GetProductId

func GetProductId(goodsId int64, amount float64) string

获取产品id goodsId 类型:1移动 2电信 3联通

func GetReq

func GetReq(url string) (string, bool)

func GetUrl

func GetUrl(url string, data map[string]string) string

func ImagePath

func ImagePath() string

图片存放目录

func ImageUrl

func ImageUrl() string

func InArray

func InArray(value string, array []interface{}) bool

判断元素是否在数组中

func InStringArray

func InStringArray(value string, array []string) bool

func IsExist

func IsExist(path string) bool

判断文件/文件夹是否存在(返回true是存在)

func IsLogin

func IsLogin(ctx *gin.Context) bool

判断用户登录状态

func Md5

func Md5(password string) (string, error)

func MkdirAll

func MkdirAll(dir string) error

func NewLogRusLogger

func NewLogRusLogger(logfile, logLevel string) (*logrus.Logger, error)

NewLogRusLogger New LogRus l

func NewRedisHelper

func NewRedisHelper() *redis.Client

func OrderDirectAdd

func OrderDirectAdd(mobile, outTradeNo, host string, goodsId int64, amount float64) (string, bool)

统一下单接口

goodsId 类型:2移动 3电信 4联通

func PostReq

func PostReq(reqMap map[string]interface{}, url string) (string, bool)

1、测试post请求 form

func PostReqJson

func PostReqJson(reqMap map[string]interface{}, url string) (string, bool)

func PostReqJsonHeader

func PostReqJsonHeader(reqMap map[string]string, url string, header map[string]string) (string, bool)

func PostReqJsonV2

func PostReqJsonV2(reqMap map[string]string, url string) (string, bool)

func PostReqV2

func PostReqV2(reqMap map[string]string, url string) (string, bool)

func Reverse

func Reverse(arr *[]string)

数组反转

func SaveImage

func SaveImage(url string, dirname string) (string, error)

func SaveImageContent

func SaveImageContent(content string, title string, dirname string) string

处理富文本

func SubStr

func SubStr(str string, start int, length int) (result string)

截取字符串,支持多字节字符 start:起始下标,负数从从尾部开始,最后一个为-1 length:截取长度,负数表示截取到末尾

func TempPath

func TempPath() string

临时目录

func Uid

func Uid(ctx *gin.Context) int

登录用户ID

func UploadPath

func UploadPath() string

附件目录

Types

type Claims

type Claims struct {
	UserId   int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
	jwt.StandardClaims
}

Claim是一些实体(通常指的用户)的状态和额外的元数据

func GetLoginUserInfo

func GetLoginUserInfo(ctx *gin.Context) (*Claims, error)

根据传入的token值获取到Claims对象信息,(进而获取其中的用户名和密码)

func ParseToken

func ParseToken(token string) (*Claims, error)

根据传入的token值获取到Claims对象信息,(进而获取其中的用户名和密码)

type LocalTime

type LocalTime time.Time

func (LocalTime) MarshalJSON

func (l LocalTime) MarshalJSON() ([]byte, error)

func (*LocalTime) UnmarshalJSON

func (l *LocalTime) UnmarshalJSON(b []byte) error

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func (*Lock) Lock

func (l *Lock) Lock()

func (*Lock) LockWithTimeout

func (l *Lock) LockWithTimeout(timeout time.Duration) error

func (*Lock) RLock

func (l *Lock) RLock()

func (*Lock) RLockWithTimeout

func (l *Lock) RLockWithTimeout(timeout time.Duration) error

func (*Lock) RUnlock

func (l *Lock) RUnlock()

func (*Lock) Unlock

func (l *Lock) Unlock()

type PbSettingAppUtils

type PbSettingAppUtils struct {
	Id               int    `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
	AppId            string `json:"app_id"`
	AppName          string `json:"app_name"`
	Phone            string `json:"phone"`
	AppKey           string `json:"app_key"`
	Status           int64  `json:"status"`
	CouponSmsContent string `json:"coupon_sms_content"`
	ServiceAddress   string `json:"service_address"`
	ComName          string `json:"com_name"`
	FilingNo         string `json:"filing_no"`
}

func GetAppInfo

func GetAppInfo(ctx *gin.Context, appId string) PbSettingAppUtils

根据 appid 获取 appSecret

func (*PbSettingAppUtils) TableName

func (r *PbSettingAppUtils) TableName() string

type RedisHelper

type RedisHelper struct {
	*redis.Client
}

func GetRedisHelper

func GetRedisHelper() *RedisHelper

type Rsp

type Rsp struct {
	// Code int    `json:"code"` // 比如这里仅需要rsp字段(视具体情况而定),那Rsp结构体不解析code字段即可~
	Rsp string `json:"rsp"`
}

Directories

Path Synopsis
*
*
*
*
*
Package gmd5 provides useful API for MD5 encryption algorithms.
Package gmd5 provides useful API for MD5 encryption algorithms.
*
*

Jump to

Keyboard shortcuts

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