gaecontext

package
v0.0.0-...-f39a356 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: GPL-2.0, GPL-2.0 Imports: 17 Imported by: 7

Documentation

Index

Constants

View Source
const (
	GAEContextCounterKind = "GAEContextCounterKind"
)

Variables

This section is empty.

Functions

func AcquireSequence

func AcquireSequence(c GAEContext, name string, size int) (first int64, err error)

func AcquireSequenceNo

func AcquireSequenceNo(c GAEContext, name string) (result int64, err error)

AcquireSequenceNo will return the next number in the named sequence.

func CallTransactionFunction

func CallTransactionFunction(c GAEContext, f interface{}) (err error)

CallTransactionFunction will validate that f takes something that implements a GAEContext, and that it returns an error. Then it will call f with c and return the error.

func DataHandlerFunc

func DataHandlerFunc(f func(c HTTPContext) (resp *httpcontext.DataResp, err error), scopes ...string) http.Handler

DataHandlerFunc creates an http.Handler out of a function that takes an HTTPContext and returns a *httpcontext.DataResp.

Requests without tokens, or with tokens without one of the provided scopes, will receive a 401 status unless the scopes slice is empty.

For all your tabular data generation needs.

func DocHandle

func DocHandle(router *mux.Router, f interface{}, path string, method string, minAPIVersion, maxAPIVersion int, scopes ...string)

DocHandle registeres a path/method/api version route in the provided router, handled by the provided f, wrapping it in appstats.NewHandler, registering the f-function and its route with jsoncontext.Document and then using jsoncontext.Handle to do something that acts like JSONHandlerFunc.

func HTTPHandlerFunc

func HTTPHandlerFunc(f func(c HTTPContext) error, scopes ...string) http.Handler

HTTPHandlerFunc creates an http.Handler out of a function that takes a HTTPContext.

Requests without tokens, or with tokens without one of the provided scopes, will receive a 401 status unless the scopes slice is empty.

For all your basic HTTP needs.

func JSONHandlerFunc

func JSONHandlerFunc(f func(c JSONContext) (resp jsoncontext.Resp, err error), minAPIVersion, maxAPIVersion int, scopes ...string) http.Handler

JSONHandlerFunc creates an http.Handler out of a function that takes a JSONContext.

Requests without tokens, or with tokens without one of the provided scopes, will receive a 401 status unless the scopes slice is empty.

For all your JSON API needs.

func KindsRenderer

func KindsRenderer(c JSONContext) (status int, result []string, err error)

func ServiceStatusRenderer

func ServiceStatusRenderer(ok4xxRatio, ok5xxRatio float64) func(c JSONContext) (status int, result *ServiceStatus, err error)

Types

type Counter

type Counter struct {
	Count int64
}

type DefaultContext

type DefaultContext struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(gaeCont context.Context) (result *DefaultContext)

func (*DefaultContext) AfterCreate

func (self *DefaultContext) AfterCreate(i interface{}) error

func (*DefaultContext) AfterDelete

func (self *DefaultContext) AfterDelete(i interface{}) error

func (*DefaultContext) AfterLoad

func (self *DefaultContext) AfterLoad(i interface{}) error

func (*DefaultContext) AfterSave

func (self *DefaultContext) AfterSave(i interface{}) error

Implement all the hook functions required by Context

func (*DefaultContext) AfterTransaction

func (self *DefaultContext) AfterTransaction(f interface{}) (err error)

AfterTransaction will call f directly if self is not currently running a transaction, otherwise it will be appended to a slice of funcs run after every transaction is finished.

func (*DefaultContext) AfterUpdate

func (self *DefaultContext) AfterUpdate(i interface{}) error

func (*DefaultContext) BeforeCreate

func (self *DefaultContext) BeforeCreate(i interface{}) error

func (*DefaultContext) BeforeDelete

func (self *DefaultContext) BeforeDelete(i interface{}) error

func (*DefaultContext) BeforeSave

func (self *DefaultContext) BeforeSave(i interface{}) error

func (*DefaultContext) BeforeUpdate

func (self *DefaultContext) BeforeUpdate(i interface{}) error

func (*DefaultContext) Client

func (self *DefaultContext) Client() *http.Client

Client will return an *http.Client with a nice Transport wrapper.

func (*DefaultContext) ClientTimeout

func (self *DefaultContext) ClientTimeout(d time.Duration)

