gondulapi

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: GPL-2.0 Imports: 4 Imported by: 0

README

Gondul API
==========

This is the API engine that will be used for the Gondul backend in the
future. At present, this is very much a work in progress and should NOT be
used unless you talk to me directly about it first - unless you like
breaking things.

The design goals are:

1. Make it very hard to do the wrong thing.
2. Enforce/ensure HTTP RESTful best behavior.
3. Minimize boilerplate-code
4. Make prototyping fun and easy.

To achieve this, we aim that users of the Gondul API will work mainly with
organizing their own data types and how they are interconnected, and not
worry about how that is parsed to/from JSON or checked for type-safety.

The HTTP-bit is pretty small, but important. It's worth noting that users
of the api-code will *not* have access to any information about the caller.
This is a design decision - it's not your job, it's the job of the
HTTP-server (which is represented by the Gondul API engine here). If your
data types rely on data from the client, you're doing it wrong.

The database-bit can be split into a few categories as well. But mainly, it
is an attempt to make it unnecessary to write a lot of boiler-plate to get
sensible behavior. It is currently written with several known flaws, or
trade-offs, so it's not suited for large deployments, but can be considered
a POC or research.

In general, the DB engine uses introspection to figure out how to figure
out how to retrieve and save an object. The Update mechanism will only
update fields that are actually provided (if that is possible to detect!).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config struct {
	ListenAddress    string // Defaults to :8080
	ConnectionString string // For database connections
	Prefix           string // URL prefix, e.g. "/api".
	Debug            bool   // Enables trace-debugging
}

Config covers global configuration, and if need be it will provide mechanisms for local overrides (similar to Skogul).

Functions

func ParseConfig

func ParseConfig(file string) error

ParseConfig reads a file and parses it as JSON, assuming it will be a valid configuration file.

Types

type Deleter

type Deleter interface {
	Delete(element string) error
}

Deleter should delete the object identified by the element. It should be idempotent, in that it should be safe to call it on already-deleted items.

type Error

type Error struct {
	Code    int
	Message string
}

Error is used to combine a text-based error with a HTTP error code.

func Errorf

func Errorf(code int, str string, v ...interface{}) Error

Errorf is a convenience-function to provide an Error data structure, which is essentially the same as fmt.Errorf(), but with an HTTP status code embedded into it which can be extracted.

func (Error) Error

func (e Error) Error() string

Error allows Error to implement the error interface. That's a whole lot of error in one sentence...

type Getter

type Getter interface {
	Get(element string) error
}

Getter implements Get method, which should fetch the object represented by the element path.

type Poster

type Poster interface {
	Post() error
}

Poster is not necessarily idempotent, but can be. It should write the object provided, potentially generating a new ID for it if one isn't provided in the data structure itself.

type Putter

type Putter interface {
	Put(element string) error
}

Putter is an idempotent method that requires an absolute path. It should (over-)write the object found at the element path.

Directories

Path Synopsis
cmd
test command
Package db integrates with generic databases, so far it doesn't do much, but it's supposed to do more.
Package db integrates with generic databases, so far it doesn't do much, but it's supposed to do more.
Package helper provides various minor utility-functions used throughout the gondul api.
Package helper provides various minor utility-functions used throughout the gondul api.
Package objects implements a number of objects.
Package objects implements a number of objects.
Package receiver is scaffolding around net/http that facilitates a RESTful HTTP API with certain patterns implicitly enforced: - When working on the same urls, all Methods should use the exact same data structures.
Package receiver is scaffolding around net/http that facilitates a RESTful HTTP API with certain patterns implicitly enforced: - When working on the same urls, all Methods should use the exact same data structures.

Jump to

Keyboard shortcuts

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