utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: BSD-2-Clause Imports: 6 Imported by: 2

Documentation

Overview

Package utils contains small helpers shared by Plank packages.

Index

Constants

This section is empty.

Variables

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. Possible values: stdout, stderr, null, or path to a file",
	},
	"AccessLog": {
		"FlagName":    "access-log",
		"ShortFlag":   "a",
		"Description": "HTTP server access log output. Possible values: stdout, stderr, null, or path to a file",
	},
	"ErrorLog": {
		"FlagName":    "error-log",
		"ShortFlag":   "e",
		"Description": "HTTP server error log output. Possible values: stdout, stderr, null, or path to a file",
	},
	"Debug": {
		"FlagName":    "debug",
		"ShortFlag":   "d",
		"Description": "Enable debug logging",
	},
	"NoBanner": {
		"FlagName":    "no-banner",
		"ShortFlag":   "b",
		"Description": "Do not print Plank banner at startup",
	},
	"RestBridgeTimeout": {
		"FlagName":    "rest-bridge-timeout",
		"Description": "Time in minutes before a REST endpoint for a service request to timeout",
	},
}

PlatformServerFlagConstants describes Plank CLI flags by config field name.

Functions

func ContainsString

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

ContainsString reports whether arr contains str.

func ConvertInterfaceToByteArray

func ConvertInterfaceToByteArray(mimeType string, i any) (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 DeriveStaticURIFromPath

func DeriveStaticURIFromPath(input string) (string, string)

DeriveStaticURIFromPath takes a string representing a file system path and its optional alias, and returns the path itself and the leaf segment of the path prepended with a forward slash if it does not exist. If the input is empty, just a forward slash will be returned. See the following examples:

1. folder => /folder 2. /folder => /folder 3. folder:my-folder => /my-folder 4. folder:/my-folder => /my-folder 5. nested/project => /project 6. nested/project:my-project => /my-project

func GetCallerStackFrame

func GetCallerStackFrame() runtime.Frame

GetCallerStackFrame returns the stack frame for its caller's caller.

func GetCurrentStackFrame

func GetCurrentStackFrame() runtime.Frame

GetCurrentStackFrame returns the stack frame for its caller.

func GetGoRoutineID

func GetGoRoutineID() string

GetGoRoutineID returns the current goroutine ID parsed from the runtime stack header.

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)

JoinBasePathIfRelativeRegularFilePath joins base to in unless in is absolute or a special stream name.

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

This section is empty.

Jump to

Keyboard shortcuts

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