context

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 30 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DateLayout     = "Jan 02, 2006"
	TimeLayout     = "15:04 -0700"
	DateTimeLayout = "2006-01-02 15:04 MST"
)
View Source
var (
	DefaultParsers = Parsers{
		"bool":            BoolParser,
		"html":            HtmlParser,
		"string":          StringParser,
		"string-map":      StringMapParser,
		"string-option":   StringOptionParser,
		"number":          NumberParser,
		"number-percent":  NumberPercentParser,
		"decimal":         DecimalParser,
		"decimal-percent": DecimalPercentParser,
		"email":           EmailParser,
		"path":            PathParser,
		"url":             UrlParser,
		"relative-url":    RelativeUrlParser,
		"time":            TimeParser,
		"date":            DateParser,
		"date-time":       DateTimeParser,
		"time-struct":     TimeStructParser,
		"language":        LanguageParser,
		"language-tag":    LanguageTagParser,
		"kebab":           KebabParser,
		"kebab-option":    KebabOptionParser,
		"uuid":            UuidParser,
	}
)

Functions

func AddDateTimeFormat added in v0.5.0

func AddDateTimeFormat(format string)

func BoolParser added in v0.5.0

func BoolParser(spec *Field, input interface{}) (parsed interface{}, err error)

func DateParser added in v0.5.0

func DateParser(spec *Field, input interface{}) (parsed interface{}, err error)

func DateTimeParser added in v0.5.0

func DateTimeParser(spec *Field, input interface{}) (parsed interface{}, err error)

func DecimalParser added in v0.5.0

func DecimalParser(spec *Field, input interface{}) (parsed interface{}, err error)

func DecimalPercentParser added in v0.5.0

func DecimalPercentParser(spec *Field, input interface{}) (parsed interface{}, err error)

func DeleteKV added in v0.4.0

func DeleteKV(c map[string]interface{}, key string) (deleted bool)

DeleteKV deletes the key allowing for .Deep.Variable.Names

func EmailParser added in v0.5.0

func EmailParser(spec *Field, input interface{}) (parsed interface{}, err error)

func GetKV added in v0.4.0

func GetKV(c map[string]interface{}, key string) (k string, v interface{})

GetKV looks for the key as given first and if not found looks for CamelCased, kebab-case and snake_cased variations; returning the actual key found and the generic value; returns an empty key and nil value if nothing found at all

func HtmlParser added in v0.5.0

func HtmlParser(spec *Field, input interface{}) (parsed interface{}, err error)

func KebabOptionParser added in v0.5.0

func KebabOptionParser(spec *Field, input interface{}) (parsed interface{}, err error)

func KebabParser added in v0.5.0

func KebabParser(spec *Field, input interface{}) (parsed interface{}, err error)

func LanguageParser added in v0.5.0

func LanguageParser(spec *Field, input interface{}) (parsed interface{}, err error)

func LanguageTagParser added in v0.5.0

func LanguageTagParser(spec *Field, input interface{}) (parsed interface{}, err error)

func NumberParser added in v0.5.0

func NumberParser(spec *Field, input interface{}) (parsed interface{}, err error)

func NumberPercentParser added in v0.5.0

func NumberPercentParser(spec *Field, input interface{}) (parsed interface{}, err error)

func ParseTimeStructure added in v0.5.0

func ParseTimeStructure(input string) (parsed time.Time, err error)

func PathParser added in v0.5.0

func PathParser(spec *Field, input interface{}) (parsed interface{}, err error)

func RelativeUrlParser added in v0.5.0

func RelativeUrlParser(spec *Field, input interface{}) (parsed interface{}, err error)

func SetKV added in v0.4.0

func SetKV(c map[string]interface{}, key string, value interface{}) (err error)

SetKV allows for .Deep.Variable.Names

func StringMapParser added in v0.5.0

func StringMapParser(spec *Field, input interface{}) (parsed interface{}, err error)

func StringOptionParser added in v0.5.0

func StringOptionParser(spec *Field, input interface{}) (parsed interface{}, err error)

func StringParser added in v0.5.0

func StringParser(spec *Field, input interface{}) (parsed interface{}, err error)

func TimeParser added in v0.5.0

func TimeParser(spec *Field, input interface{}) (parsed interface{}, err error)

func TimeStructParser added in v0.5.0

func TimeStructParser(spec *Field, input interface{}) (parsed interface{}, err error)

func ToKebab added in v0.5.0

func ToKebab(input string) (kebab string)

func UrlParser added in v0.5.0

func UrlParser(spec *Field, input interface{}) (parsed interface{}, err error)

func UuidParser added in v0.5.0

func UuidParser(spec *Field, input interface{}) (parsed interface{}, err error)

Types

type Context

type Context map[string]interface{}

Context is a wrapper around a map[string]interface{} structure which is used throughout Go-Enjin for parsing configurations and contents.

func New

func New() (ctx Context)

