Documentation ¶
Index ¶
- Constants
- func FixValues(results ...sql.Values)
- func InvalidName(name string) error
- type API
- func (api *API) Add(resource *ResourceSQL) error
- func (api *API) AddRest(name string, resource Rest, keys ...string) error
- func (api *API) Handle(w http.ResponseWriter, request *Request)
- func (api *API) Prefix() string
- func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (api *API) SetPrefix(prefix string) *API
- type APIError
- type ClosingBuffer
- type ColumnField
- type Columns
- type Decoder
- type Encoder
- type EqualsFilter
- type Field
- type Fields
- type Filter
- type Handle
- type Include
- type JSON
- type ManyElem
- func (elem ManyElem) AsMap(key, value string) ManyElem
- func (elem ManyElem) DetailOnly() ManyElem
- func (elem ManyElem) Exclude(names ...string) ManyElem
- func (elem ManyElem) Modify(resource *ResourceSQL) error
- func (elem ManyElem) Query(conn sql.Connection, values sql.Values) error
- func (elem ManyElem) QueryAll(c sql.Connection, values []sql.Values) error
- type ManyToManyElem
- func (elem ManyToManyElem) DetailOnly() ManyToManyElem
- func (elem ManyToManyElem) Exclude(names ...string) ManyToManyElem
- func (elem ManyToManyElem) IncludeThrough(names ...string) ManyToManyElem
- func (elem ManyToManyElem) Modify(resource *ResourceSQL) error
- func (elem ManyToManyElem) Query(c sql.Connection, values sql.Values) error
- func (elem ManyToManyElem) QueryAll(c sql.Connection, v []sql.Values) error
- type Meta
- type Modifier
- type MultiResponse
- type OptionalType
- type Param
- type Params
- type Request
- type ResourceSQL
- func (c *ResourceSQL) Delete(r *Request) (Response, *APIError)
- func (c *ResourceSQL) Get(r *Request) (Response, *APIError)
- func (c *ResourceSQL) HasRequired(values sql.Values) *APIError
- func (c *ResourceSQL) List(r *Request) (Response, *APIError)
- func (c *ResourceSQL) Patch(r *Request) (Response, *APIError)
- func (c *ResourceSQL) Post(r *Request) (Response, *APIError)
- func (c *ResourceSQL) Validate(values sql.Values) *APIError
- type Response
- type Rest
- type StringFilter
- type TableElem
- type Validator
- type YAML
Constants ¶
const ( GET method = "GET" POST method = "POST" PUT method = "PUT" PATCH method = "PATCH" DELETE method = "DELETE" OPTIONS method = "OPTIONS" )
Variables ¶
This section is empty.
Functions ¶
func FixValues ¶
FixValues converts []byte types to string, since sql.Values objects JSON encode []byte as base64.
func InvalidName ¶
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func NewSQL ¶
func NewSQL(conn sql.Connection) *API
func (*API) Add ¶
func (api *API) Add(resource *ResourceSQL) error
Add adds the SQL resource to the API using its name
func (*API) Handle ¶
func (api *API) Handle(w http.ResponseWriter, request *Request)
Handle makes an API implement a handler with an argo Request instance
type APIError ¶
type APIError struct { Meta []string `json:"meta"` Fields map[string]string `json:"fields"` // contains filtered or unexported fields }
APIError is an error structure with meta and field-specific errors
func HasRequired ¶
HasRequired confirms that all requested keys exist in the given values map.
type ClosingBuffer ¶
func (ClosingBuffer) Close ¶
func (cb ClosingBuffer) Close() (err error)
type ColumnField ¶
type ColumnField struct { Name string // contains filtered or unexported fields }
type Columns ¶
type Columns map[string]sql.ColumnElem
Columns maintains a set of columns by name
func ColumnSet ¶
func ColumnSet(columns ...sql.ColumnElem) Columns
func (Columns) Selectable ¶
func (set Columns) Selectable() []sql.ColumnElem
Selectable implement's aspect's Selectable interface so the set can be queried directly.
type Decoder ¶
Decoder is the common decoding interface
func GetDecoder ¶
GetDecoder matches the request Content-Type header with a Decoder.
type Encoder ¶
type Encoder interface { Encode(interface{}) []byte // Our responses should never error MediaType() string }
Encoder is the common encoding interface
func GetEncoder ¶
GetEncoder matches the request Accept-Encoding header with an Encoder. TODO this could be done with routes / headers / auth
type EqualsFilter ¶
type EqualsFilter struct {
// contains filtered or unexported fields
}
type Fields ¶
type Fields map[string]ColumnField
Fields maintains a set of fields by name
func FieldsFromColumns ¶
func FieldsFromColumns(columns ...sql.ColumnElem) Fields
func (Fields) Add ¶
func (set Fields) Add(f ColumnField) error
type Include ¶
type Include interface { Query(sql.Connection, sql.Values) error QueryAll(sql.Connection, []sql.Values) error }
type ManyElem ¶
type ManyElem struct {
// contains filtered or unexported fields
}
ManyElem is the internal representation of an included Many resource. The included table must be connected by a Foreign key to the parent resource table.
func (ManyElem) AsMap ¶
AsMap converts the list of many elements into a map of the given key: value.
func (ManyElem) DetailOnly ¶
DetailOnly will attach the ManyElem to only the detail views of the API.
func (ManyElem) Modify ¶
func (elem ManyElem) Modify(resource *ResourceSQL) error
Modify implements the Modifier resource that allows an element to modify a resource. It will add the ManyElem to the list of included elements for the given resource.
type ManyToManyElem ¶
type ManyToManyElem struct {
// contains filtered or unexported fields
}
func ManyToMany ¶
func ManyToMany(name string, table, through *sql.TableElem) ManyToManyElem
func (ManyToManyElem) DetailOnly ¶
func (elem ManyToManyElem) DetailOnly() ManyToManyElem
func (ManyToManyElem) Exclude ¶
func (elem ManyToManyElem) Exclude(names ...string) ManyToManyElem
Exclude removes fields on the element table from the query
func (ManyToManyElem) IncludeThrough ¶
func (elem ManyToManyElem) IncludeThrough(names ...string) ManyToManyElem
IncludeThrough adds fields from the through table to the query
func (ManyToManyElem) Modify ¶
func (elem ManyToManyElem) Modify(resource *ResourceSQL) error
func (ManyToManyElem) Query ¶
func (elem ManyToManyElem) Query(c sql.Connection, values sql.Values) error
Query is the database query method used for single result detail methods.
func (ManyToManyElem) QueryAll ¶
func (elem ManyToManyElem) QueryAll(c sql.Connection, v []sql.Values) error
QueryAll is the database query method used for multiple result list methods.
type Modifier ¶
type Modifier interface {
Modify(*ResourceSQL) error
}
type MultiResponse ¶
type MultiResponse struct { Meta Meta `json:"meta"` Results interface{} `json:"results"` }
type OptionalType ¶
OptionalType wraps a database field. It keeps the type's underlying validation while marking it as optional.
func MakeOptional ¶
func MakeOptional(t sql.Type) OptionalType
func (OptionalType) IsRequired ¶
func (opt OptionalType) IsRequired() bool
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Request ¶
type Request struct { *http.Request Encoding Encoder Decoding Decoder Params Params Values url.Values }
func (*Request) QueryValues ¶
type ResourceSQL ¶
type ResourceSQL struct { Name string // contains filtered or unexported fields }
ResourceSQL is the internal representation of a REST resource backed by SQL.
func Resource ¶
func Resource(t TableElem, fields ...Modifier) *ResourceSQL
Resource created a new ResourceSQL from the given table and modifiers. Panic on errors.
func (*ResourceSQL) HasRequired ¶
func (c *ResourceSQL) HasRequired(values sql.Values) *APIError
type Rest ¶
type Rest interface { List(*Request) (Response, *APIError) Post(*Request) (Response, *APIError) Get(*Request) (Response, *APIError) Patch(*Request) (Response, *APIError) Delete(*Request) (Response, *APIError) }
Rest is the common interface for REST-ful resources
type StringFilter ¶
type StringFilter struct {
// contains filtered or unexported fields
}
type TableElem ¶
type TableElem struct { Name string // contains filtered or unexported fields }
TableElem wraps the given SQL table. The sql.TableElem is not directly added to the resource in case we want to provide options / modifiers before altering the ResourceSQL (see the Resource() constructor)