tool

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKey = "ContextKey" // 上下文变量存储键名,前后端系统共享
)

Variables

This section is empty.

Functions

func Context

func Context() *sContext

Context 上下文管理服务

func EncryptPassword

func EncryptPassword(password, salt string) string

EncryptPassword 密码加密

func FileIsExisted

func FileIsExisted(filename string) bool

文件或文件夹是否存在

func GetCityByIp

func GetCityByIp(ip string) string

GetCityByIp 获取ip所属城市

func GetClientIp

func GetClientIp(ctx context.Context) string

GetClientIp 获取客户端IP

func GetDomain

func GetDomain(ctx context.Context) string

GetDomain 获取当前请求接口域名

func GetExt

func GetExt(fileName string) string

获取文件后缀

func GetHeader

func GetHeader(ctx context.Context) http.Header

GetHeader 获取当前请求Header

func GetLocalIP

func GetLocalIP() (ip string, err error)

GetLocalIP 服务端ip

func GetRemoteAddr

func GetRemoteAddr(ctx context.Context) string

GetRemoteAddr 获取当前请求RemoteAddr

func GetType

func GetType(p string) (result string, err error)

GetType 获取文件类型

func GetUserAgent

func GetUserAgent(ctx context.Context) string

GetUserAgent 获取user-agent

func GetUserAgentOther

func GetUserAgentOther(_agent string) *user_agent.UserAgent

获取用户其它信息

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir 检查文件夹是否存在 如果不存在则新建文件夹

func MkDir

func MkDir(src string) error

MkDir 新建文件夹

func ParseFilePath

func ParseFilePath(pathStr string) (fileName string, fileType string)

解析路径获取文件名称及后缀

func WriteToFile

func WriteToFile(fileName string, content string) error

写入文件

Types

type DoRes

type DoRes[T g.Map | g.List | any] struct {
	Code int    `json:"code" dc:"状态码"`
	Data T      `json:"data,omitempty" dc:"返回数据"`
	Msg  string `json:"msg" dc:"返回消息"`
}

基础响应对象

func (*DoRes[T]) RtJs

func (res *DoRes[T]) RtJs(ctx context.Context, _json any)

输出json

type UserContext

type UserContext struct {
	UserInfo  *UserInfoModel `json:"userInfo" dc:"用户信息"`
	Token     string         `json:"token" dc:"用户token"`
	OtherInfo g.Map          `json:"otherInfo" dc:"其它kv"` // 自定KV变量,业务模块根据需要设置,不固定
}

用户上下文

type UserInfoModel

type UserInfoModel struct {
	LoginType string `json:"loginType" dc:"登录方式"`
	LoginId   string `json:"loginId" dc:"登录id"`
	RnStr     string `json:"rnStr" dc:"随机字符串"`
	Clientid  string `json:"clientid" dc:"客户端id"`
	TenantId  string `json:"tenantId" dc:"租户id"`
	UserId    int64  `json:"userId" dc:"用户id"`
	UserName  string `json:"userName" dc:"用户名"`
	DeptId    int64  `json:"deptId" dc:"所属部门id"`
	DeptName  string `json:"deptName" dc:"所属部门名称"`
}

用户信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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