Documentation
¶
Index ¶
- Variables
- func BearerAuth(r *http.Request) (token string, ok bool)
- func CreateResource(c *ApiContext, category string, resource interface{}) bool
- func DeleteResource(c *ApiContext, category string, id Base64Id) bool
- func HandleNotImplemented(w http.ResponseWriter, r *http.Request, context *ApiContext)
- func IsMongoRunning(conf Configuration) bool
- func IsShortLink(link Link) bool
- func IsValidIdentifier(id string) bool
- func LoadResource(c *ApiContext, category string, id Base64Id, resource interface{}) bool
- func Log(c *ApiContext, level LogLevel, format string, v ...interface{})
- func MatchTags(src_tags, dst_tags Tags) bool
- func ParseLink(baseURI Link, format string, link Link) ([]string, bool)
- func ParseResource(body io.ReadCloser, resource interface{}) error
- func RenderErrorResponse(w http.ResponseWriter, context *ApiContext, err *HttpError)
- func RenderJsonResponse(w http.ResponseWriter, context *ApiContext, code int, item interface{})
- func RequestSignature(prefix string, r *http.Request) (signature string, params []string, querystring_x string)
- func SecondsSince(t Timestamp) int64
- func UpdateResource(c *ApiContext, category string, id Base64Id, resource interface{}) bool
- func UpdateResourcePart(c *ApiContext, category string, id Base64Id, part string, resource interface{}) bool
- type Account
- type ApiContext
- type Base64Id
- type BoolErr
- type Configuration
- type DELETEHandler
- type Duration
- type GETHandler
- type HandlerFunc
- type HttpError
- func NewBadRequestError(msg interface{}) *HttpError
- func NewBadRequestErrorf(format string, params ...interface{}) *HttpError
- func NewHttpError(code int, msg interface{}) *HttpError
- func NewHttpErrorf(code int, format string, params ...interface{}) *HttpError
- func NewInternalServerError(msg interface{}) *HttpError
- func NewInternalServerErrorf(format string, params ...interface{}) *HttpError
- func NewNotFoundError(msg interface{}) *HttpError
- func NewNotFoundErrorf(format string, params ...interface{}) *HttpError
- type Link
- type LogLevel
- type MeasurementState
- type NamedResource
- type POSTHandler
- type PUTHandler
- type Resource
- type ResourceCreator
- type ResourceDeleter
- type ResourceLoader
- type ResourceUpdater
- type SessionId
- type Tags
- type Timestamp
- func (t Timestamp) GetBSON() (interface{}, error)
- func (t Timestamp) IsZero() bool
- func (t Timestamp) MarshalJSON() ([]byte, error)
- func (t *Timestamp) SetBSON(raw bson.Raw) error
- func (t Timestamp) String() string
- func (t Timestamp) Time() time.Time
- func (t *Timestamp) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( UserRoleTag = NewTags("role:user") AgentRoleTag = NewTags("role:agent") AdminRoleTag = NewTags("role:admin") )
View Source
var ConfigurationDefaults = Configuration{
"listen": ":8080",
"basepath": "/api/1.0/",
"databaseurl": "localhost",
}
Functions ¶
func CreateResource ¶
func CreateResource(c *ApiContext, category string, resource interface{}) bool
func DeleteResource ¶
func DeleteResource(c *ApiContext, category string, id Base64Id) bool
func HandleNotImplemented ¶
func HandleNotImplemented(w http.ResponseWriter, r *http.Request, context *ApiContext)
func IsMongoRunning ¶
func IsMongoRunning(conf Configuration) bool
func IsShortLink ¶
func IsValidIdentifier ¶
func LoadResource ¶
func LoadResource(c *ApiContext, category string, id Base64Id, resource interface{}) bool
func Log ¶
func Log(c *ApiContext, level LogLevel, format string, v ...interface{})
func ParseResource ¶
func ParseResource(body io.ReadCloser, resource interface{}) error
func RenderErrorResponse ¶
func RenderErrorResponse(w http.ResponseWriter, context *ApiContext, err *HttpError)
func RenderJsonResponse ¶
func RenderJsonResponse(w http.ResponseWriter, context *ApiContext, code int, item interface{})
func RequestSignature ¶
func SecondsSince ¶
func UpdateResource ¶
func UpdateResource(c *ApiContext, category string, id Base64Id, resource interface{}) bool
func UpdateResourcePart ¶
func UpdateResourcePart(c *ApiContext, category string, id Base64Id, part string, resource interface{}) bool
Types ¶
type Account ¶
type Account struct { NamedResource `bson:",inline"` AccountTags Tags `json:"accountTags" bson:"accountTags"` Token string `json:"token" bson:"token"` }
type ApiContext ¶
type ApiContext struct { Configuration Configuration CtpBase Link CtpPath string Signature string Params []string QueryParam string Id SessionId Session *mgo.Session AccountTags Tags ColorLogs bool DebugVM bool }
func NewApiContext ¶
func NewApiContext(r *http.Request, conf Configuration) (*ApiContext, error)
func (*ApiContext) AuthenticateClient ¶
func (c *ApiContext) AuthenticateClient(w http.ResponseWriter, r *http.Request) bool
func (*ApiContext) Close ¶
func (c *ApiContext) Close()
func (*ApiContext) VerifyAccessTags ¶
func (c *ApiContext) VerifyAccessTags(w http.ResponseWriter, dest Tags) bool
type Configuration ¶
func LoadConfigurationFromFile ¶
func LoadConfigurationFromFile(fname string) (Configuration, bool)
func SearchAndLoadConfigurationFile ¶
func SearchAndLoadConfigurationFile() (Configuration, bool)
type DELETEHandler ¶
type DELETEHandler struct {
AccessTags Tags
}
func NewDELETEHandler ¶
func NewDELETEHandler(a Tags) *DELETEHandler
func (*DELETEHandler) Handle ¶
func (handler *DELETEHandler) Handle(w http.ResponseWriter, r *http.Request, context *ApiContext, resource ResourceDeleter)
type GETHandler ¶
func NewGETHandler ¶
func NewGETHandler(a Tags) *GETHandler
func (*GETHandler) Handle ¶
func (handler *GETHandler) Handle(w http.ResponseWriter, r *http.Request, context *ApiContext, res ResourceLoader)
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request, *ApiContext)
type HttpError ¶
type HttpError struct {
// contains filtered or unexported fields
}
func NewBadRequestError ¶
func NewBadRequestError(msg interface{}) *HttpError
func NewBadRequestErrorf ¶
func NewHttpError ¶
func NewHttpErrorf ¶
func NewInternalServerError ¶
func NewInternalServerError(msg interface{}) *HttpError
func NewInternalServerErrorf ¶
func NewNotFoundError ¶
func NewNotFoundError(msg interface{}) *HttpError
func NewNotFoundErrorf ¶
func (*HttpError) StatusCode ¶
type MeasurementState ¶
type MeasurementState string
func (MeasurementState) IsValid ¶
func (s MeasurementState) IsValid() bool
func (*MeasurementState) UnmarshalJSON ¶
func (s *MeasurementState) UnmarshalJSON(js []byte) error
type NamedResource ¶
type POSTHandler ¶
type POSTHandler struct {
AccessTags Tags
}
func NewPOSTHandler ¶
func NewPOSTHandler(a Tags) *POSTHandler
func (*POSTHandler) Handle ¶
func (handler *POSTHandler) Handle(w http.ResponseWriter, r *http.Request, context *ApiContext, res ResourceCreator)
type PUTHandler ¶
func NewPUTHandler ¶
func NewPUTHandler(a Tags) *PUTHandler
func (*PUTHandler) Handle ¶
func (handler *PUTHandler) Handle(w http.ResponseWriter, r *http.Request, context *ApiContext, resource ResourceUpdater, update ResourceUpdater)
type Resource ¶
type Resource struct { Id Base64Id `json:"-" bson:"_id,omitempty"` Parent []Base64Id `json:"-" bson:"parent,omitempty"` Self Link `json:"self" bson:"-"` Scope Link `json:"scope,omitempty" bson:"-"` AccessTags Tags `json:"accessTags,omitempty" bson:"accessTags"` ChangeId Base64Id `json:"changeId,omitempty" bson:"changeId,omitempty"` }
type ResourceCreator ¶
type ResourceCreator interface { Super() *Resource Create(*ApiContext) *HttpError }
type ResourceDeleter ¶
type ResourceDeleter interface { Super() *Resource Delete(*ApiContext) *HttpError }
type ResourceLoader ¶
type ResourceLoader interface { Super() *Resource Load(*ApiContext) *HttpError }
type ResourceUpdater ¶
type ResourceUpdater interface { Super() *Resource Update(*ApiContext, ResourceUpdater) *HttpError }
type Timestamp ¶
type Timestamp int64
func ParseTimestamp ¶
func (Timestamp) MarshalJSON ¶
func (*Timestamp) UnmarshalJSON ¶
Click to show internal directories.
Click to hide internal directories.