crudinator

package module
v0.0.0-...-c4d280c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

README

crudinator

Make writing CRUD APIs a thing of the past

The goal of this project is to make it so that you only ever have to specify a crud api and not implement it, while allowing extensibility to handle corner cases. Some features of this will be planned for rapid development only, but most are intended to be mature enough to use in a production system. A good way of thinking about this would be that we want to wrap storage solutions with auth* and event sourcing for monitoring/auditing.

Planned features:

  • A highly configurable integration for oidc
  • Event sourcing with Kafka, RabbitMQ, and maybe some Cloud-provider specific solutions
  • Storage engine support for Postgres, Mysql, SQLite, MongoDB, CockroachDB, Reddis, etcd, CouchDB, S3?, maybe more?
  • Configuration via OpenAPI specifications, scraping an existing database, HTTP interface with schema stored in the supporting db.
  • Automated management of schema in the connected storage engine. This will probably be done through integration with existing db-specific libraries
  • Vault integration for pulling credentials for oauth, event sink and db connections
  • I want to investigate other transport mechanisms, in particular grpc, but that is dependent on the complexity of implementing and maintaining the different protocol support

Initially this will require type definitions to be written in go, with annotations for validators. Custom request handlers can be added by implementing request functions for the specific task you wish to modify.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("Not Found")
)

Functions

func HandleError

func HandleError(rw http.ResponseWriter, err error) bool

Types

type AuthProvider

type AuthProvider interface{}

type CRUDGetHandler

type CRUDGetHandler interface {
	Get(ctx *Context, rw web.ResponseWriter, req *web.Request)
}

type Config

type Config struct {
	PersistentStore PersistentStoreConfig
	EventSink       EventSinkConfig
	Oauth           OauthConfig
}

func ParseConfig

func ParseConfig() Config

type Context

type Context struct {
	Validators      *map[reflect.Type]map[string]ValidatorFunc
	EventSink       EventSink
	PersistentStore PersistentStore
	context.Context
}

type ContextKey

type ContextKey string
const (
	PersistentStoreKey ContextKey = "CRUDPersistentStore"
)

type Core

type Core struct {
	Validators      map[reflect.Type]map[string]ValidatorFunc
	Resources       map[string]interface{}
	Router          *web.Router
	EventSink       EventSink
	PersistentStore PersistentStore
	OauthProvider   AuthProvider
	Config          Config
}

func New

func New(conf ...Config) (*Core, error)

New will return a new Core object with the config parsed and EventSink, PersistentStore, Oauth Provider

func (*Core) RegisterPersistentStore

func (core *Core) RegisterPersistentStore(ps PersistentStore) error

func (*Core) RegisterResource

func (core *Core) RegisterResource(res interface{})

func (*Core) RegisterValidator

func (core *Core) RegisterValidator(name string, validator ValidatorFunc)

type DefaultHandler

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

type EventSink

type EventSink interface {
	Send(interface{}) error
}

type EventSinkConfig

type EventSinkConfig struct {
	Host     string
	Port     string
	Protocol string
}

type HandleFunc

type HandleFunc func(ctx *Context, rw web.ResponseWriter, req *web.Request)

type OauthConfig

type OauthConfig struct {
	Host     string
	Port     string
	Protocol string
}

type PersistentStore

type PersistentStore interface {
	// Connect will use the provided config to connect to the persistent store provider
	Connect(PersistentStoreConfig) error

	// Session will be called before handling each request. It should return a new PersistentStore with the object that should be used for querying properly initialised. This is present to support connection pooling, but is not required to be used. If session returns nil then the original PersistentStore will be used
	Session() PersistentStore

	// Get returns the object identified by the given key from the table with the supplied name, and saves the result into the supplied dst object pointer
	Get(key interface{}, tableName string, dst interface{}) error

	// List returns a list of objects filtered using key:value pairs. The interface passed into List will always be a pointer to a slice of the reource to be listed
	List(tableName string, filters map[string]interface{}, dst interface{}) error

	// Insert will create a new entry using the provided key and value and will return an error if the operation has failed.
	Insert(key interface{}, tableName string, value interface{}) error

	// Insert will create a new entry using the provided key and value and overwrite the existing value if it does exist, and will return an error if the operation has failed.
	Set(key interface{}, tableName string, value interface{}) error

	// Update will provide partial modification of objects in a json-patch style update (TBD)
	Update(key interface{}, tableName string, value interface{}) error

	// Delete will remove the entry associated with the provided key
	Delete(key interface{}, tableName string) error

	// Close will close the underlying connection
	Close() error

	// Raw will return a pointer to the underlying db connection
	Raw() interface{}
}

func ExtractPersistentStore

func ExtractPersistentStore(ctx context.Context) PersistentStore

type PersistentStoreConfig

type PersistentStoreConfig struct {
	Engine   string //type of db. Eg: "postgres", "mysql",
	Host     string
	Port     string
	Protocol string
	Username string
	Password string
	Schema   string

	ConnectionString string
}

type StdGetHandler

type StdGetHandler interface {
	Get(rw http.ResponseWriter, req *http.Request)
}

type StdListHandler

type StdListHandler interface {
	List(rw http.ResponseWriter, req *http.Request)
}

type StdSetHandler

type StdSetHandler interface {
	Set(rw http.ResponseWriter, req *http.Request)
}

type ValidatorFunc

type ValidatorFunc func(value interface{}, annotation string) error

ValidatorFunc describes the format for validator functions. The annotation used to call the validator is provided to enable implementing variations within the same validator (eg: dates)

Directories

Path Synopsis
storage
test

Jump to

Keyboard shortcuts

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