func (*DefaultContext) Criticalf

func (self *DefaultContext) Criticalf(format string, i ...interface{})

func (*DefaultContext) Debugf

func (self *DefaultContext) Debugf(format string, i ...interface{})

func (*DefaultContext) Errorf

func (self *DefaultContext) Errorf(format string, i ...interface{})

func (*DefaultContext) GetAllowHTTPDuringTransactions

func (self *DefaultContext) GetAllowHTTPDuringTransactions() bool

func (*DefaultContext) InTransaction

func (self *DefaultContext) InTransaction() bool

func (*DefaultContext) Infof

func (self *DefaultContext) Infof(format string, i ...interface{})

func (*DefaultContext) SetAllowHTTPDuringTransactions

func (self *DefaultContext) SetAllowHTTPDuringTransactions(b bool)

func (*DefaultContext) Transaction

func (self *DefaultContext) Transaction(f interface{}, crossGroup bool) (err error)

Transaction will run f inside a transaction, optionally crossGroup (more than 1 but LESS THAN FIVE entity groups involved).

If it fails due to other concurrent transactions, it will retry this transaction up until 20 seconds have passed.

func (*DefaultContext) Warningf

func (self *DefaultContext) Warningf(format string, i ...interface{})

type DefaultHTTPContext

type DefaultHTTPContext struct {
	GAEContext
	httpcontext.HTTPContext
}

func NewHTTPContext

func NewHTTPContext(gaeCont context.Context, httpCont httpcontext.HTTPContext) (result *DefaultHTTPContext)

func (*DefaultHTTPContext) Transaction

func (self *DefaultHTTPContext) Transaction(f interface{}, crossGroup bool) error

type DefaultJSONContext

type DefaultJSONContext struct {
	GAEContext
	jsoncontext.JSONContext
}

func NewJSONContext

func NewJSONContext(gaeCont context.Context, jsonCont jsoncontext.JSONContext) (result *DefaultJSONContext)

func (*DefaultJSONContext) Transaction

func (self *DefaultJSONContext) Transaction(f interface{}, crossGroup bool) error

type ErrLockTaken

type ErrLockTaken struct {
	Key    key.Key
	Entity key.Key
	Stack  string
}

func (ErrLockTaken) Error

func (self ErrLockTaken) Error() string

func (ErrLockTaken) GetStack

func (self ErrLockTaken) GetStack() string

type GAEContext

type GAEContext interface {
	gae.PersistenceContext
	Transaction(trans interface{}, crossGroup bool) error
	GetAllowHTTPDuringTransactions() bool
	SetAllowHTTPDuringTransactions(b bool)
	Client() *http.Client
	ClientTimeout(time.Duration)
}

type HTTPContext

type HTTPContext interface {
	GAEContext
	httpcontext.HTTPContext
}

type JSONContext

type JSONContext interface {
	GAEContext
	jsoncontext.JSONContext
}

type KeyLock

type KeyLock struct {
	// Id must be created based on the value you want to lock.
	Id key.Key `datastore:"-"`
	// Entity is the id of the holder of the lock.
	Entity key.Key
}

KeyLock is a generic way of locking certain values for entities without needing the entities have that value in their key.

func (*KeyLock) Lock

func (self *KeyLock) Lock(c GAEContext) error

Lock will try to lock this KeyLock and make its Id (and the value it is based on) unavailable for other locks.

func (*KeyLock) LockedBy

func (self *KeyLock) LockedBy(c GAEContext) (isLocked bool, lockedBy key.Key, err error)

LockedBy will return whether this KeyLock is actually locked in the database and who holds it now.

func (*KeyLock) Unlock

func (self *KeyLock) Unlock(c GAEContext) (err error)

Unlock will unlock this KeyLock and make its Id (and the value it is based on) available for other locks.

type ServiceStatus

type ServiceStatus struct {
	Status    string        `json:"status"`
	Status5xx string        `json:"status_5xx"`
	Status4xx string        `json:"status_4xx"`
	LogStats  *gae.LogStats `json:"log_stats"`
	Desc      string        `json:"desc"`
}

type Transport

type Transport struct {
	T      urlfetch.Transport
	Header http.Header
}

Transport is a wrapper around another transport, that adds headers, refuses to function inside transactions (unless explicitly told so) and warns if the response is too slow or produces a 5xx status

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (res *http.Response, err error)

Jump to

Keyboard shortcuts

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