configu

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

@configu/go

Configu SDK for Go published to GitHub.

Install

go get github.com/configu/configu/go

Usage

package main

import (
	configu "github.com/configu/configu/go"
	"fmt"
)

func main() {
	store := configu.InMemoryStore{}
	set, _ := configu.NewConfigSet("test")
	schema, _ := configu.NewConfigSchema("get-started.cfgu.json")
	configu.UpsertCommand{
		Store:   &store,
		Set:     set,
		Schema:  schema,
		Configs: map[string]string{"GREETING": "hey", "SUBJECT": "configu go SDK"},
	}.Run()
	config, err := configu.EvalCommand{
		Store:  &store,
		Set:    set,
		Schema: schema,
	}.Run()
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", config)
}

Contributing

Requirements

Follow the Development section from the CONTRIBUTING.md.

Setup
cd go
go install
Contribute

Follow the Sending a Pull Request section from the CONTRIBUTING.md.

Documentation

Index

Constants

View Source
const (
	SEPARATOR  string = "/"
	ROOT       string = ""
	ROOT_LABEL string = "/"
)
View Source
const (
	EXT string = ".cfgu"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cfgu

type Cfgu struct {
	Default     *string                `json:"default,omitempty"`
	Depends     []string               `json:"depends,omitempty"`
	Description *string                `json:"description,omitempty"`
	Options     []string               `json:"options,omitempty"`
	Pattern     *string                `json:"pattern,omitempty"`
	Required    *bool                  `json:"required,omitempty"`
	Schema      map[string]interface{} `json:"schema,omitempty"`
	Template    *string                `json:"template,omitempty"`
	Type        CfguType               `json:"type"`
}

A generic declaration of a Config, aka Cfgu that specifies information about its type and other characteristics

func UnmarshalCfgu

func UnmarshalCfgu(data []byte) (Cfgu, error)

func (*Cfgu) Marshal

func (r *Cfgu) Marshal() ([]byte, error)

type CfguType

type CfguType string
const (
	AWSRegion        CfguType = "AWSRegion"
	AZRegion         CfguType = "AZRegion"
	AlibabaRegion    CfguType = "AlibabaRegion"
	Arn              CfguType = "ARN"
	Base64           CfguType = "Base64"
	Boolean          CfguType = "Boolean"
	Color            CfguType = "Color"
	ConnectionString CfguType = "ConnectionString"
	Country          CfguType = "Country"
	Currency         CfguType = "Currency"
	DateTime         CfguType = "DateTime"
	DockerImage      CfguType = "DockerImage"
	Domain           CfguType = "Domain"
	Email            CfguType = "Email"
	GCPRegion        CfguType = "GCPRegion"
	Hex              CfguType = "Hex"
	IBMRegion        CfguType = "IBMRegion"
	IPv4             CfguType = "IPv4"
	IPv6             CfguType = "IPv6"
	JSONSchema       CfguType = "JSONSchema"
	Language         CfguType = "Language"
	LatLong          CfguType = "LatLong"
	Locale           CfguType = "Locale"
	MACAddress       CfguType = "MACAddress"
	MIMEType         CfguType = "MIMEType"
	Md5              CfguType = "MD5"
	MobilePhone      CfguType = "MobilePhone"
	MongoID          CfguType = "MongoId"
	Number           CfguType = "Number"
	OracleRegion     CfguType = "OracleRegion"
	RegEx            CfguType = "RegEx"
	SHA              CfguType = "SHA"
	SemVer           CfguType = "SemVer"
	String           CfguType = "String"
	URL              CfguType = "URL"
	UUID             CfguType = "UUID"
)

func UnmarshalCfguType

func UnmarshalCfguType(data []byte) (CfguType, error)

func (*CfguType) Marshal

func (r *CfguType) Marshal() ([]byte, error)

type Command

type Command[T any] interface {
	Run() (T, error)
}

type Config

type Config struct {
	Key   string `json:"key"`
	Set   string `json:"set"`
	Value string `json:"value"`
}

A generic representation of a software configuration, aka Config

func UnmarshalConfig

func UnmarshalConfig(data []byte) (Config, error)

func (*Config) Marshal

func (r *Config) Marshal() ([]byte, error)

type ConfigSchema

type ConfigSchema struct {
	Path string           `json:"path"`
	Type ConfigSchemaType `json:"type"`
}

An interface of a <file>.cfgu.json, aka ConfigSchema that contains binding records between a unique Config.<key> and its Cfgu declaration

func NewConfigSchema

func NewConfigSchema(path string) (schema ConfigSchema, err error)

func UnmarshalConfigSchema

func UnmarshalConfigSchema(data []byte) (ConfigSchema, error)

func (*ConfigSchema) Marshal

func (r *ConfigSchema) Marshal() ([]byte, error)

func (ConfigSchema) Parse

func (schema ConfigSchema) Parse() (cfgu ConfigSchemaContents, err error)

func (ConfigSchema) Read

func (schema ConfigSchema) Read() []byte

type ConfigSchemaContents

type ConfigSchemaContents map[string]ConfigSchemaContentsValue

func UnmarshalConfigSchemaContents

func UnmarshalConfigSchemaContents(data []byte) (ConfigSchemaContents, error)

func (*ConfigSchemaContents) Marshal

func (r *ConfigSchemaContents) Marshal() ([]byte, error)

type ConfigSchemaContentsValue

type ConfigSchemaContentsValue struct {
	Default     *string                `json:"default,omitempty"`
	Depends     []string               `json:"depends,omitempty"`
	Description *string                `json:"description,omitempty"`
	Options     []string               `json:"options,omitempty"`
	Pattern     *string                `json:"pattern,omitempty"`
	Required    *bool                  `json:"required,omitempty"`
	Schema      map[string]interface{} `json:"schema,omitempty"`
	Template    *string                `json:"template,omitempty"`
	Type        CfguType               `json:"type"`
}

func UnmarshalConfigSchemaContentsValue

func UnmarshalConfigSchemaContentsValue(data []byte) (ConfigSchemaContentsValue, error)

func (*ConfigSchemaContentsValue) Marshal

func (r *ConfigSchemaContentsValue) Marshal() ([]byte, error)

type ConfigSchemaType

type ConfigSchemaType string
const (
	JSON ConfigSchemaType = "json"
)

func UnmarshalConfigSchemaType

func UnmarshalConfigSchemaType(data []byte) (ConfigSchemaType, error)

func (*ConfigSchemaType) Marshal

func (r *ConfigSchemaType) Marshal() ([]byte, error)

type ConfigSet

type ConfigSet struct {
	Hierarchy []string `json:"hierarchy"`
	Path      string   `json:"path"`
}

An interface of a path in an hierarchy, aka ConfigSet that uniquely groups Config.<key> with their Config.<value>.

func NewConfigSet

func NewConfigSet(path string) (set ConfigSet, err error)

func UnmarshalConfigSet

func UnmarshalConfigSet(data []byte) (ConfigSet, error)

func (*ConfigSet) Marshal

func (r *ConfigSet) Marshal() ([]byte, error)

type ConfigStore

type ConfigStore struct {
	Type string `json:"type"`
}

An interface of a storage, aka ConfigStore that I/Os Config records (Config[])

func UnmarshalConfigStore

func UnmarshalConfigStore(data []byte) (ConfigStore, error)

func (*ConfigStore) Marshal

func (r *ConfigStore) Marshal() ([]byte, error)

type ConfigStoreContents

type ConfigStoreContents []ConfigStoreContentsElement

func UnmarshalConfigStoreContents

func UnmarshalConfigStoreContents(data []byte) (ConfigStoreContents, error)

func (*ConfigStoreContents) Marshal

func (r *ConfigStoreContents) Marshal() ([]byte, error)

type ConfigStoreContentsElement

type ConfigStoreContentsElement struct {
	Key   string `json:"key"`
	Set   string `json:"set"`
	Value string `json:"value"`
}

func UnmarshalConfigStoreContentsElement

func UnmarshalConfigStoreContentsElement(data []byte) (ConfigStoreContentsElement, error)

func (*ConfigStoreContentsElement) Marshal

func (r *ConfigStoreContentsElement) Marshal() ([]byte, error)

type ConfigStoreQuery

type ConfigStoreQuery struct {
	Key string `json:"key"`
	Set string `json:"set"`
}

func UnmarshalConfigStoreQuery

func UnmarshalConfigStoreQuery(data []byte) (ConfigStoreQuery, error)

func (*ConfigStoreQuery) Marshal

func (r *ConfigStoreQuery) Marshal() ([]byte, error)

type ConfiguConfigStore

type ConfiguConfigStore struct {
	Org   string
	Token string
}

func (ConfiguConfigStore) Get

func (s ConfiguConfigStore) Get(queries []ConfigStoreQuery) ([]Config, error)

func (ConfiguConfigStore) GetType

func (s ConfiguConfigStore) GetType() string

func (ConfiguConfigStore) Set

func (s ConfiguConfigStore) Set(configs []Config) error

type ConfiguError

type ConfiguError struct {
	Message    string
	Location   []string
	Suggestion string
}

func (ConfiguError) Error

func (err ConfiguError) Error() string

type EvalCommand

type EvalCommand struct {
	Store    IConfigStore
	Set      ConfigSet
	Schema   ConfigSchema
	Configs  map[string]string
	Validate *bool
	Previous *EvalCommandReturn
}

func (EvalCommand) Run

func (c EvalCommand) Run() (EvalCommandReturn, error)

type EvalCommandReturn

type EvalCommandReturn map[string]*EvalCommandReturnValue

type EvalCommandReturnContext

type EvalCommandReturnContext struct {
	Store  string
	Set    string
	Schema string
	Key    string
	Cfgu   ConfigSchemaContentsValue
}

type EvalCommandReturnResult

type EvalCommandReturnResult struct {
	Origin EvaluatedConfigOrigin
	Source string
	Value  string
}

type EvalCommandReturnValue

type EvalCommandReturnValue struct {
	Context EvalCommandReturnContext
	Result  EvalCommandReturnResult
}

type EvaluatedConfigOrigin

type EvaluatedConfigOrigin string
const (
	ConfigsOverride EvaluatedConfigOrigin = "CONFIGS_OVERRIDE"
	StoreSet        EvaluatedConfigOrigin = "STORE_SET"
	SchemaTemplate  EvaluatedConfigOrigin = "SCHEMA_TEMPLATE"
	SchemaDefault   EvaluatedConfigOrigin = "SCHEMA_DEFAULT"
	EmptyValue      EvaluatedConfigOrigin = "EMPTY_VALUE"
)

type IConfigStore

type IConfigStore interface {
	Get(queries []ConfigStoreQuery) ([]Config, error)
	Set(configs []Config) error
	GetType() string
}

type InMemoryStore

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

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(queries []ConfigStoreQuery) ([]Config, error)

func (*InMemoryStore) GetType

func (s *InMemoryStore) GetType() string

func (*InMemoryStore) Set

func (s *InMemoryStore) Set(configs []Config) error

type JsonFileConfigStore

type JsonFileConfigStore struct {
	Path string
}

func (JsonFileConfigStore) Get

func (s JsonFileConfigStore) Get(queries []ConfigStoreQuery) ([]Config, error)

func (JsonFileConfigStore) GetType

func (s JsonFileConfigStore) GetType() string

func (JsonFileConfigStore) Read

func (JsonFileConfigStore) Set

func (s JsonFileConfigStore) Set(configs []Config) error

func (JsonFileConfigStore) Write

type UpsertCommand

type UpsertCommand struct {
	Store   IConfigStore
	Set     ConfigSet
	Schema  ConfigSchema
	Configs map[string]string
}

func (UpsertCommand) Run

func (c UpsertCommand) Run() (interface{}, error)

Jump to

Keyboard shortcuts

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