config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchPath

func MatchPath(templatePath, requestPath string) (map[string]string, bool)

MatchPath parses Paths to match and extract {<param>} defined in rule.Path from request.Path, it returns extracted parameters and flag if requestPath matched templatePath

func MergeMap

func MergeMap(values map[string]interface{}, target map[string]interface{})

MergeMap merge values

func MergeValues

func MergeValues(values url.Values, target map[string]interface{})

MergeValues merge values

Types

type Config

type Config struct {
	URL          string
	CacheRules   bool `json:",omitempty"`
	Rules        Rules
	Connectors   Connectors
	DataCacheURL string `json:",omitempty"`
}

Config represents a config

func NewConfig

func NewConfig(ctx context.Context, source string) (*Config, error)

NewConfig creates a new config from env (json or URL)

func NewConfigFromEnv

func NewConfigFromEnv(ctx context.Context, key string) (*Config, error)

NewConfigFromEnv creates config from env

func NewConfigFromURL

func NewConfigFromURL(ctx context.Context, URL string) (*Config, error)

NewConfigFromURL creates new config from URL

func (*Config) Init

func (c *Config) Init(ctx context.Context, fs afs.Service) error

Init initialises config

func (*Config) ReloadChanged

func (c *Config) ReloadChanged(ctx context.Context, fs afs.Service) (err error)

ReloadChanged reload changes if needed

func (Config) Validate

func (c Config) Validate() error

Validate checks if config is valid

type Connector

type Connector struct {
	Name    string
	URL     string
	Dialect string
	Secrets *Secret `json:",omitempty"`
	Config  *dsc.Config
}

Connector represents database connector

func (*Connector) Init

func (c *Connector) Init() error

Init initialise connector

func (*Connector) Validate

func (c *Connector) Validate() error

Validate checks if connector is valid

type Connectors

type Connectors struct {
	URL    string
	Loader *Loader
	// contains filtered or unexported fields
}

Connectors represents connectors pool

func (*Connectors) Add

func (c *Connectors) Add(connector *Connector) error

func (Connectors) Get

func (c Connectors) Get(name string) (*Connector, error)

Get returns a connector for supplied name

func (*Connectors) Init

func (c *Connectors) Init(ctx context.Context, fs afs.Service) error

Init initialises connector

func (*Connectors) Load

func (c *Connectors) Load(ctx context.Context, fs afs.Service, URL string) error

Load load connector

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader represents URL changes notifier

func NewLoader

func NewLoader(baeURL string, checkFrequency time.Duration, fs afs.Service, onChanged, onRemoved Notify) *Loader

NewLoader create a loader

func (*Loader) Notify

func (m *Loader) Notify(ctx context.Context, fs afs.Service) (bool, error)

Notify notifies any rule changes

type Notify

type Notify func(ctx context.Context, fs afs.Service, URL string) error

Notify represent notify function

type Resources

type Resources struct {
	// contains filtered or unexported fields
}

Resources represents a resource

func NewResources

func NewResources() *Resources

NewResources creates a resources container

func (*Resources) Add

func (r *Resources) Add(URL string, modified time.Time)

Add add url with modified time

func (*Resources) Get

func (r *Resources) Get(URL string) *time.Time

Get returns URL last modified time

func (*Resources) GetMissing

func (r *Resources) GetMissing(snapshot map[string]time.Time) []string

GetMissing returns missing in snapshot URLs

func (*Resources) Has

func (r *Resources) Has(URL string) bool

Has returns true if has URL

func (*Resources) Remove

func (r *Resources) Remove(URL string)

Remove removes URL from a elements

type Rule

type Rule struct {
	Info       rule.Info
	Path       string `json:",omitempty"`
	PathPrefix string `json:",omitempty"`
	UseCache   bool   `json:",omitempty"`
	data.Meta
}

Rule represents data rule

func (*Rule) Init

func (r *Rule) Init(ctx context.Context, fs afs.Service) (err error)

Init initialise rule

func (*Rule) Validate

func (r *Rule) Validate() error

Validate checks if rule is valid

type Rules

type Rules struct {
	URL string

	Loader *Loader
	// contains filtered or unexported fields
}

Rules stores rules

func (*Rules) Add

func (r *Rules) Add(rule *Rule) error

func (*Rules) Init

func (r *Rules) Init(ctx context.Context, fs afs.Service) error

Init initialises rules

func (Rules) Len

func (r Rules) Len() int

Len is the number of elements in the collection.

func (Rules) Less

func (r Rules) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (*Rules) Load

func (r *Rules) Load(ctx context.Context, fs afs.Service, URL string) error

Load load a rule

func (Rules) Match

func (r Rules) Match(Path string) (*Rule, url.Values)

Match matches rule with path

func (Rules) Swap

func (r Rules) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type Secret

type Secret access.Request

Secret represents a secret config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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