util

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package util go实用库 RSA的签名及验签 SHA256 With RSA

Package util go实用库 RSA的签名及验签 SHA256 With RSA

Package util go实用库 安全散列算法SHA常用函数

Index

Constants

View Source
const (
	ServiceInfoKeyPrefix   = "service.info."
	ServiceConfigKeyPrefix = "service.config."
)

Variables

This section is empty.

Functions

func AddGlobalFields added in v1.0.4

func AddGlobalFields(name, mode string)

func BaseCors added in v1.0.6

func BaseCors(w http.ResponseWriter)

func BaseMiddleware added in v1.0.6

func BaseMiddleware(next http.HandlerFunc) http.HandlerFunc

func Ceil

func Ceil(v float64) float64

Ceil 进一法

func Date

func Date(s, layout string) (int64, error)

Date 获取日期字符串的当地Unix时间戳 layout s的时间格式

func Floor

func Floor(v float64) float64

Floor 舍弃法

func GenerateUUID added in v1.0.6

func GenerateUUID() (uuid string, err error)

UUID 获取uuid

func LimitOffset added in v1.0.1

func LimitOffset(page, pageSize int32) (limit, offset uint64)

LimitOffset 用于获取sql分页的limit和offset

func MD5

func MD5(s string) string

MD5 字符串md5加密

func MobileEncode

func MobileEncode(mobile string) string

MobileEncode 手机号加星星, 显示前3位开头和4位尾号

func ParseTimeByUUID

func ParseTimeByUUID(uuid string) (dateTime string, err error)

ParseTimeByUUID 根据uuid, 获取生成该uuid的时间

func RSA

func RSA(src, privateKey string) (s string, err error)

RSA RSA签名

func RSACheck

func RSACheck(src, sign, publicKey string) (ok bool, err error)

RSACheck RSA验签

func Random

func Random(min, max int64) int64

Random 随机生成指定范围的数

func RandomNumber

func RandomNumber() int64

RandomNumber 随机生成一个数

func RandomStr

func RandomStr(length int) string

RandomStr 随机指定长度的字符串,不含大写

func RandomString

func RandomString(length int) string

RandomString 生成随机字符串

func Response

func Response(w http.ResponseWriter, resp interface{}, err error, code ...int)

func Round

func Round(v float64, decimals int) float64

Round 四舍五入 decimals 精确到几位小数

func SHA256

func SHA256(s []byte) (r []byte, err error)

SHA256 加密

func StringToTime

func StringToTime(str, format string) (t time.Time, err error)

func TimeToString

func TimeToString(t time.Time, format string) string

Types

type BasicContext added in v1.0.6

type BasicContext string
const (
	Token      BasicContext = "token"
	UUID       BasicContext = "uuid"
	Name       BasicContext = "name"
	PageURI    BasicContext = "pageURI"
	RequestURI BasicContext = "requestURI"
	SystemCode BasicContext = "systemCode"
)

type Body

type Body struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

type Client added in v1.0.2

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

func NewEtcdCli added in v1.0.2

func NewEtcdCli(endpoints []string) (cli Client)

func (Client) Close added in v1.0.2

func (cli Client) Close() error

func (Client) Delete added in v1.0.2

func (cli Client) Delete(key string) (err error)

删除key

func (Client) Get added in v1.0.2

func (cli Client) Get(key string) (value []byte, err error)

func (Client) GetByPrefix added in v1.0.2

func (cli Client) GetByPrefix(key string) (res []map[string][]byte, err error)

func (Client) GetByPrefixDesc added in v1.0.2

func (cli Client) GetByPrefixDesc(key string) (res []map[string][]byte, err error)

获取key前缀的kv

func (Client) GetConfig added in v1.0.2

func (cli Client) GetConfig(serviceName string, mode string, prevision int64) (content string, version int64, err error)

func (Client) GetOneByPrefix added in v1.0.2

func (cli Client) GetOneByPrefix(keyPrefix string) (key string, value []byte, err error)

基于key降序获取key前缀的第一个kv

func (Client) GetOneByPrefixDesc added in v1.0.5

func (cli Client) GetOneByPrefixDesc(keyPrefix string) (key string, value []byte, err error)

基于创建时间降序获取key前缀的第一个kv 其实 clientv3.WithSort(clientv3.SortByCreateRevision, clientv3.SortDescend) 可以去掉,默认也是按这个排序

func (Client) GetOneKeyByPrefix added in v1.0.2

func (cli Client) GetOneKeyByPrefix(keyPrefix string) (key string, err error)

基于key降序获取key前缀的第一个key

func (Client) GetOneKeyByPrefixDesc added in v1.0.5

func (cli Client) GetOneKeyByPrefixDesc(keyPrefix string) (key string, err error)

基于创建时间降序获取key前缀的第一个key 其实 clientv3.WithSort(clientv3.SortByCreateRevision, clientv3.SortDescend) 可以去掉,默认也是按这个排序

func (Client) GetPageListByPrefix added in v1.0.2

func (cli Client) GetPageListByPrefix(key string) (res []map[string][]byte, err error)

func (Client) GetWithOption added in v1.0.2

func (cli Client) GetWithOption(key string, opts []clientv3.OpOption) (res []map[string][]byte, err error)

获取key前缀的kv

func (Client) InitMerge added in v1.0.2

func (cli Client) InitMerge(name, mode string, cPoint any) int64

func (Client) Put added in v1.0.2

func (cli Client) Put(key, value string) error

func (Client) Watch added in v1.0.2

func (cli Client) Watch(serviceName, mode string, version int64, action func(string))

type ErrorMsg added in v1.0.8

type ErrorMsg struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func (*ErrorMsg) Error added in v1.0.8

func (e *ErrorMsg) Error() string

func (*ErrorMsg) Response added in v1.0.9

func (e *ErrorMsg) Response(w http.ResponseWriter)

type ModeVsersion added in v1.0.2

type ModeVsersion struct {
	Dev  int64 `json:"dev"`  // 开发环境
	Test int64 `json:"test"` // 测试环境
	Pre  int64 `json:"pre"`  // 预生产环境
	Pro  int64 `json:"pro"`  // 生产环境
}

type Service added in v1.0.2

type Service struct {
	Typ            string       `json:"type"`           // 服务类型, api、rpc
	Summary        string       `json:"summary"`        // 服务概述
	CurrentVersion ModeVsersion `json:"currentVersion"` // 当前版本
}

type ServiceConfig added in v1.0.2

type ServiceConfig struct {
	Content    string `json:"content"`    // 版本创建时间
	CreateTime string `json:"createTime"` // 版本创建时间
	CreateUser string `json:"createUser"` // 创建人
	UpdateTime string `json:"updateTime"` // 最近版本落地时间
}

Jump to

Keyboard shortcuts

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