utils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: BSD-2-Clause Imports: 9 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InfoHeaderf  = color.New(color.FgHiBlue).Add(color.Bold).PrintfFunc()
	Infof        = color.New(color.FgHiCyan).PrintfFunc()
	WarnHeaderf  = color.New(color.FgHiYellow).Add(color.Bold).PrintfFunc()
	Warnf        = color.New(color.FgHiYellow).PrintfFunc()
	ErrorHeaderf = color.New(color.FgHiRed).Add(color.Bold).PrintfFunc()
	Errorf       = color.New(color.FgHiRed).PrintfFunc()
)
View Source
var PlatformServerFlagConstants = map[string]map[string]string{
	"Hostname": {
		"FlagName":    "hostname",
		"ShortFlag":   "n",
		"Description": "Hostname where Plank accepts connections",
	},
	"Port": {
		"FlagName":    "port",
		"ShortFlag":   "p",
		"Description": "Port where Plank is to be served",
	},
	"RootDir": {
		"FlagName":    "rootdir",
		"ShortFlag":   "r",
		"Description": "Root directory for the server (default: Current directory)",
	},
	"Cert": {
		"FlagName":    "cert",
		"Description": "X509 Certificate file for TLS",
	},
	"CertKey": {
		"FlagName":    "cert-key",
		"Description": "X509 Certificate private Key file for TLS",
	},
	"Static": {
		"FlagName":    "static",
		"ShortFlag":   "s",
		"Description": "Path(s) where static files will be served",
	},
	"SpaPath": {
		"FlagName":    "spa-path",
		"Description": "Path to serve Single Page Application (SPA) from. The URI is derived from the leaf directory. A different URI can be specified by providing it following a colon (e.g. --spa-path ./path/to/spa-app:my-spa",
	},
	"NoFabricBroker": {
		"FlagName":    "no-fabric-broker",
		"Description": "Disable Fabric (STOMP) broker",
	},
	"FabricEndpoint": {
		"FlagName":    "fabric-endpoint",
		"Description": "Fabric broker endpoint",
	},
	"TopicPrefix": {
		"FlagName":    "topic-prefix",
		"Description": "Topic prefix for Fabric broker",
	},
	"QueuePrefix": {
		"FlagName":    "query-prefix",
		"Description": "Queue prefix for Fabric broker",
	},
	"RequestPrefix": {
		"FlagName":    "request-prefix",
		"Description": "Application request prefix for Fabric broker",
	},
	"RequestQueuePrefix": {
		"FlagName":    "request-queue-prefix",
		"Description": "Application request queue prefix for Fabric broker",
	},
	"ConfigFile": {
		"FlagName":    "config-file",
		"Description": "Path to the server config JSON file",
	},
	"ShutdownTimeout": {
		"FlagName":    "shutdown-timeout",
		"Description": "Graceful server shutdown timeout in minutes",
	},
	"OutputLog": {
		"FlagName":    "output-log",
		"ShortFlag":   "l",
		"Description": "Platform log output",
	},
	"AccessLog": {
		"FlagName":    "access-log",
		"ShortFlag":   "a",
		"Description": "HTTP server access log output",
	},
	"ErrorLog": {
		"FlagName":    "error-log",
		"ShortFlag":   "e",
		"Description": "HTTP server error log output",
	},
	"Debug": {
		"FlagName":    "debug",
		"ShortFlag":   "d",
		"Description": "Enable debug logging",
	},
	"NoBanner": {
		"FlagName":    "no-banner",
		"ShortFlag":   "b",
		"Description": "Do not print Plank banner at startup",
	},
	"Prometheus": {
		"FlagName":    "prometheus",
		"Description": "Enable Prometheus for basic runtime metrics",
	},
	"RestBridgeTimeout": {
		"FlagName":    "rest-bridge-timeout",
		"Description": "Time in minutes before a REST endpoint for a service request to timeout",
	},
}

Functions

func ContainsString

func ContainsString(arr []string, str string) bool

func ConvertInterfaceToByteArray

func ConvertInterfaceToByteArray(mimeType string, i interface{}) (results []byte, err error)

ConvertInterfaceToByteArray converts the interface i into a byte array. Depending on the value of mimeType being of JSON type, either JSON Marshaller is used or the interface is just straight cast to a byte array.

func CreateTextFormatterFromFormatOptions

func CreateTextFormatterFromFormatOptions(opts *LogFormatOption) *logrus.TextFormatter

CreateTextFormatterFromFormatOptions takes *server.LogFormatOption and returns the pointer to a new logrus.TextFormatter instance.

func DeriveStaticURIFromPath

func DeriveStaticURIFromPath(input string) (string, string)

func GetCallerStackFrame

func GetCallerStackFrame() runtime.Frame

func GetCurrentStackFrame

func GetCurrentStackFrame() runtime.Frame

func GetGoRoutineID

func GetGoRoutineID() string

func GetNewLogFilePointer

