cfg

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cfg is used for defining configuration properties. It contains the options to use in Connector.DefineConfig

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(rule string, value string) (ok bool)

Validate validates that the value matches the rule. The rule itself is assumed to be valid.

Types

type Config

type Config struct {
	Name         string
	Description  string
	DefaultValue string
	Validation   string
	Secret       bool

	Value string
}

Config is a property used to configure a microservice. Although technically public, it is used internally and should not be constructed by microservices directly.

func NewConfig

func NewConfig(name string, options ...Option) (*Config, error)

NewConfig creates a new config property.

func (*Config) Apply

func (c *Config) Apply(options ...Option) error

Apply the provided options to the config.

type Option

type Option func(c *Config) error

Option is used to construct a request in Connector.Publish

func DefaultValue

func DefaultValue(defaultValue string) Option

DefaultValue sets the value to be used as default of the config property when no value is explicitly set. If validation is set, the default value must pass validation.

func Description

func Description(description string) Option

Description sets the description of the config property. The description is intended for humans and should explain the purpose of the config property and how it will impact the microservice.

func Secret

func Secret() Option

Secret indicates that the config property's value should be considered a secret.

func Validation

func Validation(validation string) Option

Validation sets the validation rule of the config property.

Valid rules are:

str ^[a-zA-Z0-9]+$
bool
int [0,60]
float [0.0,1.0)
dur (0s,24h]
set Red|Green|Blue
url
email
json

Whereas the following types are synonymous:

str, string, text, (empty)
bool, boolean
int, integer, long
float, double, decimal, number
dur, duration

Jump to

Keyboard shortcuts

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