Documentation ¶
Overview ¶
Package server provides an HTTP interface for the job queue/scheduler.
Example ¶
package main import ( "net/http" "github.com/kevinburke/rest/resterror" ) type auther struct{} func (a *auther) Authorize(userId, token string) *resterror.Error { // Implement your auth scheme here. return nil } func main() { // Get all server routes using your authorization handler, then listen on // port 9090 handler := Get(Config{Auth: &auther{}}) http.ListenAndServe(":9090", handler) }
Output:
Index ¶
- Constants
- Variables
- func AddUser(user string, password string)
- func Get(c Config) http.Handler
- func New(ctx context.Context, cfg Config) (http.Handler, error)
- func V2(db *newmodels.Queries, test bool) http.Handler
- type Authorizer
- type Config
- type CreateJobRequestdeprecated
- type EnqueueJobRequestdeprecated
- type JobStatusRequest
- type SharedSecretAuthorizer
- type UnsafeBypassAuthorizer
Examples ¶
Constants ¶
const MAX_ENQUEUE_DATA_SIZE = 100 * 1024
The maximum data size that can be sent in the body of a HTTP request.
Variables ¶
var DefaultAuthorizer = NewSharedSecretAuthorizer()
var DefaultServer http.Handler
DefaultServer serves every route using the DefaultAuthorizer for authentication.
var Logger = handlers.Logger
Functions ¶
func AddUser ¶
AddUser tells the DefaultAuthorizer that a given user and password is allowed to access the API.
func Get ¶
Get returns a http.Handler with all routes initialized using the given Authorizer. Get assumes that setup.DB has been called; to call both use New.
Types ¶
type Authorizer ¶
type Authorizer interface { // Authorize returns nil if the user and token are allowed to access the // API, and a resterror.Error otherwise. The rest.Error will be returned as the // body of a 401 HTTP response. Authorize(user string, token string) *resterror.Error }
The Authorizer interface can be used to authorize a given user and token to access the API.
type Config ¶
type Config struct { // Authorizer to use. If nil, DefaultAuthorizer is used. Auth Authorizer // Database connector, for example db.DatabaseURLConnector. If nil, // db.DefaultConnection is used. Connector db.Connector // Number of open connections to the database NumConns int // Enqueueing a job with name "meta.shutdown" will shutdown the dequeuer (so // it can be restarted with a job type added or removed). // // Enable this flag if you have long running jobs that could be interfered // with if the dequeuer restarted. DisableMetaShutdown bool // In test mode, do some things synchronously that would otherwise be done // in a background goroutine. Test bool }
type CreateJobRequest
deprecated
type CreateJobRequest = httptypes.CreateJobTypeRequest
Deprecated: Use httptypes.CreateJobTypeRequest instead.
type EnqueueJobRequest
deprecated
type EnqueueJobRequest = httptypes.EnqueueJobRequest
Deprecated: use httptypes.EnqueueJobRequest instead.
type JobStatusRequest ¶
type JobStatusRequest = httptypes.JobStatusRequest
type SharedSecretAuthorizer ¶
type SharedSecretAuthorizer struct {
// contains filtered or unexported fields
}
SharedSecretAuthorizer uses an in-memory map of usernames and passwords to authenticate incoming requests.
func NewSharedSecretAuthorizer ¶
func NewSharedSecretAuthorizer() *SharedSecretAuthorizer
NewSharedSecretAuthorizer creates a SharedSecretAuthorizer ready for use.
func (*SharedSecretAuthorizer) AddUser ¶
func (ssa *SharedSecretAuthorizer) AddUser(userId string, password string)
AddUser authorizes a given user and password to access the API.
type UnsafeBypassAuthorizer ¶
type UnsafeBypassAuthorizer struct{}
Use this if you need to bypass the API authorization scheme.