ctp

package
v0.0.0-...-064bbc6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2016 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

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 BearerAuth

func BearerAuth(r *http.Request) (token string, ok bool)

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(link Link) bool

func IsValidIdentifier

func IsValidIdentifier(id string) bool

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 MatchTags

func MatchTags(src_tags, dst_tags Tags) bool
func ParseLink(baseURI Link, format string, link Link) ([]string, bool)

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 RequestSignature(prefix string, r *http.Request) (signature string, params []string, querystring_x string)

func SecondsSince

func SecondsSince(t Timestamp) int64

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 Base64Id

type Base64Id string

func NewBase64Id

func NewBase64Id() Base64Id

func (*Base64Id) String

func (id *Base64Id) String() string

type BoolErr

type BoolErr int
const (
	Tfalse BoolErr = iota
	Ttrue
	Terror
)

func ToBoolErr

func ToBoolErr(b bool) BoolErr

func (BoolErr) MarshalJSON

func (t BoolErr) MarshalJSON() ([]byte, error)

func (BoolErr) String

func (t BoolErr) String() string

func (*BoolErr) UnmarshalJSON

func (t *BoolErr) UnmarshalJSON(js []byte) error

type Configuration

type Configuration map[string]string

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 Duration

type Duration int64

type GETHandler

type GETHandler struct {
	AccessTags Tags
	ShowTags   bool
}

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 NewBadRequestErrorf(format string, params ...interface{}) *HttpError

func NewHttpError

func NewHttpError(code int, msg interface{}) *HttpError

func NewHttpErrorf

func NewHttpErrorf(code int, format string, params ...interface{}) *HttpError

func NewInternalServerError

func NewInternalServerError(msg interface{}) *HttpError

func NewInternalServerErrorf

func NewInternalServerErrorf(format string, params ...interface{}) *HttpError

func NewNotFoundError

func NewNotFoundError(msg interface{}) *HttpError

func NewNotFoundErrorf

func NewNotFoundErrorf(format string, params ...interface{}) *HttpError

func (*HttpError) Error

func (e *HttpError) Error() string

func (*HttpError) StatusCode

func (e *HttpError) StatusCode() int
type Link string
func ExpandLink(baseURI Link, link Link) Link
func NewLink(baseURI Link, format string, params ...interface{}) Link
func ShortenLink(baseURI Link, link Link) Link

type LogLevel

type LogLevel uint
const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
)

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 NamedResource struct {
	Resource   `bson:",inline"`
	Name       string `json:"name" bson:"name"`
	Annotation string `json:"annotation" bson:"annotation"`
}

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

type PUTHandler struct {
	AccessTags Tags
	ShowTags   bool
}

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"`
}

func (*Resource) Super

func (r *Resource) Super() *Resource

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 SessionId

type SessionId uint

type Tags

type Tags []string

func NewTags

func NewTags(tags ...string) Tags

func (*Tags) Append

func (t *Tags) Append(tags Tags)

func (Tags) HasWildcard

func (t Tags) HasWildcard() bool

func (Tags) String

func (t Tags) String() string

func (Tags) WithPrefix

func (t Tags) WithPrefix(prefix string) []string

type Timestamp

type Timestamp int64

func Now

func Now() Timestamp

func ParseTimestamp

func ParseTimestamp(str string) (Timestamp, error)

func (Timestamp) GetBSON

func (t Timestamp) GetBSON() (interface{}, error)

func (Timestamp) IsZero

func (t Timestamp) IsZero() bool

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) SetBSON

func (t *Timestamp) SetBSON(raw bson.Raw) error

func (Timestamp) String

func (t Timestamp) String() string

func (Timestamp) Time

func (t Timestamp) Time() time.Time

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL