Documentation ¶
Index ¶
- Constants
- Variables
- func ClearFactory(inner endpoint.Endpoint) endpoint.Endpoint
- func CloseAllIn(ctx context.Context)
- func Middleware(factory Factory) endpoint.Middleware
- func ParseError(err error) (code int, msg string)
- func RequestFuncWithFactory(factory Factory) httptransport.RequestFunc
- func WithFactory(parent context.Context, factory Factory) context.Context
- type BasicConds
- type BasicQuery
- func (q *BasicQuery) AddCond(p string, v interface{}) Query
- func (q *BasicQuery) GetConds() Conds
- func (q *BasicQuery) GetLimit() uint64
- func (q *BasicQuery) GetOffset() uint64
- func (q *BasicQuery) GetSorts() Sorts
- func (q *BasicQuery) SetConds(cs Conds) Query
- func (q *BasicQuery) SetLimit(n uint64) Query
- func (q *BasicQuery) SetOffset(n uint64) Query
- func (q *BasicQuery) SetSorts(cs Sorts) Query
- func (q *BasicQuery) Sort(sstr string) Query
- type BasicSorts
- type Cond
- type Conds
- type Conn
- type EntityListPtr
- type EntityPtr
- type Factory
- type Pager
- type PoolConn
- type Provider
- type Query
- type Response
- type Result
- type Sort
- type Sorts
- type Source
- type SourceFunc
- type SourcePool
- type Store
- type StoreError
- func (err StoreError) Error() string
- func (err StoreError) String() string
- func (err *StoreError) TellClient(msg string, v ...interface{}) *StoreError
- func (err *StoreError) TellDeveloper(msg string, v ...interface{}) *StoreError
- func (err *StoreError) TellServer(msg string, v ...interface{}) *StoreError
- type Stores
Constants ¶
const ( And = iota Or )
const ( Asc = iota Desc )
const (
DefaultSrc keys
)
context keys
Variables ¶
var ErrorForbidden = Error(http.StatusForbidden, "Permission Denied")
ErrorForbidden singleton status in case permission denied
var ErrorInternal = Error(http.StatusInternalServerError, "Internal Server Error")
ErrorInternal singleton status in case internal server error
var ErrorMethodNotAllowed = Error(http.StatusMethodNotAllowed, "Method Not Allowed")
ErrorMethodNotAllowed singleton status in case HTTP method is not allowed to use
var ErrorNotFound = Error(http.StatusNotFound, "Not Found")
ErrorNotFound singleton status in case not found
var StatusFound = Error(http.StatusFound, "Success")
StatusFound singleton status in case entity found
Functions ¶
func ClearFactory ¶
ClearFactory cleans up after RequestFunc. If you called RequestFunc in your http transport, you should use this
func CloseAllIn ¶
CloseAllIn close all Store connections in the context
func Middleware ¶
func Middleware(factory Factory) endpoint.Middleware
Middleware takes a Factory and create a middleware that does WithStores and CloseAllIn
func ParseError ¶
ParseError reads and parse a given status message. It reads Error type and unpack the status code and message. If it is not of Error type, it will return 400 internal server error. If it is nil, it will return 302 found
func RequestFuncWithFactory ¶
func RequestFuncWithFactory(factory Factory) httptransport.RequestFunc
RequestFuncWithFactory returns a go-kit/kit/transpoirt/http.RequestFunc that will add a given factory to the context
Types ¶
type BasicConds ¶
BasicConds implements of Conds
func (*BasicConds) Add ¶
func (c *BasicConds) Add(prop string, value interface{}) Conds
Add adds a condition
func (*BasicConds) GetMap ¶
func (c *BasicConds) GetMap() (m map[string]interface{}, err error)
GetMap gets the list of conditions in the form of map[string]interface{}
func (*BasicConds) SetRel ¶
func (c *BasicConds) SetRel(r int) Conds
SetRel is setter of relation flag
type BasicQuery ¶
BasicQuery implements Query interface
func (*BasicQuery) AddCond ¶
func (q *BasicQuery) AddCond(p string, v interface{}) Query
AddCond add a Cond to Conds
func (*BasicQuery) GetConds ¶
func (q *BasicQuery) GetConds() Conds
GetConds get the conds interface within
func (*BasicQuery) GetOffset ¶
func (q *BasicQuery) GetOffset() uint64
GetOffset is getter of offset
func (*BasicQuery) GetSorts ¶
func (q *BasicQuery) GetSorts() Sorts
GetSorts get the Sorts interface within
func (*BasicQuery) SetConds ¶
func (q *BasicQuery) SetConds(cs Conds) Query
SetConds set the conds interface within
func (*BasicQuery) SetLimit ¶
func (q *BasicQuery) SetLimit(n uint64) Query
SetLimit is setter of limit
func (*BasicQuery) SetOffset ¶
func (q *BasicQuery) SetOffset(n uint64) Query
SetOffset is setter of offset
func (*BasicQuery) SetSorts ¶
func (q *BasicQuery) SetSorts(cs Sorts) Query
SetSorts set the Sorts interface within
type BasicSorts ¶
type BasicSorts []*Sort
BasicSorts implements Sorts
func (*BasicSorts) Add ¶
func (ss *BasicSorts) Add(sstr string) Sorts
Add adds a Sort to the BasicSort collection
func (*BasicSorts) GetAll ¶
func (ss *BasicSorts) GetAll() []*Sort
GetAll returns the whole collection of Sort as slice
type Cond ¶
type Cond struct { Prop string Value interface{} }
Cond is the generic condition statement aims to be interatable with upper.io and google datastore
type Conds ¶
type Conds interface { // SetRel is setter of relation flag SetRel(int) Conds // GetRel is getter of relation flag GetRel() int // Add adds a condition Add(string, interface{}) Conds // GetAll gets the list of conditions GetAll() []Cond // GetMap gets the list of conditions in the // form of map[string]interface{} // // Compatible layer with upper.io // the result can be used as db.Cond GetMap() (map[string]interface{}, error) }
Conds is the general interface represents conditions all setters return itself so the operation can cascade
type Conn ¶
type Conn interface { // Raw returns the raw session object Raw() interface{} // Close disconnect the session to the data source Close() }
Conn is the interface to handle database connections session to Source
type EntityListPtr ¶
type EntityListPtr interface{}
EntityListPtr holds ointer to list of entiity It is basically empty interface. Only named as a hint.
type EntityPtr ¶
type EntityPtr interface{}
EntityPtr holds pointer to entiity. It is basically empty interface. Only named as a hint.
type Factory ¶
type Factory interface { // SetSource sets a Source to the key SetSource(srcKey interface{}, src Source) // GetSource gets a Source with the given key GetSource(srcKey interface{}) Source // Set associates a source and a store provider to a key (store key) Set(key, srcKey interface{}, provider Provider) // Get retrieve a source and a store provider // associated with the given key (store key) Get(key interface{}) (srcKey interface{}, provider Provider) }
Factory is the interface to manufacture Stores. It contains definitions of Source and Store
Factory produces and manage Store instances
type Pager ¶
type Pager interface { // MarshalJSON implements json Marshaler interface MarshalJSON() ([]byte, error) // UnmarshalJSON implements json Unarshaler interface UnmarshalJSON([]byte) error // SetTotal sets the total in the pager descriptor SetTotal(total int) Pager // GetTotal gets the total in the pager descriptor GetTotal() (total int) // SetLimit sets the limit and offset in the pager descriptor SetLimit(limit, offset int) Pager // GetLimit gets the limit and offset in the pager descriptor GetLimit() (limit, offset int) }
Pager is an implementation of a pager descriptor
type PoolConn ¶
type PoolConn struct {
// contains filtered or unexported fields
}
PoolConn is a wrapper of Conn that also implments Conn
type Query ¶
type Query interface { // SetLimit is setter of limit SetLimit(uint64) Query // GetLimit is getter of limit GetLimit() uint64 // SetOffset is setter of offset SetOffset(uint64) Query // GetOffset is getter of offset GetOffset() uint64 // SetConds sets the conds interface withing SetConds(Conds) Query // GetConds gets the conds interface within GetConds() Conds // AddCond add a Cond to Conds AddCond(prop string, val interface{}) Query // SetSorts sets the Sorts interface withing SetSorts(Sorts) Query // GetSorts gets the Sorts interface within GetSorts() Sorts // AddSort add a Sort to Sorts Sort(sstr string) Query }
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response helps to wrap a
func ExpandResponse ¶
ExpandResponse converts a map[string]interface{} into proper JSON-marshalable response
func NewResponse ¶
NewResponse return a service response pointer
func (Response) MarshalJSON ¶
MarshalJSON implements json Marshaler interface
type Result ¶
type Result interface { // All fetches all results within the result set and dumps them into the // given pointer to slice of maps or structs All(el interface{}) (err error) // Raw returns the underlying database result variable Raw() (interface{}, error) // Count returns the number of items matches match the given query Count() (count uint64, err error) // Close closes the result set Close() error }
Result defines interface of an entity servie search result
type Sort ¶
Sort is the generic description of a sorting aims to be interatable with upper.io and google datastore
type SourceFunc ¶
SourceFunc implements Source for functions
type SourcePool ¶
type SourcePool struct {
// contains filtered or unexported fields
}
SourcePool helps to pool connection of any given source
func Pool ¶
func Pool(src Source, size uint, expires time.Duration) *SourcePool
Pool wraps a source into a SourcePool
func (*SourcePool) AddNewConn ¶
func (pool *SourcePool) AddNewConn()
AddNewConn adds a new connection to the pool
func (*SourcePool) Open ¶
func (pool *SourcePool) Open() (conn Conn, err error)
Open implements Source.Open()
type Store ¶
type Store interface { // Basic entity operations Create(Conds, EntityPtr) error Search(Query) Result One(Conds, EntityPtr) error Update(Conds, EntityPtr) error Delete(Conds) error // Memory allocation AllocEntity() EntityPtr AllocEntityList() EntityListPtr // Helper Len(EntityListPtr) int64 // Close the database session this // service is using Close() error }
Store defines interface of an entity service
type StoreError ¶
type StoreError struct { // Status is the http status code Status int `json:"status"` // Code is service specific status code Code int `json:"code"` // ServerMsg is the server side log message ServerMsg string `json:"-"` // ClientMsg is the client side message which could // be displayed to their user directly ClientMsg string `json:"message"` // DeveloperMsg is the client side message which // should be of help to developer. Omit if empty DeveloperMsg string `json:"developer_message,omitempty"` }
StoreError is for common service error message
func Error ¶
func Error(code int, msg string, v ...interface{}) *StoreError
Error creates formated error message with entityError type
func ExpandError ¶
func ExpandError(err error) *StoreError
ExpandError trys to cast the error into *StoreError or generate a new *ServicError based on it
func (StoreError) Error ¶
func (err StoreError) Error() string
Error implements the standard error type returns the client message
func (StoreError) String ¶
func (err StoreError) String() string
String implements Stringer type which returns the client message
func (*StoreError) TellClient ¶
func (err *StoreError) TellClient(msg string, v ...interface{}) *StoreError
TellClient sets server message
func (*StoreError) TellDeveloper ¶
func (err *StoreError) TellDeveloper(msg string, v ...interface{}) *StoreError
TellDeveloper sets server message
func (*StoreError) TellServer ¶
func (err *StoreError) TellServer(msg string, v ...interface{}) *StoreError
TellServer sets server message
type Stores ¶
type Stores interface { // Connect connects a provider at a source // and return connection and, if any, connection error Get(key interface{}) (s Store, err error) // Close close all Conn in the set Close() }
Stores is an interface for store with connection pool management.
Each HTTP request should have its own Stores instance in the context