shared

package
v0.0.0-...-4d495be Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const APIInsightsTraceID = "api_insights_trace_id"
View Source
const (
	EnvCorsWhiteListFilePath = "CORS_WHITELIST_FILEPATH"
)

Variables

View Source
var (
	CorsHandlerEnabled = GetBoolFromEnv("SHARED_CORS_ENABLED", false)
)
View Source
var LogOpt = LogOption{LogFormat: "json", LogLevel: "info", LogName: ""}

LogOpt is global logging configuration instance

View Source
var (
	// UUIDRegex describes the form of a valid UUID
	UUIDRegex = regexp.MustCompile("(?i)[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}")
)

Functions

func GetBoolFromEnv

func GetBoolFromEnv(key string, defaultValue bool) bool

func GetCORSWhitelist

func GetCORSWhitelist() []string

func GetStringFromEnv

func GetStringFromEnv(key string, defaultValue string) string

func HTTPApp

func HTTPApp(config *AppConfig, customFlags []cli.Flag, commands ...*cli.Command) *cli.App

func InitTracer

func InitTracer(service string) (opentracing.Tracer, io.Closer, error)

InitTracer returns an instance of Jaeger Tracer that samples 100% of traces and logs all spans to stdout.

func IsUUID

func IsUUID(s string) bool

func LogDebugf

func LogDebugf(format string, v ...interface{})

LogDebugf logs message in debug level

func LogErrorf

func LogErrorf(format string, v ...interface{})

LogErrorf logs message in error level

func LogFatalf

func LogFatalf(format string, v ...interface{})

LogFatalf logs message in fatal level

func LogInfof

func LogInfof(format string, v ...interface{})

LogInfof logs message in info level

func LogPrintf

func LogPrintf(format string, v ...interface{})

LogPrintf logs message in error level

func LogWarnf

func LogWarnf(format string, v ...interface{})

LogWarnf logs message in warn level

func MergeFlags

func MergeFlags(flagGroups ...[]cli.Flag) []cli.Flag

func NewHeader

func NewHeader(description string) restful.Header

func RouteAuthHeader

func RouteAuthHeader(ws *restful.WebService) func(*restful.RouteBuilder)

func RouteParams

func RouteParams(params ...*restful.Parameter) func(*restful.RouteBuilder)

func RouteReads

func RouteReads(sample interface{}, description ...string) func(*restful.RouteBuilder)

func RouteReturns

func RouteReturns(sample interface{}, responseCodes ...int) func(*restful.RouteBuilder)

func RouteWrites

func RouteWrites(sample interface{}) func(*restful.RouteBuilder)

func ServeCommand

func ServeCommand(config *AppConfig, customFlags []cli.Flag, commands ...*cli.Command) *cli.Command

func ServeJSON

func ServeJSON(rw http.ResponseWriter, httpStatus int, data interface{}) error

func StartSpan

func StartSpan(context context.Context, variables ...string) (opentracing.Span, context.Context)

func TimeUUID

func TimeUUID() string

Types

type AppConfig

type AppConfig struct {
	// AppVersion is the version of the microservice.
	AppVersion string `json:"appVersion"`

	// AppName is the name of the microservice.
	AppName string `json:"appName"`

	// AppPort the port for the App microservice web server to listen on.
	AppPort int `json:"appPort"`

	// AppHost is the host name for the App microservice.  This is used
	// for the OAuth callback url.
	AppHost string `json:"appHost"`

	// AppEnvironment signals the environment this config is intended
	// to be. Possible values include 'production', 'development', etc.
	AppEnvironment Environment `json:"appEnvironment"`

	// ConfigDir is the directory to search for configuration JSON files. Defaults to working directory
	ConfigDir string `json:"configDir"`

	// HTTPHandler is the func that registers the microservice and
	// returns the restful.Container.
	HTTPHandler func(*AppConfig) (*restful.Container, error) `json:"-"`
}

func (*AppConfig) Env

func (c *AppConfig) Env(suffix string) string

func (*AppConfig) LoadConfigFile

func (c *AppConfig) LoadConfigFile(relPath string) ([]byte, error)

func (*AppConfig) LoadConfigJSON

func (c *AppConfig) LoadConfigJSON(relPath string, dest interface{}) error

func (*AppConfig) String

func (c *AppConfig) String() string

type Environment

type Environment string
const (
	EnvTest        Environment = "test"
	EnvDevelopment Environment = "development"
	EnvIntegration Environment = "integration"
	EnvStaging     Environment = "staging"
	EnvProduction  Environment = "production"
)

type LogOption

type LogOption struct {
	LogFormat string `long:"log-format"  description:"Log Format - text or json" default:"json" env:"LOG_FORMAT"`
	LogLevel  string `long:"log-level"   description:"Log Level - debug, info, warn, error, or fatal" default:"info" env:"LOG_LEVEL"`
	LogName   string `long:"log-name"    description:"Log Name - log name" env:"LOG_NAME"`
}

LogOption defines the cli options for service

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
	WithField(key string, value interface{}) Logger
	SetLevel(level string) error
	GetLevel() log.Level
}

Logger defines a generic logging interface

func GlobalLogger

func GlobalLogger() Logger

GlobalLogger will return a global logger

func LoggerFromContext

func LoggerFromContext(ctx context.Context) Logger

LoggerFromContext will return a Logger instance from context object

func LoggerFromRequest

func LoggerFromRequest(r *http.Request) Logger

LoggerFromRequest will return a Logger instance from request object

func NewLogger

func NewLogger(additionalFields log.Fields) Logger

NewLogger will create a new Logger instance

func NewLoggerWithSkip

func NewLoggerWithSkip(additionalFields log.Fields, skip int) Logger

NewLoggerWithSkip will create a new Logger instance

Jump to

Keyboard shortcuts

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