config

package
v0.0.0-...-23fd19e Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config contains the configuration data structs and flag types used in the command line tool.

Index

Constants

This section is empty.

Variables

View Source
var LogFormatDefault = LogFormatPretty

LogFormatDefault is the default log format. Used in the LogFormat.JSONSchema method.

View Source
var LogLevelDefault = LogLevel(zerolog.WarnLevel)

LogLevelDefault is the default log format. Used in the LogLevel.JSONSchema method.

View Source
var OutFormatDefault = OutFormatPretty

OutFormatDefault is the default log format. Used in the OutFormat.JSONSchema method.

Functions

func Schema

func Schema(sourceDir string) *jsonschema.Schema

Schema returns the JSON schema for the Config struct.

Supports optionally supplying the source directory path, which can point to the Go module directory, and will then use the comments from the source code as descriptions in the resulting schema.

Types

type Auth

type Auth struct {
	// Email is your account's login email address.
	Email string `jsonschema:"oneof_type=string;null" jsonschema_extras:"format=email"`
	// Password is your account's login password.
	Password string `jsonschema:"oneof_type=string;null"`

	// CSRFToken is provided by this program when it fails to
	// log in due to them detecting login via new device. You then need to
	// run the program again but with the CSRF (Cross-Site-Request-Forgery)
	// token and email token.
	CSRFToken string `yaml:"csrfToken,omitempty" jsonschema:"oneof_type=string;null"`
	// EmailToken is sent by Personio to your email when it fails to
	// log in due to them detecting login via new device. You then need to
	// run the program again but with the CSRF (Cross-Site-Request-Forgery)
	// token and email token.
	EmailToken string `yaml:"emailToken,omitempty" jsonschema:"oneof_type=string;null"`
}

Auth contains configs for how the program should authenticate with Personio.

type Config

type Config struct {
	// BaseURL is the URL to your Personio instance.
	// This can be with or without the trailing slash.
	//
	// The program with later append paths like /login/index
	// and /api/v1/attendances/periods when invoking its HTTP
	// requests.
	//
	// Any query parameters and fragments will get removed.
	BaseURL string `yaml:"baseUrl" jsonschema:"oneof_type=string;null" jsonschema_extras:"format=uri"`
	Auth    Auth

	// MinimumPeriodDuration is the duration for which attendance periods that
	// are shorter than will get skipped when creating or updating attendance.
	//
	// The value is a Go duration, which allows values like:
	// - 30s
	// - 12m30s
	// - 2h12m30s
	MinimumPeriodDuration time.Duration `yaml:"minimumPeriodDuration" jsonschema:"type=string"`

	// Output is the format of the command line results.
	// This controls the format of the single command line
	// result output written to STDOUT.
	Output OutFormat
	Log    Log
}

Config is the full configuration file.

type Log

type Log struct {
	// Format is the way the program formats its logging line. The
	// "pretty" option is meant for humans and is colored, while the
	// "json" option is meant for easier parsing in logging management
	// systems like for example Kibana or Splunk.
	Format LogFormat
	// Level is the severity level to filter logs on, where "trace"
	// is the lowest logging/severity level, and "panic" is the
	// highest. The program will only log messages that are equal
	// severity or higher than this value. You can also set this
	// to "disabled" to turn of logging.
	Level LogLevel
}

Log contains configs for the command line logging, which compared to the command line output, loggin is written to STDERR and contains small status reports, and is mostly used for debugging.

type LogFormat

type LogFormat string

LogFormat is an enum of different log formats.

const (
	LogFormatPretty LogFormat = "pretty"
	LogFormatJSON   LogFormat = "json"
)

Available LogFormat values.

func (LogFormat) JSONSchema

func (LogFormat) JSONSchema() *jsonschema.Schema

JSONSchema returns the custom JSON schema definition for this type.

func (*LogFormat) Set

func (f *LogFormat) Set(value string) error

Set implements pflag.Value.

Used by cobra when setting the new value for a flag.

func (LogFormat) String

func (f LogFormat) String() string

String implements fmt.Stringer and pflag.Value.

Used by cobra when showing the default value of a flag.

func (*LogFormat) Type

func (f *LogFormat) Type() string

Type implements pflag.Value.

Used by cobra when rendering the list of flags and their types.

func (*LogFormat) UnmarshalText

func (f *LogFormat) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Used when parsing YAML config files.

type LogLevel

type LogLevel zerolog.Level

LogLevel is an enum of different log levels / severities.

This is just a wrapper around the zerolog.Level type, where all the different enum values are defined.

func (LogLevel) JSONSchema

func (LogLevel) JSONSchema() *jsonschema.Schema

JSONSchema returns the custom JSON schema definition for this type.

func (LogLevel) MarshalText

func (l LogLevel) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

Used when printing YAML config files.

func (*LogLevel) Set

func (l *LogLevel) Set(value string) error

Set implements pflag.Value.

Used by cobra when setting the new value for a flag.

func (LogLevel) String

func (l LogLevel) String() string

String implements fmt.Stringer and pflag.Value.

Used by cobra when showing the default value of a flag.

func (*LogLevel) Type

func (l *LogLevel) Type() string

Type implements pflag.Value.

Used by cobra when rendering the list of flags and their types.

func (*LogLevel) UnmarshalText

func (l *LogLevel) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Used when parsing YAML config files.

type OutFormat

type OutFormat string

OutFormat is an enum of different output formats.

const (
	OutFormatPretty OutFormat = "pretty"
	OutFormatJSON   OutFormat = "json"
	OutFormatYAML   OutFormat = "yaml"
)

Available OutFormat values.

func (OutFormat) JSONSchema

func (OutFormat) JSONSchema() *jsonschema.Schema

JSONSchema returns the custom JSON schema definition for this type.

func (*OutFormat) Set

func (f *OutFormat) Set(value string) error

Set implements pflag.Value.

Used by cobra when setting the new value for a flag.

func (OutFormat) String

func (f OutFormat) String() string

String implements fmt.Stringer and pflag.Value.

Used by cobra when showing the default value of a flag.

func (*OutFormat) Type

func (f *OutFormat) Type() string

Type implements pflag.Value.

Used by cobra when rendering the list of flags and their types.

func (*OutFormat) UnmarshalText

func (f *OutFormat) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Used when parsing YAML config files.

Jump to

Keyboard shortcuts

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