func GetNewLogFilePointer(file string) (*os.File, error)

GetNewLogFilePointer returns the pointer to a new os.File instance given the file name

func IsAbsolutePath

func IsAbsolutePath(p string) bool

IsAbsolutePath returns if path is an absolute path in *nix and Windows file systems

func JoinBasePathIfRelativeRegularFilePath

func JoinBasePathIfRelativeRegularFilePath(base string, in string) (out string)

func SanitizeUrl

func SanitizeUrl(url string, suffixSlash bool) string

SanitizeUrl removes excess forward slashes as well as pad the end of the URL with / if suffixSlash is true

Types

type LogConfig

type LogConfig struct {
	AccessLog     string           `json:"access_log"`
	ErrorLog      string           `json:"error_log"`
	OutputLog     string           `json:"output_log"`
	FormatOptions *LogFormatOption `json:"format_options"`
	Root          string           `json:"root"`
	// contains filtered or unexported fields
}

func (*LogConfig) GetAccessLogFilePointer

func (lc *LogConfig) GetAccessLogFilePointer() *os.File

func (*LogConfig) GetErrorLogFilePointer

func (lc *LogConfig) GetErrorLogFilePointer() *os.File

func (*LogConfig) GetPlatformLogFilePointer

func (lc *LogConfig) GetPlatformLogFilePointer() *os.File

func (*LogConfig) PrepareLogFiles

func (lc *LogConfig) PrepareLogFiles() error

type LogFormatOption

type LogFormatOption struct {
	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool `json:"force_colors"`

	// Force disabling colors.
	DisableColors bool `json:"disable_colors"`

	// Force quoting of all values
	ForceQuote bool `json:"force_quote"`

	// DisableQuote disables quoting for all values.
	// DisableQuote will have a lower priority than ForceQuote.
	// If both of them are set to true, quote will be forced on all values.
	DisableQuote bool `json:"disable_quote"`

	// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
	EnvironmentOverrideColors bool `json:"environment_override_colors"`

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool `json:"disable_timestamp"`

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool `json:"full_timestamp"`

	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string `json:"timestamp_format"`

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool `json:"disable_sorting"`

	// Disables the truncation of the level text to 4 characters.
	DisableLevelTruncation bool `json:"disable_level_truncation"`

	// PadLevelText Adds padding the level text so that all the levels output at the same length
	// PadLevelText is a superset of the DisableLevelTruncation option
	PadLevelText bool `json:"pad_level_text"`

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool `json:"quote_empty_fields"`

	// FieldMap allows users to customize the names of keys for default fields.
	// As an example:
	// formatter := &TextFormatter{
	//     FieldMap: FieldMap{
	//         FieldKeyTime:  "@timestamp",
	//         FieldKeyLevel: "@level",
	//         FieldKeyMsg:   "@message"}}
	FieldMap logrus.FieldMap
	// contains filtered or unexported fields
}

LogFormatOption is merely a wrapper of logrus.TextFormatter because TextFormatter does not allow serializing its public members of the struct

type PlankLogger

type PlankLogger struct {
	*logrus.Logger
}
var Log *PlankLogger

func (*PlankLogger) Debug

func (l *PlankLogger) Debug(args ...interface{})

func (*PlankLogger) Debugf

func (l *PlankLogger) Debugf(format string, args ...interface{})

func (*PlankLogger) Debugln

func (l *PlankLogger) Debugln(args ...interface{})

func (*PlankLogger) Error

func (l *PlankLogger) Error(args ...interface{})

func (*PlankLogger) Errorf

func (l *PlankLogger) Errorf(format string, args ...interface{})

func (*PlankLogger) Errorln

func (l *PlankLogger) Errorln(args ...interface{})

func (*PlankLogger) Info

func (l *PlankLogger) Info(args ...interface{})

func (*PlankLogger) Infof

func (l *PlankLogger) Infof(format string, args ...interface{})

func (*PlankLogger) Infoln

func (l *PlankLogger) Infoln(args ...interface{})

func (*PlankLogger) Panic

func (l *PlankLogger) Panic(args ...interface{})

func (*PlankLogger) Panicf

func (l *PlankLogger) Panicf(format string, args ...interface{})

func (*PlankLogger) Panicln

func (l *PlankLogger) Panicln(args ...interface{})

func (*PlankLogger) Trace

func (l *PlankLogger) Trace(args ...interface{})

func (*PlankLogger) Tracef

func (l *PlankLogger) Tracef(format string, args ...interface{})

func (*PlankLogger) Traceln

func (l *PlankLogger) Traceln(args ...interface{})

func (*PlankLogger) Warn

func (l *PlankLogger) Warn(args ...interface{})

func (*PlankLogger) Warnf

func (l *PlankLogger) Warnf(format string, args ...interface{})

func (*PlankLogger) Warnln

func (l *PlankLogger) Warnln(args ...interface{})

Jump to

Keyboard shortcuts

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