util

package
v0.0.0-...-c78e9a6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: LGPL-2.1 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOG_LEVEL_WARN  int = 0
	LOG_LEVEL_INFO  int = 1
	LOG_LEVEL_DEBUG int = 2
	LOG_LEVEL_TRACE int = 3
	LOG_LEVEL_ERROR int = -1
	LOG_LEVEL_FATAL int = -2
)
View Source
const DEFAULT_DIRECTORY_PERMISSION = 0775
View Source
const DEFAULT_FILE_PERMISSION = 0664
View Source
const HASH_KEY = "CDKCloud."

Variables

View Source
var LogFileInitialized = false
View Source
var LogLevel = map[string]int{
	"WARN":  0,
	"INFO":  1,
	"DEBUG": 2,
	"TRACE": 3,
	"ERROR": -1,
	"FATAL": -2,
}
View Source
var LogLevelEnvName = "LOG_LEVEL"
View Source
var LogLevelName = map[int]string{
	0:  "WARN",
	1:  "INFO",
	2:  "DEBUG",
	3:  "TRACE",
	-1: "ERROR",
	-2: "FATAL",
}
View Source
var ServerToken = ""

Functions

func BodyDump

func BodyDump(ignore ...string) echo.MiddlewareFunc

func CheckFileExists

func CheckFileExists(name string) bool

func ConvertType

func ConvertType(sourceValue any, targetType reflect.Type) (any, error)

func CopyFile

func CopyFile(infile, outfile string) error

func CopyMap

func CopyMap[K comparable, V any](src map[K]V) map[K]V

CopyMap returns a shallow copy of src. Returns nil if src is nil.

func CreateFormFile

func CreateFormFile(fieldname, filename string) textproto.MIMEHeader

Set the Content-Type of upload file.

func ExecCommand

func ExecCommand(dir string, name string, flags ...string) (out []byte, err error)

func GenerateGJWToken

func GenerateGJWToken(password, deviceid, userid, issuer string,
	roles []string, expire_seconds int64) (string, error)

func GenerateGJWTokenWithTime

func GenerateGJWTokenWithTime(password string, deviceid string, userid string, issuer string, roles []string, expire_seconds int64, current time.Time) (string, error)

func GenerateServerToken

func GenerateServerToken(password, systemid, userid, issuer string,
	roles []string, expire_seconds int64) (string, error)

func GenerateServerTokenWithTime

func GenerateServerTokenWithTime(password string, systemid string, userid string, issuer string, roles []string, expire_seconds int64, current time.Time) (string, error)

func GetContentType

func GetContentType(ext string) string

func GetFileName

func GetFileName(file string) string

func GetFileSize

func GetFileSize(name string) (int64, error)

func GetHeader

func GetHeader(depth int) string

func GetStreamUUID

func GetStreamUUID() (string, error)

func GetStringSignature

func GetStringSignature(src string, key string, length int) string

func GetStructJSON

func GetStructJSON(v interface{}) string

func GetSysLogLevel

func GetSysLogLevel() int

func GetTempFileName

func GetTempFileName(tempFolder string, pattern string) (string, error)

func GetUUID

func GetUUID() (string, error)

func GetWorkFolder

func GetWorkFolder(jobId string, rootPath string, create bool) (string, error)

func HTTPDeleteFile

func HTTPDeleteFile(url string) ([]byte, error)

func HTTPGetFile

func HTTPGetFile(url string, file string) error

func HTTPGetRequest

func HTTPGetRequest(url string) ([]byte, error)

func HTTPGetRequestAuth

func HTTPGetRequestAuth(url string, token string) ([]byte, error)

func HTTPGetRequestInternal

func HTTPGetRequestInternal(url string, headers *map[string]string) ([]byte, error)

func HTTPPostRequest

func HTTPPostRequest(url string, contentType string, post []byte) ([]byte, int, error)

func HTTPPostRequestAuth

func HTTPPostRequestAuth(url string, contentType string, post []byte, token string) ([]byte, int, error)

func HTTPPostRequestInternal

func HTTPPostRequestInternal(url string, contentType string, post []byte, timeout int, headers *map[string]string) ([]byte, int, error)

func HTTPUploadFile

func HTTPUploadFile(filename, url string, fieldname string) ([]byte, error)

func ImplementsInterface

func ImplementsInterface(target reflect.Type, theInterface reflect.Type) bool

func InitLogFile

func InitLogFile(logowner string, minversion string, folder string) (*os.File, error)

func IsArrayType

func IsArrayType(target reflect.Type) bool

func IsConvertible

func IsConvertible(sourceValue any, targetType reflect.Type) bool

func IsEmptyStr

func IsEmptyStr(target *string) bool

func IsErrorObj

func IsErrorObj(target interface{}) bool

func IsErrorType

func IsErrorType(target reflect.Type) bool

