utils

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 23 Imported by: 31

Documentation

Index

Constants

View Source
const (
	// Log Type
	Console = "Console"
	System  = "System"
	Result  = "Result"

	WebIDESource = "apaas-ide"
	ISWebIDE     = "IS_WEB_IDE"
)

Variables

This section is empty.

Functions

func AesDecryptText

func AesDecryptText(fieldID int64, realEncryptKey []byte, encryptedText string) (originText string, err error)

func BoolPtr

func BoolPtr(val bool) *bool

func BoolValueOfPtr

func BoolValueOfPtr(val *bool) bool

func Decode

func Decode(input interface{}, output interface{}) error

func EnableMesh added in v0.0.23

func EnableMesh() bool

EnableMesh 是否支持 Mesh,通过 FaaS 的环境变量来判断

func ErrorWrapper added in v0.0.22

func ErrorWrapper(body []byte, extra map[string]interface{}, err error) ([]byte, error)

func GetAGWDomain

func GetAGWDomain(ctx context.Context) string

func GetAGWDomainByConf

func GetAGWDomainByConf(ctx context.Context) string

func GetAPaaSLaneFromCtx added in v0.0.4

func GetAPaaSLaneFromCtx(ctx context.Context) string

func GetAPaaSPersistFaaSMapFromCtx added in v0.0.4

func GetAPaaSPersistFaaSMapFromCtx(ctx context.Context) (copyRes map[string]string)

func GetAPaaSPersistFaaSMapStr added in v0.0.4

func GetAPaaSPersistFaaSMapStr(ctx context.Context) string

func GetAPaaSPersistFaaSValueFromCtx added in v0.0.4

func GetAPaaSPersistFaaSValueFromCtx(ctx context.Context, key string) string

func GetApiTimeoutFromCtx

func GetApiTimeoutFromCtx(ctx context.Context) map[string]int64

func GetAppIDAndSecret

func GetAppIDAndSecret() (string, string, error)

func GetAppInfoFromCtx added in v0.0.8

func GetAppInfoFromCtx(ctx context.Context) (*structs.AppInfo, error)

func GetBizIDC added in v0.0.34

func GetBizIDC() string

func GetBoe

func GetBoe(ctx context.Context) string

func GetCurFunctionMetaConfFromCtx added in v0.0.19

func GetCurFunctionMetaConfFromCtx(ctx context.Context) *structs.FunctionMeta

func GetDebugTypeFromCtx

func GetDebugTypeFromCtx(ctx context.Context) int

func GetDistributedMaskFromCtx

func GetDistributedMaskFromCtx(ctx context.Context) string

func GetEnv

func GetEnv() string

func GetEnvBoeFromCtx

func GetEnvBoeFromCtx(ctx context.Context) string

func GetEnvOrgID

func GetEnvOrgID() string

func GetEventInfoFromCtx added in v0.0.8

func GetEventInfoFromCtx(ctx context.Context) (*structs.EventInfo, error)

func GetExecuteIDFromCtx added in v0.0.29

func GetExecuteIDFromCtx(ctx context.Context) string

func GetFaaSEnvIDFromCtx added in v0.0.23

func GetFaaSEnvIDFromCtx(ctx context.Context) string

func GetFaaSEnvTypeFromCtx added in v0.0.23

func GetFaaSEnvTypeFromCtx(ctx context.Context) int64

GetEnvTypeFromCtx

func GetFaaSInfraDomain

func GetFaaSInfraDomain(ctx context.Context) string

func GetFaaSInfraDomainName added in v0.0.23

func GetFaaSInfraDomainName() string

func GetFaaSInfraPSM added in v0.0.23

func GetFaaSInfraPSM(ctx context.Context) string

Deprecated

func GetFaaSInfraPSMFromEnv added in v0.0.23

func GetFaaSInfraPSMFromEnv() (psm string, cluster string)

func GetFaaSLaneIDFromCtx added in v0.0.20

func GetFaaSLaneIDFromCtx(ctx context.Context) string

func GetFaaSPlatform added in v0.0.23

func GetFaaSPlatform() string

func GetFaaSType added in v0.0.4

