config

package
v0.0.0-...-e37af68 Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config is the package that holds all the configurable structures and functions. Its main purpose is to allow users to load a configuration from a json file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppContext

type AppContext struct {
	Driver  Driver
	Render  *render.Render
	Version string
	Port    string
}

AppContext is the structure that holds the current context of the app will be passed in the handlers

type Configuration

type Configuration struct {
	Context  *Context       `json:"context"`
	Database *Database      `json:"database"`
	Manager  *ManagerConfig `json:"manager"`
}

Configuration is the overarching struct for our configuration object

func LoadConfig

func LoadConfig(filename string) (Configuration, error)

LoadConfig is the main way of interacting and creating a configuration. This will create and validate a configuration from a filename.

type Context

type Context struct {
	Port    int    `json:"port"`
	Version string `json:"version"`
}

Context of the server itself

type DBRequest

type DBRequest struct {
	Method  string
	Params  map[string]interface{}
	Queries map[string]interface{}
	Type    string
	Model   Fields
}

DBRequest is the object given to our drivers, each driver must implement the MakeRequest function. This function will take a DBRequest object as a parameter. This object will hold a summerized version of the Restful call

func (*DBRequest) Validate

func (req *DBRequest) Validate() error

Validate will validate the DBRequest with the model provided to make sure the values are able to convert into the proper values given by the model TODO: Check/Enforce type conversion on fields - int, int64 etc.

type Database

type Database struct {
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Type     string `json:"type"`
}

Database configuration

type Driver

type Driver interface {
	MakeRequest(*DBRequest) (interface{}, error)
	ConvertToDriverError(error) error
}

Driver interface is what all database drivers must implement, it allows the server to interact with the database without actually caring what the database actually is.

type Field

type Field struct {
	Key        string      `json:"key"`
	ValueType  interface{} `json:"value_type,omitempty"`
	Options    []string    `json:"options,omitempty"`
	ForeignKey string      `json:"foreignkey,omitempty"`
}

Field is the encapsulation of each of the fields of a object within a database. Its the Field of a data model.

func (*Field) IsOptionSet

func (field *Field) IsOptionSet(option string) bool

IsOptionSet checks to see if within that field a specific option flag is set.

type Fields

type Fields []*Field

Fields is the array version of Field

func (Fields) Atomic

func (f Fields) Atomic() map[string]*Field

Atomic will grab all fields of atomic types, meaning - string, int, int64, etc.

func (Fields) FindField

func (f Fields) FindField(key string) *Field

func (Fields) ForeignKeys

func (f Fields) ForeignKeys() map[string]*Field

ForeignKeys will retrieve all the fields that are not atomic types but rather are types that are defined within the model configuration itself.

func (Fields) GetID

func (f Fields) GetID() string

GetID retrieves the key of the field with the "id" option set. This option can only be set On one field on any given data model.

func (Fields) ToMap

func (f Fields) ToMap() map[string]interface{}

ToMap converts the fields object into a map with each fields key as the map key.

type ManagerConfig

type ManagerConfig struct {
	Generics []string      `json:"generics,omitempty"`
	Plugs    []*PlugConfig `json:"plugins"`
}

ManagerConfig is config object that will hold everything todo with the endpoints itself, including the datamodels, as well as the generic endpoints that will be set. Things like healthcheck and eventually, the login endpoint

type PlugConfig

type PlugConfig struct {
	PathToCode     string `json:"pathtocode,omitempty"`
	PathToCompiled string `json:"pathtocompiled,omitempty"`
	Name           string `json:"name"`
	Description    string `json:"description,omitempty"`
	Path           string `json:"path,omitempty"`
	Model          Fields `json:"model,omitempty"`
}

PlugConfig encapsulates everything around the plugin object, this will hold data for both the model method, or code method of setting up your endpoint. TODO: Check if this is the best way

Jump to

Keyboard shortcuts

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