Documentation ¶
Overview ¶
Package gondulapi provides the framework for building a HTTP REST-API backed by a Postgresql Database. The package can be split into three:
1. The HTTP bit, found in receiver/. This deals with accepting HTTP requests, parsing requests and mapping them to data types. It ensures proper division of labour, and makes it less easy to make inconsistent APIs by enforcing that if you GET something on an URL, PUT or POST to the same URL will accept the exact same data type back. In other words, you can do:
GET http://foo/blatti/x > file vim file // Change a field lwp-request -m PUT http://foo/blatti/x < file
And it will do what you expect, assuming the datastructure implements both the Getter-interface and the Putter interface.
2. The SQL bit, found in db/. This is an attempt to use reflection to avoid having to write database queries by hand. It is not meant to cover 100% of all SQL access. Since it makes mapping a Go data type to an SQL table easy, it is meant to inspire good database models, where the API can mostly just get items back and forth.
3. "Misc" - or maybe I should say, the actual Gondul API. Which at this moment isn't actually written. Some other bits fall under this category though, such as config file management and logging. Not very exotic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Config struct { ListenAddress string // Defaults to :8080 ConnectionString string // For database connections Prefix string // URL prefix, e.g. "/api". HTTPUser string // username for HTTP basic auth HTTPPw string // password for HTTP basic auth Debug bool // Enables trace-debugging Driver string // SQL driver, defaults to postgres }
Config covers global configuration, and if need be it will provide mechanisms for local overrides (similar to Skogul).
var InternalError = Error{500, "Internal Server Error"}
InternalError is provided for the common case of returning an opaque error that can be passed to a user.
Functions ¶
func ParseConfig ¶
ParseConfig reads a file and parses it as JSON, assuming it will be a valid configuration file.
Types ¶
type Auther ¶ added in v0.0.8
type Auther interface {
Auth(basepath string, element string, method string, user string, password string) error
}
Auther allows objects to enforce (basic) authentication optionally. For every request, a basepath (the path the object is registered to), an element (the item being worked on, if any) a method (GET/PUT/POST, etc) and username and password is provided.
See gondulapi/auth for some convenience-implementations.
type Deleter ¶
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 `json:"-"` Message interface{} }
Error is used to combine a text-based error with a HTTP error code.
func Errorf ¶
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.
type Getter ¶
Getter implements Get method, which should fetch the object represented by the element path.
type Poster ¶
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 ¶
Putter is an idempotent method that requires an absolute path. It should (over-)write the object found at the element path.
type Report ¶ added in v0.0.8
type Report struct { Affected int `json:",omitempty"` Ok int `json:",omitempty"` Failed int `json:",omitempty"` Error error `json:",omitempty"` Code int `json:"-"` Headers map[string]string `json:"-"` }
Report is an update report on write-requests. The precise meaning might vary, but the gist should be the same.
Directories ¶
Path | Synopsis |
---|---|
package auth provides easy to use authentication primitives for GondulAPI.
|
package auth provides easy to use authentication primitives for GondulAPI. |
cmd
|
|
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 receiver is scaffolding around net/http that facilitates a RESTful HTTP API with certain patterns implicitly enforced:
|
Package receiver is scaffolding around net/http that facilitates a RESTful HTTP API with certain patterns implicitly enforced: |
Package types provides a set of common data types that implement the relevant interfaces for use within gondulapi.
|
Package types provides a set of common data types that implement the relevant interfaces for use within gondulapi. |