func GetFaaSType(ctx context.Context) string

func GetFuncAPINameFromCtx added in v0.0.19

func GetFuncAPINameFromCtx(ctx context.Context) string

func GetFunctionAPIIDFromCtx added in v0.0.31

func GetFunctionAPIIDFromCtx(ctx context.Context) string

func GetFunctionMetaConfFromCtx added in v0.0.19

func GetFunctionMetaConfFromCtx(ctx context.Context, apiName string) *structs.FunctionMeta

func GetFunctionNameFromCtx

func GetFunctionNameFromCtx(ctx context.Context) string

func GetGlobalAuthType added in v0.0.21

func GetGlobalAuthType() *string

GetGlobalAuthType 全局鉴权类型配置,优先级低于接口级

func GetInnerAPIPSM

func GetInnerAPIPSM(ctx context.Context) string

GetInnerAPIPSM open-sdk: from ctx faaS-sdk: from const by env Deprecated

func GetInnerAPIPSMFromCtx

func GetInnerAPIPSMFromCtx(ctx context.Context) string

func GetInnerAPIPSMFromEnv added in v0.0.23

func GetInnerAPIPSMFromEnv() string

func GetLGWClusterFromEnv added in v0.0.23

func GetLGWClusterFromEnv() string

func GetLGWPSMFromEnv added in v0.0.23

func GetLGWPSMFromEnv() string

func GetLogIDFromCtx

func GetLogIDFromCtx(ctx context.Context) string

func GetLogIDFromExtra

func GetLogIDFromExtra(extra map[string]interface{}) string

func GetLoopMaskFromCtx

func GetLoopMaskFromCtx(ctx context.Context) []string

func GetMeshDestReqTimeout added in v0.0.28

func GetMeshDestReqTimeout(ctx context.Context) int64

func GetNamespace

func GetNamespace() string

func GetNamespaceFromCtx

func GetNamespaceFromCtx(ctx context.Context) string

func GetOpenAPIDomain

func GetOpenAPIDomain(ctx context.Context) string

func GetOpenAPIDomainByConf added in v0.0.23

func GetOpenAPIDomainByConf(ctx context.Context) string

func GetOpenAPIDomainName added in v0.0.23

func GetOpenAPIDomainName() string

func GetOpenAPIPSMAndCluster added in v0.0.23

func GetOpenAPIPSMAndCluster(ctx context.Context) (psm string, cluster string)

func GetParamUnauthFieldByKey added in v0.0.19

func GetParamUnauthFieldByKey(ctx context.Context, key string) (unauthFields interface{})

func GetParamUnauthFieldMapFromCtx added in v0.0.19

func GetParamUnauthFieldMapFromCtx(ctx context.Context) (keyToUnauthFields map[string]interface{})

参数对应的无权限字段

func GetParamUnauthFieldRecordByKey added in v0.0.19

func GetParamUnauthFieldRecordByKey(ctx context.Context, key string) (unauthFields []string)

func GetParamUnauthFieldRecordListByKey added in v0.0.19

func GetParamUnauthFieldRecordListByKey(ctx context.Context, key string) (unauthFieldsList [][]string)

func GetRecordID added in v0.0.19

func GetRecordID(record interface{}) int64

func GetRecordUnauthFieldByObject added in v0.0.19

func GetRecordUnauthFieldByObject(ctx context.Context, objectAPIName string) (recordIDToUnauthFields map[int64][]string)

func GetRecordUnauthFieldByObjectAndRecordID added in v0.0.19

func GetRecordUnauthFieldByObjectAndRecordID(ctx context.Context, objectAPIName string, recordID int64) (unauthFields []string)

func GetSDKConf added in v0.0.23

func GetSDKConf(ctx context.Context) *structs.SDKConf

func GetSDKTransientConf added in v0.0.23

func GetSDKTransientConf(ctx context.Context) *structs.SDKTransientConf

func GetServiceID

func GetServiceID() string

func GetSocketAddr added in v0.0.23

func GetSocketAddr() string

func GetSourceTypeFromCtx

func GetSourceTypeFromCtx(ctx context.Context) int

func GetTTEnvFromCtx

