Documentation ¶
Index ¶
- func AppVersion() string
- func BindEventSubscriber(injector *dingo.Injector) *dingo.Binding
- func BindTemplateFunc(injector *dingo.Injector, name string, fnc TemplateFunc)
- func LogFunc(l Logger, fields map[LogKey]any) func(f func(l Logger, args ...any), args ...any)
- func LogFuncWithContext(l Logger, fields map[LogKey]any) func(ctx context.Context, f func(l Logger, args ...any), args ...any)
- type DefaultEventRouter
- type Event
- type EventRouter
- type LogKey
- type Logger
- type NullLogger
- func (NullLogger) Debug(_ ...interface{})
- func (NullLogger) Debugf(_ string, _ ...interface{})
- func (NullLogger) Error(_ ...interface{})
- func (NullLogger) Fatal(_ ...interface{})
- func (n NullLogger) Flush()
- func (NullLogger) Info(_ ...interface{})
- func (NullLogger) Panic(_ ...interface{})
- func (NullLogger) Warn(_ ...interface{})
- func (n NullLogger) WithContext(_ context.Context) Logger
- func (n NullLogger) WithField(_ LogKey, _ interface{}) Logger
- func (n NullLogger) WithFields(_ map[LogKey]interface{}) Logger
- type PartialTemplateEngine
- type ServerShutdownEvent
- type ServerStartEvent
- type SessionModule
- type ShutdownEvent
- type StartupEvent
- type StdLogger
- func (l *StdLogger) Debug(args ...interface{})
- func (l *StdLogger) Debugf(f string, args ...interface{})
- func (l *StdLogger) Error(args ...interface{})
- func (l *StdLogger) Fatal(args ...interface{})
- func (l *StdLogger) Flush()
- func (l *StdLogger) Info(args ...interface{})
- func (l *StdLogger) Panic(args ...interface{})
- func (l *StdLogger) Warn(args ...interface{})
- func (l *StdLogger) WithContext(_ context.Context) Logger
- func (l *StdLogger) WithField(key LogKey, value interface{}) Logger
- func (l *StdLogger) WithFields(fields map[LogKey]interface{}) Logger
- type TemplateEngine
- type TemplateFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppVersion ¶ added in v3.2.1
func AppVersion() string
AppVersion returns the application version set this during build with `go build -ldflags "-X flamingo.me/flamingo/v3/framework/flamingo.appVersion=1.2.3"`.
func BindEventSubscriber ¶
BindEventSubscriber is a helper to bind a private event Subscriber via Dingo
func BindTemplateFunc ¶
func BindTemplateFunc(injector *dingo.Injector, name string, fnc TemplateFunc)
BindTemplateFunc makes sure a template function is correctly bound via dingo
func LogFunc ¶ added in v3.7.0
Example ¶
package main import ( "fmt" "io" "log" "strings" "flamingo.me/flamingo/v3/framework/flamingo" ) func createLogger(recorder io.Writer) flamingo.Logger { var l = new(flamingo.StdLogger) l.Logger = *log.New(recorder, "TEST--", 0) return l } func main() { recorder := &strings.Builder{} // the flamingo.Logger is normally obtained via injection logger := createLogger(recorder) // we can create a log function which we use later to log messages with the fields we define here logFunc := flamingo.LogFunc(logger, map[flamingo.LogKey]any{ flamingo.LogKeyBusinessID: "example", flamingo.LogKeyCategory: "test", }) // the wanted log level is defined by passing the corresponding method from the flamingo.Logger interface logFunc(flamingo.Logger.Info, "my", "log", "args") logFunc(flamingo.Logger.Warn, "my", "log", "args") logFunc(flamingo.Logger.Debug, "my", "log", "args") // if we do not give the level, it will be Info logFunc(nil, "my", "log", "args") fmt.Println(recorder.String()) }
Output: TEST--WithFields map[businessId:example category:test] TEST--info: mylogargs TEST--WithFields map[businessId:example category:test] TEST--warn: mylogargs TEST--WithFields map[businessId:example category:test] TEST--debug: mylogargs TEST--WithFields map[businessId:example category:test] TEST--info: mylogargs
func LogFuncWithContext ¶ added in v3.7.0
func LogFuncWithContext(l Logger, fields map[LogKey]any) func(ctx context.Context, f func(l Logger, args ...any), args ...any)
Example ¶
package main import ( "context" "fmt" "io" "log" "strings" "flamingo.me/flamingo/v3/framework/flamingo" ) func createLogger(recorder io.Writer) flamingo.Logger { var l = new(flamingo.StdLogger) l.Logger = *log.New(recorder, "TEST--", 0) return l } func main() { recorder := &strings.Builder{} // the flamingo.Logger is normally obtained via injection logger := createLogger(recorder) // we can create a log function which we use later to log messages with the fields we define here // the log function will expect a context on each call logFunc := flamingo.LogFuncWithContext(logger, map[flamingo.LogKey]any{ flamingo.LogKeyBusinessID: "example", }) ctx := context.Background() // the current context is the first argument. It is up to the logger implementation what to do with it // the standard flamingo zap.Logger can add the session hash aon tracing information as fields // the StdLogger we use here, does nothing with the context // the wanted log level is defined by passing the corresponding method from the flamingo.Logger interface logFunc(ctx, flamingo.Logger.Info, "my", "log", "args") logFunc(ctx, flamingo.Logger.Warn, "my", "log", "args") logFunc(ctx, flamingo.Logger.Debug, "my", "log", "args") // if we do not give the level, it will be Info logFunc(ctx, nil, "my", "log", "args") fmt.Println(recorder.String()) }
Output: TEST--WithFields map[businessId:example] TEST--info: mylogargs TEST--WithFields map[businessId:example] TEST--warn: mylogargs TEST--WithFields map[businessId:example] TEST--debug: mylogargs TEST--WithFields map[businessId:example] TEST--info: mylogargs
Types ¶
type DefaultEventRouter ¶
type DefaultEventRouter struct {
// contains filtered or unexported fields
}
DefaultEventRouter is a default event routing implementation
func (*DefaultEventRouter) Dispatch ¶
func (d *DefaultEventRouter) Dispatch(ctx context.Context, event Event)
Dispatch calls the event's Dispatch method on each subscriber
func (*DefaultEventRouter) Inject ¶
func (d *DefaultEventRouter) Inject(provider eventSubscriberProvider, logger Logger)
Inject eventSubscriberProvider dependency
type EventRouter ¶
EventRouter routes events
type LogKey ¶
type LogKey string
LogKey is a logging key constant
const ( LogKeyAccesslog LogKey = "accesslog" // LogKeyAccesslog marks a logmessage belonging to an (incoming) call (value should be 1) LogKeyApicall LogKey = "apicall" // LogKeyApicall marks a logmessage belonging to an (outgoing) api call (value should be 1) LogKeyArea LogKey = "area" LogKeyBusinessID LogKey = "businessId" LogKeyCategory LogKey = "category" LogKeyModule LogKey = "module" LogKeySubCategory LogKey = "sub_category" LogKeyClientIP LogKey = "client_ip" LogKeyCode LogKey = "code" LogKeyConnectionStatus LogKey = "connection_status" LogKeyCorrelationID LogKey = "correlationId" LogKeyTraceID LogKey = "traceID" LogKeySpanID LogKey = "spanID" LogKeyLevel LogKey = "level" LogKeyMessage LogKey = "message" LogKeyMethod LogKey = "method" LogKeySession LogKey = "session" LogKeyPath LogKey = "path" LogKeyReferer LogKey = "referer" LogKeyRequest LogKey = "request" LogKeyRequestTime LogKey = "request_time" LogKeyRequestedEndpoint LogKey = "requested_endpoint" LogKeyRequestedURL LogKey = "requested_url" LogKeyResponse LogKey = "response" LogKeyResponseCode LogKey = "response_code" LogKeyResponseTime LogKey = "response_time" LogKeySource LogKey = "source" LogKeyTimestamp LogKey = "@timestamp" LogKeyTrace LogKey = "trace" )
Common logger field keys
type Logger ¶
type Logger interface { WithContext(ctx context.Context) Logger Debug(args ...interface{}) Info(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Debugf(log string, args ...interface{}) WithField(key LogKey, value interface{}) Logger WithFields(fields map[LogKey]interface{}) Logger Flush() }
Logger defines a standard Flamingo logger interfaces
Example ¶
In this example we see the normal usecase of a logger
package main import ( "context" "fmt" "io" "log" "strings" "flamingo.me/flamingo/v3/framework/flamingo" ) func createLogger(recorder io.Writer) flamingo.Logger { var l = new(flamingo.StdLogger) l.Logger = *log.New(recorder, "TEST--", 0) return l } func main() { recorder := &strings.Builder{} // the flamingo.Logger is normally obtained via injection logger := createLogger(recorder) // create a new child logger witch additional fields logger = logger.WithFields(map[flamingo.LogKey]any{ flamingo.LogKeyBusinessID: "example", flamingo.LogKeyCategory: "test", }) // we can also add single fields logger = logger.WithField(flamingo.LogKeySubCategory, "another field") // we can add the current context. It is up to the logger implementation what to do with it // the standard flamingo zap.Logger can add the session hash aon tracing information as fields // the StdLogger we use here, does nothing with the context logger = logger.WithContext(context.Background()) // log some messages in different levels logger.Info("my", "log", "args") logger.Warn("my", "log", "args") logger.Debug("my", "log", "args") fmt.Println(recorder.String()) }
Output: TEST--WithFields map[businessId:example category:test] TEST--WithField sub_category another field TEST--info: mylogargs TEST--warn: mylogargs TEST--debug: mylogargs
type NullLogger ¶
type NullLogger struct{}
NullLogger does not log
func (NullLogger) Debugf ¶
func (NullLogger) Debugf(_ string, _ ...interface{})
Debugf null-implementation
func (NullLogger) WithContext ¶
func (n NullLogger) WithContext(_ context.Context) Logger
WithContext null-implementation
func (NullLogger) WithField ¶
func (n NullLogger) WithField(_ LogKey, _ interface{}) Logger
WithField null-implementation
func (NullLogger) WithFields ¶
func (n NullLogger) WithFields(_ map[LogKey]interface{}) Logger
WithFields null-implementation
type PartialTemplateEngine ¶
type PartialTemplateEngine interface {
RenderPartials(ctx context.Context, templateName string, data interface{}, partials []string) (map[string]io.Reader, error)
}
PartialTemplateEngine is used for progressive enhancements / rendering of partial template areas usually this is requested via the appropriate javascript headers and taken care of in the framework renderer
type ServerShutdownEvent ¶
type ServerShutdownEvent struct{}
ServerShutdownEvent is dispatched when a server is stopped (not for CLI commands)
type ServerStartEvent ¶
type ServerStartEvent struct {
Port string
}
ServerStartEvent is dispatched when a server is started (not for CLI commands)
type SessionModule ¶
type SessionModule struct {
// contains filtered or unexported fields
}
SessionModule for session management
func (*SessionModule) Configure ¶
func (m *SessionModule) Configure(injector *dingo.Injector)
Configure DI
func (*SessionModule) CueConfig ¶ added in v3.1.0
func (*SessionModule) CueConfig() string
CueConfig defines the session config scheme
func (*SessionModule) FlamingoLegacyConfigAlias ¶ added in v3.1.0
func (m *SessionModule) FlamingoLegacyConfigAlias() map[string]string
FlamingoLegacyConfigAlias maps legacy config to new
func (*SessionModule) Inject ¶
func (m *SessionModule) Inject(config *struct { // session config is optional to allow usage of the DefaultConfig Backend string `inject:"config:flamingo.session.backend"` Secret string `inject:"config:flamingo.session.secret"` FileName string `inject:"config:flamingo.session.file"` Secure bool `inject:"config:flamingo.session.cookie.secure"` SameSite string `inject:"config:flamingo.session.cookie.sameSite"` // float64 is used due to the injection as config from json - int is not possible on this StoreLength float64 `inject:"config:flamingo.session.store.length"` MaxAge float64 `inject:"config:flamingo.session.max.age"` Path string `inject:"config:flamingo.session.cookie.path"` RedisURL string `inject:"config:flamingo.session.redis.url"` RedisHost string `inject:"config:flamingo.session.redis.host"` RedisPassword string `inject:"config:flamingo.session.redis.password"` RedisIdleConnections float64 `inject:"config:flamingo.session.redis.idle.connections"` RedisDatabase int `inject:"config:flamingo.session.redis.database,optional"` RedisTLS bool `inject:"config:flamingo.session.redis.tls,optional"` RedisClusterMode bool `inject:"config:flamingo.session.redis.clusterMode,optional"` RedisTimeout string `inject:"config:flamingo.session.redis.timeout,optional"` CheckSession bool `inject:"config:flamingo.session.healthcheck,optional"` })
Inject dependencies
type ShutdownEvent ¶
type ShutdownEvent struct{}
ShutdownEvent is dispatched when the application shuts down
type StartupEvent ¶
type StartupEvent struct{}
StartupEvent is dispatched when the application starts
type StdLogger ¶
StdLogger uses the go stdlib logger for logging
func (*StdLogger) WithContext ¶
WithContext currently does nothing
func (*StdLogger) WithFields ¶
WithFields currently logs the fields
type TemplateEngine ¶
type TemplateEngine interface {
Render(context context.Context, name string, data interface{}) (io.Reader, error)
}
TemplateEngine defines the basic template engine
type TemplateFunc ¶
TemplateFunc defines an interface for a custom function to be used in gotemplates/pug templates