Documentation ¶
Index ¶
- Constants
- Variables
- func Cache(scope *gorm.Scope)
- func CacheKey(resource interface{}) string
- func CanMerge(current Revisioner, updated Revisioner) bool
- func CanPerform(resource interface{}, request *http.Request, read bool) error
- func ClearUserSession(w http.ResponseWriter, req *http.Request) error
- func Create(rType reflect.Type, request *http.Request) (int, interface{}, error)
- func DB() *gorm.DB
- func DefaultCacheKey(name string, id interface{}) string
- func Delete(rType reflect.Type, request *http.Request) (int, interface{}, error)
- func GetCurrentUser(req *http.Request) (interface{}, error)
- func HandleLogout(w http.ResponseWriter, request *http.Request)
- func HandleQuery(rType reflect.Type, request *http.Request) (int, interface{}, error)
- func InitGormDb(newDb *gorm.DB)
- func InitSessionStore(store sessions.Store)
- func LoginWithPassword(w http.ResponseWriter, request *http.Request, usernameCol string, ...) (interface{}, error)
- func Pool() *redis.Pool
- func Read(rType reflect.Type, request *http.Request) (int, interface{}, error)
- func RedisClearAll() error
- func RegisterCacher(cache Cacher)
- func RegisterModel(resource interface{})
- func RegisterWithPassword(w http.ResponseWriter, request *http.Request, usernameCol string, ...) (interface{}, error)
- func SetUserModel(user interface{})
- func SetUserSession(w http.ResponseWriter, req *http.Request, user interface{}) error
- func TableName(resource interface{}) string
- func Uncache(scope *gorm.Scope)
- func Update(rType reflect.Type, request *http.Request) (int, interface{}, error)
- type API
- func (api *API) AddCrudResource(resource interface{}, paths ...string)
- func (api *API) AddDefaultAuthPaths(resource interface{})
- func (api *API) AddDefaultCrudPaths(resource interface{})
- func (api *API) AddDefaultQueryPath(resource interface{})
- func (api *API) AddLoginPath(resource interface{}, path string)
- func (api *API) AddLogoutPath(resource interface{}, path string)
- func (api *API) AddQueryResource(resource interface{}, path string)
- func (api *API) AddRegisterPath(resource interface{}, path string)
- func (api *API) Mux() *mux.Router
- type Cacher
- type DeleteSupporter
- type GetSupporter
- type HeadSupporter
- type Loginer
- type Logouter
- type PatchSupporter
- type Permission
- type PermitReader
- type PermitWriter
- type PostSupporter
- type PutSupporter
- type QueryItem
- type QueryParams
- type QuerySupporter
- type RedisCache
- type Registerer
- type Revisioner
- type Roler
Constants ¶
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" HEAD = "HEAD" PATCH = "PATCH" )
HTTP Methods
const ( // SessionName is default name for user session SessionName = "goal.UserSessionName" // SessionKey is default key for user object SessionKey = "goal.UserSessionKey" )
Variables ¶
SharedSessionStore used to generate session for multiple requests
Functions ¶
func CacheKey ¶
func CacheKey(resource interface{}) string
CacheKey defines by the struct or fallback to name:id format
func CanMerge ¶
func CanMerge(current Revisioner, updated Revisioner) bool
CanMerge check if the updated object can be safely merged to current object
func CanPerform ¶
CanPerform check if a roler can access a resource (read/write) If read is false, then it will check for write permission It will return error if the check is failed
func ClearUserSession ¶
func ClearUserSession(w http.ResponseWriter, req *http.Request) error
ClearUserSession removes the current user from session
func DefaultCacheKey ¶
DefaultCacheKey returns default format for redis key
func GetCurrentUser ¶
GetCurrentUser returns current user based on the request header
func HandleLogout ¶
func HandleLogout(w http.ResponseWriter, request *http.Request)
HandleLogout let user logout from the system
func HandleQuery ¶
HandleQuery retrieves results filtered by request parameters
func InitSessionStore ¶
InitSessionStore initializes SharedSessionStore
func LoginWithPassword ¶
func LoginWithPassword( w http.ResponseWriter, request *http.Request, usernameCol string, passwordCol string) (interface{}, error)
LoginWithPassword checks if username and password correct and set user into session
func RedisClearAll ¶
func RedisClearAll() error
RedisClearAll clear all data from connection's CURRENT database
func RegisterModel ¶
func RegisterModel(resource interface{})
RegisterModel initializes default routes for a model
func RegisterWithPassword ¶
func RegisterWithPassword( w http.ResponseWriter, request *http.Request, usernameCol string, passwordCol string) (interface{}, error)
RegisterWithPassword checks if username exists and sets password with bcrypt algorithm Client can provides extra data to be saved into database for user
func SetUserModel ¶
func SetUserModel(user interface{})
SetUserModel lets goal which model act as user
func SetUserSession ¶
func SetUserSession(w http.ResponseWriter, req *http.Request, user interface{}) error
SetUserSession sets current user to session
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
An API manages a group of resources by routing requests to the correct method on a matching resource and marshalling the returned data to JSON for the HTTP response.
You can instantiate multiple APIs on separate ports. Each API will manage its own set of resources.
func (*API) AddCrudResource ¶
AddCrudResource adds a new resource to an API. The API will route requests that match one of the given paths to the matching HTTP method on the resource.
func (*API) AddDefaultAuthPaths ¶
func (api *API) AddDefaultAuthPaths(resource interface{})
AddDefaultAuthPaths route request to the model which implement authentications
func (*API) AddDefaultCrudPaths ¶
func (api *API) AddDefaultCrudPaths(resource interface{})
AddDefaultCrudPaths adds default path for a resource. The default path is based on the struct name
func (*API) AddDefaultQueryPath ¶
func (api *API) AddDefaultQueryPath(resource interface{})
AddDefaultQueryPath allows model to support query based on request data, return filtered results back to client. The path is created base on struct name
func (*API) AddLoginPath ¶
AddLoginPath let user login to system
func (*API) AddLogoutPath ¶
AddLogoutPath let user logout from the system
func (*API) AddQueryResource ¶
AddQueryResource allows model to support query based on request data, return filtered results back to client
func (*API) AddRegisterPath ¶
AddRegisterPath let user to register into a system
type Cacher ¶
type Cacher interface { Get(string, interface{}) error Set(string, interface{}) error Delete(string) error Exists(string) (bool, error) }
Cacher defines a interface for fast key-value caching
SharedCache is global variable to cache data
type DeleteSupporter ¶
type DeleteSupporter interface {
Delete(http.ResponseWriter, *http.Request) (int, interface{}, error)
}
DeleteSupporter is the interface that provides the Delete method a resource must support to receive HTTP DELETEs.
type GetSupporter ¶
GetSupporter is the interface that provides the Get method a resource must support to receive HTTP GETs.
type HeadSupporter ¶
HeadSupporter is the interface that provides the Head method a resource must support to receive HTTP HEADs.
type PatchSupporter ¶
type PatchSupporter interface {
Patch(http.ResponseWriter, *http.Request) (int, interface{}, error)
}
PatchSupporter is the interface that provides the Patch method a resource must support to receive HTTP PATCHs.
type Permission ¶
Permission makes it easier to implement access control
func (*Permission) PermitRead ¶
func (p *Permission) PermitRead() []string
PermitRead conforms to PermitReader interface
func (*Permission) PermitWrite ¶
func (p *Permission) PermitWrite() []string
PermitWrite conforms to PermitWriter interface
type PermitReader ¶
type PermitReader interface {
PermitRead() []string
}
PermitReader allows authenticated user to read the record
type PermitWriter ¶
type PermitWriter interface {
PermitWrite() []string
}
PermitWriter allows authenticated user to write the record
type PostSupporter ¶
PostSupporter is the interface that provides the Post method a resource must support to receive HTTP POSTs.
type PutSupporter ¶
PutSupporter is the interface that provides the Put method a resource must support to receive HTTP PUTs.
type QueryItem ¶
type QueryItem struct { Key string `json:"key"` Op string `json:"op"` Val interface{} `json:"val"` Or []*QueryItem `json:"or"` }
QueryItem defines most basic element of a query. For example: name = Thomas
type QueryParams ¶
type QueryParams struct { Where []*QueryItem `json:"where"` Limit int64 `json:"limit"` Order map[string]bool `json:"order"` Include []string `json:"include"` }
QueryParams defines structure of a query. Where clause may include multiple QueryItem and connect by "AND" operator
func (*QueryParams) Find ¶
func (params *QueryParams) Find(resource interface{}, results interface{}) error
Find constructs the query, return error immediately if query is invalid, and query database if everything is valid
type QuerySupporter ¶
type QuerySupporter interface {
Query(http.ResponseWriter, *http.Request) (int, interface{}, error)
}
QuerySupporter is the interface that return filtered results based on request paramters
type RedisCache ¶
type RedisCache struct{}
RedisCache implements Cacher interface
func (*RedisCache) Delete ¶
func (cache *RedisCache) Delete(key string) error
Delete a key from Redis
func (*RedisCache) Exists ¶
func (cache *RedisCache) Exists(key string) (bool, error)
Exists checks if a key exists inside Redis
func (*RedisCache) Get ¶
func (cache *RedisCache) Get(key string, val interface{}) error
Get returns data for a key
func (*RedisCache) InitRedisPool ¶
func (cache *RedisCache) InitRedisPool(p *redis.Pool) error
InitRedisPool initializes Redis and connection pool
func (*RedisCache) Set ¶
func (cache *RedisCache) Set(key string, val interface{}) error
Set a val for a key into Redis
type Registerer ¶
type Registerer interface {
Register(http.ResponseWriter, *http.Request) (int, interface{}, error)
}
Registerer register a new user to system
type Revisioner ¶
type Revisioner interface { CurrentRevision() int64 SetNextRevision() }
Revisioner tell the revision of current record. It is typically used to avoid data being overridden by multiple clients