func GetTTEnvFromCtx(ctx context.Context) string

func GetTenantFromCtx

func GetTenantFromCtx(ctx context.Context) (*structs.Tenant, error)

func GetTenantIDFromCtx

func GetTenantIDFromCtx(ctx context.Context) int64

func GetTenantName

func GetTenantName() string

func GetTenantTypeFromCtx added in v0.0.29

func GetTenantTypeFromCtx(ctx context.Context) int64

func GetTraceHeader added in v0.0.23

func GetTraceHeader(ctx context.Context) map[string]string

func GetTriggerTaskIDFromCtx

func GetTriggerTaskIDFromCtx(ctx context.Context) int64

func GetTriggerTypeFromCtx

func GetTriggerTypeFromCtx(ctx context.Context) string

func GetUserContext

func GetUserContext(ctx context.Context) (res structs.UserContext)

func GetUserContextMap added in v0.0.2

func GetUserContextMap(ctx context.Context) (res map[string]interface{})

func GetUserIDFromCtx

func GetUserIDFromCtx(ctx context.Context) int64

func Int64InInt64s

func Int64InInt64s(ns []int, n int) bool

func Int64Ptr

func Int64Ptr(val int64) *int64

func Int64ValueOfPtr

func Int64ValueOfPtr(p *int64, defaultVal int64) int64

func IntInInts

func IntInInts(ns []int, n int) bool

func IntPtr

func IntPtr(val int) *int

func IntValueOfPtr

func IntValueOfPtr(p *int, defaultVal int) int

func InvokeFuncWithRetry

func InvokeFuncWithRetry(retryCount int, retryInterval time.Duration, f func() error) error

func IsCloseMesh added in v0.0.23

func IsCloseMesh(ctx context.Context) bool

func IsDebug

func IsDebug(ctx context.Context) bool

IsDebug 是否调试

func IsExternalFaaS added in v0.0.23

func IsExternalFaaS() bool

func IsLocalDebug

func IsLocalDebug(ctx context.Context) bool

func IsMicroservice added in v0.0.4

func IsMicroservice(ctx context.Context) bool

func IsRuntime added in v0.0.23

func IsRuntime(ctx context.Context) bool

func IsTrueString added in v0.0.23

func IsTrueString(str string) bool

func JsonMarshalBytes

func JsonMarshalBytes(val interface{}) ([]byte, error)

func JsonUnmarshalBytes

func JsonUnmarshalBytes(val []byte, addr interface{}) error

func LevelInfo

func LevelInfo(level logrus.Level) (string, int)

func NowMils

func NowMils() int64

func OpenMesh added in v0.0.23

func OpenMesh(ctx context.Context) bool

OpenMesh 是否开启 Mesh,有开关可以关闭 Mesh,有些场景不允许走 Mesh

func ParseStrList added in v0.0.19

func ParseStrList(v interface{}) (strs []string)

func ParseStrsList added in v0.0.19

func ParseStrsList(v interface{}) (strsList [][]string)

func PrintLog

func PrintLog(contents ...interface{})

PrintLog unittest to use

func PtrToInt

func PtrToInt(p *int, defaultVal int) int

func SetAPaaSLaneToCtx added in v0.0.4

func SetAPaaSLaneToCtx(ctx context.Context, lane string) context.Context

func SetAPaaSPersistFaaSMapToCtx added in v0.0.4

func SetAPaaSPersistFaaSMapToCtx(ctx context.Context, aPaaSPersistFaaSMap map[string]string) context.Context

func SetAPaaSPersistHeader added in v0.0.26

func SetAPaaSPersistHeader(ctx context.Context, header http.Header)

func SetApiTimeoutMethodToCtx

func SetApiTimeoutMethodToCtx(ctx context.Context, method string) context.Context

func SetApiTimeoutToCtx

func SetApiTimeoutToCtx(ctx context.Context, timeout map[string]int64) context.Context

func SetAppInfoToCtx added in v0.0.8

func SetAppInfoToCtx(ctx context.Context, appInfo *structs.AppInfo) context.Context

func SetDebugTypeToCtx

