utils

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 32 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ClusterCachePrefix          = "cluster-cache-"
	TokenCachePrefix            = "token-cache-"
	UserCachePrefix             = "user-cache-"
	AlertIndicatorCache         = "alert-indicator"
	PromAlertsCache             = "prom-alerts"
	AlertSilenceCache           = "alert-silence"
	AlertTenantClusterCache     = "alert-tenant-clusters"
	AlertClustersCache          = "alert-clusters"
	AlertMessagesCache          = "alert-message"
	AlertClusterCache           = "alert-cluster"
	AlertNodeCache              = "alert-node"
	AlertAppCache               = "alert-app"
	LicAllClusterVcpusCache     = "lic-all-cluster-vcpus"
	LicProductCache             = "lic-product-cache"
	ClusterPrometheusCacheKey   = "ClusterPrometheus__"
	ClusterAlertmanagerCacheKey = "ClusterAlertmanager__"
	ClusterSkywalkingCacheKey   = "ClusterSkywalking__"
)
View Source
const (
	Failed                   = "4000"
	FailedParamsError        = "4002"
	FailedRemoteServiceError = "4001"
	FailedUnknown            = "4003"
	FailedDecodeError        = "4004"
	AthorizationError        = "4005"
	JsonError                = "4006"
	ResourceNotFound         = "4007"
	LicenseError             = "4008"
	BiddenError              = "4009"
	RoleChangeNeedReLogin    = "4010"
)

request fail

View Source
const (
	SystemError = "9000"
)

system error

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(temp string, data map[string]interface{}) (string, error)

渲染模板

func BadDecode

func BadDecode(ctx *gin.Context, err error)

BadDecode 解码失败

func BadParams

func BadParams(ctx *gin.Context, err error)

BadParams 参数绑定失败

func CacheUrlAll

func CacheUrlAll() map[string]urlcache.UrlCache

获取URL全量数据

func CacheUrlGet

func CacheUrlGet(key string) (urlcache.UrlCache, bool)

获取URL缓存

func CacheUrlSet

func CacheUrlSet(value urlcache.UrlCache) error

设置URL缓存

func CacheUrlSetList

func CacheUrlSetList(values []urlcache.UrlCache) error

func ContainsString

func ContainsString(slice []string, s string) bool

func ConvCNMix2pinyin

func ConvCNMix2pinyin(mix string) string

中文+英文+数字

func DecodeBase64

func DecodeBase64(in string) (string, error)

解密base64

func DecodeURLBase64

func DecodeURLBase64(in string) (string, error)

func EncodeBase64

func EncodeBase64(in string) string

加密base64

func ExecCommand

func ExecCommand(cmd string) ([]byte, error)

func ExecCommandString

func ExecCommandString(cmd string) (string, error)

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetIPs

func GetIPs() (ips []string)

func GetIps

func GetIps() []string

func GetMacAddrs

func GetMacAddrs() (macAddrs []string)

0:cf:e0:44:dd:be,enp1s0

func GetRandomSalt

func GetRandomSalt() string

return len=8 salt

func GetRandomString

func GetRandomString(len int) string

生成随机字符串

func GzipDe

func GzipDe(in []byte) ([]byte, error)

解压文件

func GzipEn

func GzipEn(str string) ([]byte, error)

压缩文件

func In

func In(target string, source []string) bool

快速判断字符是否在字符数组中

func IsPathExists

func IsPathExists(path string) bool

func Jiami

func Jiami(code string) string

加密

func MD5

func MD5(text string) string

生成32位MD5

func Mkdir

func Mkdir(basePath string) string

定义一个创建文件目录的方法

func NewCacheCliWithTTL

func NewCacheCliWithTTL() *cache.Cache

func ParseIps

func ParseIps(in string) ([]string, error)

func PkgResp

func PkgResp(c *gin.Context, code int, result Result)

PkgResp 包装返回类

func SendError

func SendError(c *gin.Context, code int, err error)

SendError...

func SendErrorMessage

func SendErrorMessage(c *gin.Context, code int, errorCode string, errorMsg string)

SendErrorMessage select fail

