context

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 (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) 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) CamelizeKeys

func (c Context) CamelizeKeys()

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

func (Context) Copy

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

Copy makes a duplicate of this Context

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) 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

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) 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) LowerCamelizeKeys added in v0.2.2

func (c Context) LowerCamelizeKeys()

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

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) SetSpecific

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

SetSpecific is like Set(), without CamelCasing the key

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) 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 RequestKey

type RequestKey string

Jump to

Keyboard shortcuts

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