func SetDebugTypeToCtx(ctx context.Context, debugType int) context.Context

func SetDistributedMaskToCtx

func SetDistributedMaskToCtx(ctx context.Context, mask string) context.Context

func SetEnvBoeToCtx

func SetEnvBoeToCtx(ctx context.Context, boe string) context.Context

func SetEventIDToCtx added in v0.0.29

func SetEventIDToCtx(ctx context.Context, eventID string) context.Context

func SetEventInfoToCtx added in v0.0.8

func SetEventInfoToCtx(ctx context.Context, appInfo *structs.EventInfo) context.Context

func SetFaaSEnvIDCtx added in v0.0.23

func SetFaaSEnvIDCtx(ctx context.Context, envID string) context.Context

func SetFaaSEnvTypeCtx added in v0.0.23

func SetFaaSEnvTypeCtx(ctx context.Context, envType int64) context.Context

func SetFaaSLaneIDCtx added in v0.0.20

func SetFaaSLaneIDCtx(ctx context.Context, laneID string) context.Context

func SetFuncAPINameToCtx added in v0.0.19

func SetFuncAPINameToCtx(ctx context.Context, funcAPIName string) context.Context

func SetFunctionMetaConfToCtx added in v0.0.19

func SetFunctionMetaConfToCtx(ctx context.Context, metaConf map[string]string) context.Context

SetFunctionMetaConfToCtx 提供给框架层使用

func SetFunctionNameToCtx

func SetFunctionNameToCtx(ctx context.Context, functionName string) context.Context

func SetInnerAPIPSMToCtx

func SetInnerAPIPSMToCtx(ctx context.Context, psm string) context.Context

func SetKEnvToCtx

func SetKEnvToCtx(ctx context.Context, kEnv string) context.Context

func SetKEnvToCtxForRPC

func SetKEnvToCtxForRPC(ctx context.Context) context.Context

func SetLogIDToCtx

func SetLogIDToCtx(ctx context.Context, logID string) context.Context

func SetLoopMaskToCtx

func SetLoopMaskToCtx(ctx context.Context, mask []string) context.Context

func SetRecordUnauthField added in v0.0.19

func SetRecordUnauthField(ctx context.Context, unauthFieldMap RecordUnauthField) context.Context

func SetRuntimeType added in v0.0.23

func SetRuntimeType(ctx context.Context, runtimeType string) context.Context

func SetSourceTypeToCtx

func SetSourceTypeToCtx(ctx context.Context, sourceType int) context.Context

func SetTTEnvToCtx

func SetTTEnvToCtx(ctx context.Context, ttEnv string) context.Context

func SetTenantToCtx

func SetTenantToCtx(ctx context.Context, tenant *structs.Tenant) context.Context

func SetTriggerTaskIDToCtx

func SetTriggerTaskIDToCtx(ctx context.Context, taskID int64) context.Context

func SetTriggerTypeToCtx

func SetTriggerTypeToCtx(ctx context.Context, triggerType string) context.Context

func SetUserAndAuthTypeToCtx added in v0.0.5

func SetUserAndAuthTypeToCtx(ctx context.Context, authType *string) context.Context

func SetUserAndAuthTypeToHeaders added in v0.0.5

func SetUserAndAuthTypeToHeaders(ctx context.Context, headers map[string][]string) map[string][]string

func SetUserAndMixAuthTypeToCtx added in v0.0.19

func SetUserAndMixAuthTypeToCtx(ctx context.Context, authType *string, isMix bool) context.Context

SetUserAndMixAuthTypeToCtx 设置鉴权方式 - 接口级配置优先级高于函数级 - 函数级配置 - oql 接口使用 system 和 mix_user_system - 除 oql 之外的接口使用 system 和 user

func SetUserAndMixAuthTypeToHeaders added in v0.0.19

func SetUserAndMixAuthTypeToHeaders(ctx context.Context, headers map[string][]string, isMix bool) map[string][]string

func SetUserContext

func SetUserContext(ctx context.Context, userCtx structs.UserContext) context.Context

func SetUserContextMap added in v0.0.2

func SetUserContextMap(ctx context.Context, userCtxMap map[string]interface{}) context.Context

