server

package
v0.0.0-...-7ed8402 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 35 Imported by: 1

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

Examples

Constants

View Source
const MAX_ENQUEUE_DATA_SIZE = 100 * 1024

The maximum data size that can be sent in the body of a HTTP request.

Variables

View Source
var DefaultAuthorizer = NewSharedSecretAuthorizer()
View Source
var DefaultServer http.Handler

DefaultServer serves every route using the DefaultAuthorizer for authentication.

View Source
var Logger = handlers.Logger

Functions

func AddUser

func AddUser(user string, password string)

AddUser tells the DefaultAuthorizer that a given user and password is allowed to access the API.

func Get

func Get(c Config) http.Handler

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.

func New

func New(ctx context.Context, cfg Config) (http.Handler, error)

New initializes the database connection and returns a http.Handler that can run the server.

func V2

func V2(db *newmodels.Queries, test bool) http.Handler

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.

func (*SharedSecretAuthorizer) Authorize

func (c *SharedSecretAuthorizer) Authorize(userId string, token string) *resterror.Error

Authorize returns nil if the userId and token have been added to c, and a resterror.Error if they are not allowed to access the API.

type UnsafeBypassAuthorizer

type UnsafeBypassAuthorizer struct{}

Use this if you need to bypass the API authorization scheme.

func (*UnsafeBypassAuthorizer) Authorize

func (u *UnsafeBypassAuthorizer) Authorize(userId string, token string) *resterror.Error

Jump to

Keyboard shortcuts

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