app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cfg2Dot added in v0.0.5

func Cfg2Dot(cfg *Config, pkg string) *templates.Dot

Cfg2Dot converts the configuration into a templates.Dot for code generation.

Types

type Arg

type Arg struct {
	Name string
	Type string
}

Arg represents an argument in the log format string. An Arg is represented in YAML as a map with a single element.

func (*Arg) MarshalYAML

func (a *Arg) MarshalYAML() (any, error)

func (*Arg) UnmarshalYAML

func (a *Arg) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML custom unmarshals YAML node into Arg struct.

type Config

type Config struct {
	// Additional imports for the generated code.
	// For the main code `slog.Logger` is already included.
	// For test code `github.com/stretchr/testify/require`, `testing`, `bytes`, `errors`, and `slog.Logger` are already included.
	Imports []string `json:"import" yaml:"imports"`
	Events  map[string]struct {
		Type   YAMLEnum[LogType]  `json:"type" yaml:"type"`               // Event type (errorf, verbosef).
		Level  YAMLEnum[LogLevel] `json:"level" yaml:"level"`             // Log level (error, warn, info, debug).
		Nice   string             `json:"nice" yaml:"nice"`               // User-friendly message.
		Format string             `json:"format" yaml:"format"`           // Format string for identifying events.
		Args   []*Arg             `json:"args" yaml:"args"`               // Arguments for the format string.
		Custom bool               `json:"custom" yaml:"custom,omitempty"` // Flag for custom parsing.
	} `json:"events" yaml:"events"`
}

Config struct defines the main configuration for generating the code.

type Enum

type Enum interface{ Values() []string }

type LogLevel

type LogLevel string

LogLevel are the valid log levels available from [slog.Logger].

const (
	LogLevelError LogLevel = "error"
	LogLevelWarn  LogLevel = "warn"
	LogLevelInfo  LogLevel = "info"
	LogLevelDebug LogLevel = "debug"
)

func (LogLevel) Values

func (LogLevel) Values() []string

Values method returns all valid values for LogLevel.

type LogType

type LogType string

LogType are the valid log levels available from [device.Logger].

const (
	LogTypeErrorf   LogType = "errorf"
	LogTypeVerbosef LogType = "verbosef"
)

func (LogType) Values

func (LogType) Values() []string

Values method returns all valid values for LogType.

type YAMLEnum

type YAMLEnum[E Enum] string

YAMLEnum handles unmarshalling and validation of enums from yaml.

func (*YAMLEnum[E]) UnmarshalYAML

func (e *YAMLEnum[E]) UnmarshalYAML(n *yaml.Node) error

Jump to

Keyboard shortcuts

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