func IsFuncType

func IsFuncType(target reflect.Type) bool

func IsInterfaceType

func IsInterfaceType(target reflect.Type) bool

func IsPointerType

func IsPointerType(target reflect.Type) bool

func IsStructType

func IsStructType(target reflect.Type) bool

func IsValidID

func IsValidID(id string) bool

func IsValidRole

func IsValidRole(role string) bool

func IsValidStreamUUID

func IsValidStreamUUID(id string) bool

func IsValidURL

func IsValidURL(urlstr string) bool

func IsValidUUID

func IsValidUUID(uuid string) bool

func LoadServerKey

func LoadServerKey(certfile, certkey, certca string) (*http.Server, error)

func LogWithLevel

func LogWithLevel(level int, loggeronly bool, v ...interface{})

func LogWithLevelJSON

func LogWithLevelJSON(level int, logger bool, v interface{})

func NewNameSameExt

func NewNameSameExt(oldFilePathWithExt string, newFileNameNoExt string) string

func PostRequest

func PostRequest(url string, request interface{}) (string, int, error)

func PostRequestAuth

func PostRequestAuth(url string, request interface{}, token string) (string, int, error)

func RandStringAlphaNums

func RandStringAlphaNums(n int) string

func RandStringLetters

func RandStringLetters(n int) string

func ReadFile

func ReadFile(filename string) ([]byte, error)

func SetLogLevelEnvName

func SetLogLevelEnvName(name string)

func StdOutFormat

func StdOutFormat(v ...interface{})

func StdOutFormatWithLevel

func StdOutFormatWithLevel(level int, v ...interface{})

func StringInSlice

func StringInSlice(a string, list []string) bool

func ToPtr

func ToPtr[T interface{}](source T) *T

func Unused

func Unused(_ ...interface{})

Unused is for avoiding unused variable error, in case you want to run debugging and inspect the variable value. Example:

svc := NewService();
utility.Unused(svc); // Now put breakpoint and run debugger here.

func WriteFile

func WriteFile(filename string, data []byte) error

Types

type ApiError

type ApiError struct {
	Code  int    `json:"code,omitempty"`
	Error string `json:"error"`
}

func NewApiCodeError

func NewApiCodeError(text string, code int) *ApiError

func NewApiError

func NewApiError(text string) *ApiError

type GJWCustomClaims

type GJWCustomClaims struct {
	UserId string   `json:"userid,omitempty"`
	DId    string   `json:"did,omitempty"`
	Roles  []string `json:"roles"`
	jwt.RegisteredClaims
}

type GJWTokenPayload

type GJWTokenPayload struct {
	UserId string   `json:"userid,omitempty"`
	DId    string   `json:"did,omitempty"`
	Roles  []string `json:"roles"`
}

func ParseGJWToken

func ParseGJWToken(tokenString string, password string) (*GJWTokenPayload, error)

type Logger

type Logger struct {
}

func (*Logger) Debug

func (log *Logger) Debug(v ...interface{})

func (*Logger) Error

func (log *Logger) Error(v ...interface{})

func (*Logger) FDebug

func (log *Logger) FDebug(v ...interface{})

func (*Logger) FError

func (log *Logger) FError(v ...interface{})

func (*Logger) FFatal

func (log *Logger) FFatal(v ...interface{})

func (*Logger) FInfo

func (log *Logger) FInfo(v ...interface{})

func (*Logger) FWarn

func (log *Logger) FWarn(v ...interface{})

func (*Logger) Fatal

func (log *Logger) Fatal(v ...interface{})

func (*Logger) Info

func (log *Logger) Info(v ...interface{})

func (*Logger) Warn

func (log *Logger) Warn(v ...interface{})

type RequestContext

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

func NewRequestContext

func NewRequestContext() *RequestContext

func (*RequestContext) DbTx

func (this *RequestContext) DbTx() *gorm.DB

func (*RequestContext) GetContext

func (this *RequestContext) GetContext() context.Context

func (*RequestContext) GoContext

func (this *RequestContext) GoContext() context.Context

func (*RequestContext) TODO

func (this *RequestContext) TODO() *RequestContext

func (*RequestContext) WithDbTx

func (this *RequestContext) WithDbTx(tx *gorm.DB) *RequestContext

func (*RequestContext) WithGoContext

func (this *RequestContext) WithGoContext(ctx context.Context) *RequestContext

type ServerCustomClaims

type ServerCustomClaims struct {
	SystemId string   `json:"systemid"`
	UserId   string   `json:"userid"`
	Roles    []string `json:"roles"`
	jwt.RegisteredClaims
}

type ServerTokenPayload

type ServerTokenPayload struct {
	UserId   string   `json:"userid"`
	SystemId string   `json:"systemid"`
	Roles    []string `json:"roles"`
}

Jump to

Keyboard shortcuts

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