util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectName = "flame"

	// General
	ALL          = "all"
	ID           = "id"
	Design       = "design"
	Message      = "message"
	Errors       = "errors"
	GenericError = "GenericError"
	InternalUser = "sys"

	// Status
	Status        = "status"
	StatusSuccess = "Success"
	StatusError   = "Error"

	// Database
	MONGODB = "mongodb"
	MySQL   = "mysql"

	// Database Fields
	//TODO append Field to distinguish the fields
	DBFieldMongoID          = "_id"
	DBFieldUserId           = "userid"
	DBFieldId               = "id"
	DBFieldDesignId         = "designid"
	DBFieldCode             = "code"
	DBFieldSchema           = "schema"
	DBFieldSchemaId         = "schemaid"
	DBFieldJobId            = "jobid"
	DBFieldTaskId           = "taskid"
	DBFieldState            = "state"
	DBFieldRole             = "role"
	DBFieldTaskLog          = "log"
	DBFieldIsPublic         = "ispublic"
	DBFieldTaskDirty        = "dirty"
	DBFieldTaskKey          = "key"
	DBFieldTimestamp        = "timestamp"
	DBFieldComputeId        = "computeid"
	DBFieldComputeRegion    = "region"
	DBFieldURL              = "url"
	DBFieldAgentStatuses    = "agentstatuses"
	DBFieldGroupAssociation = "groupassociation"

	// Port numbers
	ApiServerRestApiPort  = 10100 // REST API port
	NotifierGrpcPort      = 10101 // for notification and push
	ControllerRestApiPort = 10102 // Controller REST API port
	AgentGrpcPort         = 10103 // for flamelet - application
	MetaServerPort        = 10104 // meta data update and retrieval (Experimental)

	// Service names
	Agent      = "flamelet"
	ApiServer  = "apiserver"
	Controller = "controller"
	Notifier   = "notifier"
	MetaServer = "metaserver"
	Deployer   = "deployer"
	CliTool    = "flamectl"

	// file permission
	FilePerm0644 = 0644
	FilePerm0700 = 0700
	FilePerm0755 = 0755

	NumTokensInRestEndpoint = 3
	NumTokensInEndpoint     = 2

	TaskConfigFile = "config"
	TaskCodeFile   = "code.zip"

	LogDirPath = "/var/log/" + ProjectName

	DefaultRealm = "default"
	RealmSep     = "/"
)

Variables

This section is empty.

Functions

func ByteToStruct

func ByteToStruct(msg []byte, obj interface{}) error

func Contains

func Contains(haystack []string, needle string) bool

func CopyFile

func CopyFile(src string, dst string) error

func FormatJSON

func FormatJSON(data []byte) ([]byte, error)

FormatJSON prettify the json by adding tabs

func InitZapLog

func InitZapLog(service string) *zap.Logger

InitZapLog Zap Logger initialization

https://pkg.go.dev/go.uber.org/zap#ReplaceGlobals https://pkg.go.dev/go.uber.org/zap#hdr-Choosing_a_Logger

In most circumstances, use the SugaredLogger. It's 4-10x faster than most other structured logging packages and has a familiar, loosely-typed API.

sugar := logger.Sugar()
sugar.Infow("Failed to fetch URL.",
	// Structured context as loosely typed key-value pairs.
	"url", url,
	"attempt", 3,
	"backoff", time.Second,
)
sugar.Infof("Failed to fetch URL: %s", url)

In the unusual situations where every microsecond matters, use the Logger. It's even faster than the SugaredLogger, but only supports structured logging.

logger.Info("Failed to fetch URL.",
	// Structured context as strongly typed fields.
	zap.String("url", url),
	zap.Int("attempt", 3),
	zap.Duration("backoff", time.Second),
)

func JSONMarshal added in v0.1.3

func JSONMarshal(t interface{}) ([]byte, error)

Marshal JSON to escape HTML characters like <, > while printing

func PrettyJsonString added in v0.1.2

func PrettyJsonString(data []byte) (string, error)

func ProtoStructToStruct

func ProtoStructToStruct(msg *structpb.Struct, obj interface{}) error

func RandString

func RandString(n int) string

func ReadFileToStruct added in v0.2.2

func ReadFileToStruct(filePath string, obj interface{}) error

func StructToMapInterface

func StructToMapInterface(in interface{}) (map[string]interface{}, error)

StructToMapInterface converts any struct interface into map interface using json de-coding/encoding.

func ToProtoStruct

func ToProtoStruct(in interface{}) (*structpb.Struct, error)

func ZipFile

func ZipFile(fdList []FileData) ([]byte, error)

func ZipFileByTopLevelDir

func ZipFileByTopLevelDir(fdList []FileData) (map[string][]byte, error)

Types

type FileData

type FileData struct {
	BaseName string `json:"basename"`
	FullName string `json:"fullname"`
	Data     string `json:"data"`
}

func UnzipFile

func UnzipFile(file *os.File) ([]FileData, error)

Jump to

Keyboard shortcuts

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