New constructs a new Context instance

func NewFromMap

func NewFromMap(m map[string]interface{}) Context

NewFromMap casts an existing map[string]interface{} as a Context

func NewFromOsEnviron

func NewFromOsEnviron(slices ...[]string) (c Context)

NewFromOsEnviron constructs a new Context from os.Environ() string K=V slices

func ParseJson added in v0.4.0

func ParseJson(content string) (m Context, err error)

func ParseToml added in v0.4.0

func ParseToml(content string) (m Context, err error)

func ParseYaml added in v0.4.0

func ParseYaml(content string) (m Context, err error)

func (Context) Apply

func (c Context) Apply(contexts ...Context)

Apply takes a list of contexts and merges their contents into this one

func (Context) ApplySpecific added in v0.2.2

func (c Context) ApplySpecific(contexts ...Context)

ApplySpecific takes a list of contexts and merges their contents into this one, keeping the keys specifically

func (Context) AsDeepKeyed added in v0.5.0

func (c Context) AsDeepKeyed() (ctx Context)

AsDeepKeyed returns a deep-key flattened version of this context For example:

map[string]interface{}{"one": map[string]interface{}{"two": "deep"}}

becomes:

map[string]interface{}{".one.two": "deep"}

func (Context) AsJSON added in v0.1.0

func (c Context) AsJSON() (data []byte, err error)

func (Context) AsMap

func (c Context) AsMap() (out map[string]interface{})

AsMap returns this Context, shallowly copied, as a new map[string]interface{} instance.

func (Context) AsMapStrings

func (c Context) AsMapStrings() (out map[string]string)

AsMapStrings returns this Context as a transformed map[string]string structure, where each key's value is checked and if it's a string, use it as-is and if it's anything else, run it through fmt.Sprintf("%v") to make it a string.

func (Context) AsOsEnviron

func (c Context) AsOsEnviron() (out []string)

AsOsEnviron returns this Context as a transformed []string slice where each key is converted to SCREAMING_SNAKE_CASE and the value is converted to a string (similarly to AsMapStrings) and the key/value pair is concatenated into a single "K=V" string and appended to the output slice, sorted by key in natural order, suitable for use in os.Environ cases.

func (Context) AsTOML added in v0.1.0

func (c Context) AsTOML() (data []byte, err error)

func (Context) AsYAML added in v0.1.0

func (c Context) AsYAML() (data []byte, err error)

func (Context) Bool

func (c Context) Bool(key string, def bool) bool

func (Context) Boolean added in v0.5.0

func (c Context) Boolean(key string) (value, ok bool)

func (Context) Bytes added in v0.5.0

func (c Context) Bytes(key string, def []byte) []byte

Bytes returns the key's value as a byte slice, returning the given default if not found or not actually a byte slice value.

func (Context) CamelizeKeys

func (c Context) CamelizeKeys()

CamelizeKeys transforms all keys within the Context to be of CamelCased form

func (Context) Context added in v0.5.0

func (c Context) Context(key string) (ctx Context)

Context looks for the given key and if the value is of Context type, returns it

func (Context) Copy

func (c Context) Copy() (ctx Context)

Copy makes a deep-copy of this Context

func (Context) DeepKeys added in v0.5.0

func (c Context) DeepKeys() (keys []string)

DeepKeys returns a list of .deep.keys for the entire context structure

func (Context) DefaultStrings

func (c Context) DefaultStrings(key string, def []string) []string

DefaultStrings is a wrapper around Strings() and returns the given default list of strings if the key is not found

func (Context) Delete

func (c Context) Delete(key string) (deleted bool)

Delete deletes the given key from the Context and follows a similar key lookup process to Get() for finding the key to delete and will only delete the first matching key format (specific, Camel, kebab) found

func (Context) DeleteKeys

func (c Context) DeleteKeys(keys ...string)

DeleteKeys is a batch wrapper around Delete()

func (Context) Duration added in v0.5.11

func (c Context) Duration(key string, def time.Duration) time.Duration

func (Context) Empty added in v0.5.0

func (c Context) Empty() (empty bool)

Empty returns true if there is nothing stored in the Context

func (Context) FirstString added in v0.5.0

func (c Context) FirstString(key string) (value string, ok bool)

func (Context) Float64

func (c Context) Float64(key string, def float64) float64

func (Context) Get

func (c Context) Get(key string) (value interface{})

Get is a convenience wrapper around GetKV

func (Context) GetKV added in v0.2.2

func (c Context) GetKV(key string) (k string, v interface{})

GetKV looks for the key as given first and if not found looks for CamelCased, kebab-case and snake_cased variations; returning the actual key found and the generic value; returns an empty key and nil value if nothing found at all

func (Context) Has

func (c Context) Has(key string) (present bool)

Has returns true if the given Context key exists and is not nil

func (Context) HasExact added in v0.5.0

func (c Context) HasExact(key string) (present bool)