func SetUserIDToCtx

func SetUserIDToCtx(ctx context.Context, userID int64) context.Context

func StrInStrs

func StrInStrs(strs []string, str string) bool

func StringPtr

func StringPtr(val string) *string

func StringValueOfPtr

func StringValueOfPtr(p *string, defaultVal string) string

func TimeMils

func TimeMils(t time.Time) int64

func ToString added in v0.0.19

func ToString(v interface{}) string

func WebIDELevelInfo added in v0.0.7

func WebIDELevelInfo(level logrus.Level) string

func WithAPaaSPersistFaaSValue added in v0.0.4

func WithAPaaSPersistFaaSValue(ctx context.Context, key, value string) context.Context

func WriteUnauthFieldMapWithLock added in v0.0.22

func WriteUnauthFieldMapWithLock(ctx context.Context, objectAPIName string, recordID int64, unauthFields []string)

Types

type ConsoleLogger

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

func GetConsoleLogger

func GetConsoleLogger(logIDs ...string) *ConsoleLogger

func (*ConsoleLogger) Errorf

func (c *ConsoleLogger) Errorf(format string, args ...interface{})

func (*ConsoleLogger) Infof

func (c *ConsoleLogger) Infof(format string, args ...interface{})

func (*ConsoleLogger) Result

func (c *ConsoleLogger) Result(format string, args ...interface{})

func (*ConsoleLogger) Warnf

func (c *ConsoleLogger) Warnf(format string, args ...interface{})

type LogFormatter

type LogFormatter struct {
}

func (*LogFormatter) Format

func (m *LogFormatter) Format(entry *logrus.Entry) ([]byte, error)

type PathReplace

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

PathReplace 路径替换工具

func NewPathReplace

func NewPathReplace(path string) *PathReplace

func (*PathReplace) APIName

func (p *PathReplace) APIName(APIName string) *PathReplace

func (*PathReplace) ExecutionID

func (p *PathReplace) ExecutionID(instanceID int64) *PathReplace

func (*PathReplace) FieldAPIName

func (p *PathReplace) FieldAPIName(fieldAPIName string) *PathReplace

func (*PathReplace) FileID

func (p *PathReplace) FileID(fileID string) *PathReplace

func (*PathReplace) FunctionAPIName

func (p *PathReplace) FunctionAPIName(functionAPIName string) *PathReplace

func (*PathReplace) Namespace

func (p *PathReplace) Namespace(namespace string) *PathReplace

func (*PathReplace) ObjectAPIName

func (p *PathReplace) ObjectAPIName(objectAPIName string) *PathReplace

func (*PathReplace) ObjectAPINameV3 added in v0.0.33

func (p *PathReplace) ObjectAPINameV3(objectAPIName string) *PathReplace

func (*PathReplace) Path

func (p *PathReplace) Path() string

func (*PathReplace) RecordID

func (p *PathReplace) RecordID(recordID int64) *PathReplace

func (*PathReplace) RecordIDStr added in v0.0.33

func (p *PathReplace) RecordIDStr(recordID string) *PathReplace

type RecordUnauthField added in v0.0.19

type RecordUnauthField = map[string]map[int64][]string

RecordUnauthField 记录对应的无权限字段

func GetRecordUnauthField added in v0.0.19

func GetRecordUnauthField(ctx context.Context) (objToRecordIDToUnauthFields RecordUnauthField)

type RuntimeType added in v0.0.23

type RuntimeType string
const (
	RuntimeTypeRuntime    RuntimeType = "0" // 运行态
	RuntimeTypeCloudDebug RuntimeType = "1" // 云端调试
	RuntimeTypeLocalDebug RuntimeType = "2" // 本地调试
)

func GetRuntimeType added in v0.0.23

func GetRuntimeType(ctx context.Context) RuntimeType

type WebIDELogFormatter added in v0.0.7

type WebIDELogFormatter struct {
}

func (*WebIDELogFormatter) Format added in v0.0.7

func (m *WebIDELogFormatter) Format(entry *logrus.Entry) ([]byte, error)

Jump to

Keyboard shortcuts

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