func SendErrorMessageInterface

func SendErrorMessageInterface(c *gin.Context, code int, codeStr string, data interface{})

func SendMessage

func SendMessage(c *gin.Context, code int, success bool, data interface{}, errcode, errmsg, host, traceid, showtype string)

func SendSuccessMessage

func SendSuccessMessage(c *gin.Context, code int, data interface{})

SendSuccessMessage select success and have data

func WriteFile

func WriteFile(path string, data []byte) (int, error)

写文件

Types

type CodeGoutResponseUse

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

CodeGoutResponseUse 按code处理gout请求的response,方法不太公用,先放在这里

func NewCodeGoutResponseUse

func NewCodeGoutResponseUse(codes []int, check ...bool) *CodeGoutResponseUse

func (*CodeGoutResponseUse) ModifyResponse

func (c *CodeGoutResponseUse) ModifyResponse(response *http.Response) error

type E422

type E422 struct {
	Type    string      `json:"type"`
	Links   interface{} `json:"links"`
	Code    string      `json:"code"`
	Message string      `json:"message"`
	Status  int         `json:"status"`
}

func ParseE422

func ParseE422(data []byte) (*E422, error)

func (*E422) String

func (e *E422) String() string

type GoutCli

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

func NewGoutClient

func NewGoutClient() *GoutCli

默认开启tls忽略验证

func (*GoutCli) DELETE

func (g *GoutCli) DELETE(url string) *dataflow.DataFlow

func (*GoutCli) GET

func (g *GoutCli) GET(url string) *dataflow.DataFlow

统一处理k8s结构体异常的错误

func (*GoutCli) OPTIONS

func (g *GoutCli) OPTIONS(url string) *dataflow.DataFlow

func (*GoutCli) PATCH

func (g *GoutCli) PATCH(url string) *dataflow.DataFlow

func (*GoutCli) POST

func (g *GoutCli) POST(url string) *dataflow.DataFlow

func (*GoutCli) PUT

func (g *GoutCli) PUT(url string) *dataflow.DataFlow

func (*GoutCli) SetSkipVerify

func (g *GoutCli) SetSkipVerify(skipVerify bool) *GoutCli

自定义tls证书校验模式

type GoutError

type GoutError struct {
	Type    string      `json:"type"`
	Status  interface{} `json:"status"`
	Code    interface{} `json:"code"` // code有可能是一个结构体
	Message string      `json:"message"`
}

func (GoutError) Error

func (ge GoutError) Error() string

type GoutResponseDelete

type GoutResponseDelete struct{}

func (*GoutResponseDelete) ModifyResponse

func (g *GoutResponseDelete) ModifyResponse(response *http.Response) error

ModifyResponse 删除时 200、202都为成功 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#delete-secret-v1-core

type GoutResponseMiddleware

type GoutResponseMiddleware struct{}

func (*GoutResponseMiddleware) ModifyResponse

func (gout *GoutResponseMiddleware) ModifyResponse(response *http.Response) error

ModifyResponse 统一对gout请求的response中的code、date字段处理

type ModifyResponseUse

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

func NewModifyResponse

func NewModifyResponse(codes []int) *ModifyResponseUse

func (*ModifyResponseUse) ModifyResponse

func (c *ModifyResponseUse) ModifyResponse(response *http.Response) error

type Result

type Result struct {
	Success      bool        `json:"success"`
	Data         interface{} `json:"data"`
	ErrorCode    string      `json:"errorCode"`
	ErrorMessage string      `json:"message"`
	Host         string      `json:"host"`
	TraceId      string      `json:"traceid"`
	ShowType     string      `json:"showtype"`
	Code         int         `json:"code"`
}

func CliErr

func CliErr(err error) Result

func PkgErrorMsg

func PkgErrorMsg(errMsg string) Result

func PkgSuccess

func PkgSuccess(data interface{}) Result

func (*Result) String

func (r *Result) String() string

type ValueWrapper

type ValueWrapper struct {
	Value     interface{}
	CacheTime time.Time
	Duration  time.Duration
}

Directories

Path Synopsis
orm

Jump to

Keyboard shortcuts

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