HasExact returns true if the specific Context key given exists and is not nil

func (Context) Int

func (c Context) Int(key string, def int) int

func (Context) Int64

func (c Context) Int64(key string, def int64) int64

func (Context) KebabKeys added in v0.4.0

func (c Context) KebabKeys()

KebabKeys transforms all keys within the Context to be of kebab-cased form

func (Context) Keys

func (c Context) Keys() (keys []string)

Keys returns a list of all the map keys in the Context, sorted in natural order for consistency

func (Context) Len added in v0.5.0

func (c Context) Len() (count int)

Len returns the number of keys in the Context

func (Context) LowerCamelizeKeys added in v0.2.2

func (c Context) LowerCamelizeKeys()

LowerCamelizeKeys transforms all keys within the Context to be of lowerCamelCased form

func (Context) PruneEmpty added in v0.5.0

func (c Context) PruneEmpty() (pruned Context)

func (Context) Select

func (c Context) Select(keys ...string) (selected map[string]interface{})

func (Context) Set

func (c Context) Set(key string, value interface{}) Context

Set CamelCases the given key and sets that within this Context

func (Context) SetKV added in v0.4.0

func (c Context) SetKV(key string, value interface{}) (err error)

SetKV allows for .Deep.Variable.Names

func (Context) SetSpecific

func (c Context) SetSpecific(key string, value interface{}) Context

SetSpecific is like Set(), without CamelCasing the key

func (Context) Slice added in v0.5.1

func (c Context) Slice(key string) (list []interface{}, ok bool)

func (Context) String

func (c Context) String(key, def string) string

String returns the key's value as a string, returning the given default if not found or not actually a string value.

func (Context) StringOrStrings

func (c Context) StringOrStrings(key string) (values []string)

StringOrStrings returns the key's value as a list of strings and if the key's actual value is not a list of strings, return that as a list of one string

func (Context) Strings

func (c Context) Strings(key string) (values []string)

Strings returns the key's value as a list of strings, returning an empty list if not found or not actually a list of strings

func (Context) Time added in v0.5.11

func (c Context) Time(key string, def time.Time) time.Time

func (Context) Uint

func (c Context) Uint(key string, def uint) uint

func (Context) Uint64

func (c Context) Uint64(key string, def uint64) uint64

func (Context) ValueAsInt

func (c Context) ValueAsInt(key string, def int) int

type Field added in v0.5.0

type Field struct {
	Key      string `json:"key"`
	Tab      string `json:"tab"`
	Label    string `json:"label"`
	Format   string `json:"format"`
	Category string `json:"category"`

	Input    string `json:"input"`
	Weight   int    `json:"weight"`
	Required bool   `json:"required,omitempty"`

	Step         float64           `json:"step"`
	Minimum      float64           `json:"minimum"`
	Maximum      float64           `json:"maximum"`
	Placeholder  string            `json:"placeholder"`
	DefaultValue interface{}       `json:"default-value"`
	ValueLabels  map[string]string `json:"value-labels"`
	ValueOptions []string          `json:"value-options"`

	LockNonEmpty bool `json:"lock-non-empty"`
	NoResetValue bool `json:"no-reset-value"`

	Printer *message.Printer `json:"-"`
	Parse   Parser           `json:"-"`
}

func ParseField added in v0.5.0

func ParseField(data map[string]interface{}) (field *Field)

func (*Field) Copy added in v0.5.1

func (f *Field) Copy() (copied *Field)

type Fields added in v0.5.0

type Fields map[string]*Field

func (Fields) CategoryNames added in v0.5.0

func (f Fields) CategoryNames() (names []string)

func (Fields) Copy added in v0.5.1

func (f Fields) Copy() (copied Fields)

func (Fields) Init added in v0.5.0

func (f Fields) Init(printer *message.Printer, parsers Parsers)

func (Fields) Keys added in v0.5.0

func (f Fields) Keys() (keys []string)

func (Fields) Len added in v0.5.0

func (f Fields) Len() (count int)

func (Fields) Lookup added in v0.5.0

func (f Fields) Lookup(key string) (field *Field, ok bool)

func (Fields) SortedKeys added in v0.5.0

func (f Fields) SortedKeys() (keys []string)

func (Fields) TabCategoryFields added in v0.5.0

func (f Fields) TabCategoryFields(tab, category string, ignored ...string) (fields Fields)

func (Fields) TabCategoryNames added in v0.5.0

func (f Fields) TabCategoryNames(tab string) (keys []string)

func (Fields) TabFields added in v0.5.0

func (f Fields) TabFields(tab string) (fields Fields)

func (Fields) TabNames added in v0.5.0

func (f Fields) TabNames() (names []string)

type Parser added in v0.5.0

type Parser func(spec *Field, input interface{}) (parsed interface{}, err error)

type Parsers added in v0.5.0

type Parsers map[string]Parser

Jump to

Keyboard shortcuts

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