serve

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultInsecureSecret = "They're all gonna laugh at you!"

DefaultInsecureSecret is the hash secret used if couch_httpd_auth.secret is unconfigured. Please configure couch_httpd_auth.secret, or they're all gonna laugh at you!

View Source
const DefaultSessionTimeout = 600

DefaultSessionTimeout is the default session timeout, in seconds, used if couch_httpd_auth.timeout is inuset.

Variables

View Source
var (
	// SessionKey is a context key used to access the authenticated session.
	SessionKey = &contextKey{"session"}
	// ClientContextKey is a context key used to access the kivik client.
	ClientContextKey = &contextKey{"client"}
	// ServiceContextKey is a context key used to access the serve.Service struct.
	ServiceContextKey = &contextKey{"service"}
)

Functions

func BindParams

func BindParams(r *http.Request, i interface{}) error

BindParams binds the request form or JSON body to the provided struct.

func DecodeCookie

func DecodeCookie(cookie string) (name string, created int64, err error)

DecodeCookie decodes a Base64-encoded cookie, and returns its component parts.

func MustGetSession

func MustGetSession(ctx context.Context) *auth.Session

MustGetSession returns the user context for the currently authenticated user. If no session is set, the function panics.

func StringQueryParam

func StringQueryParam(r *http.Request, key string) (string, bool)

StringQueryParam extracts a query parameter as string.

Types

type Service

type Service struct {
	// Client is an instance of a driver.Client, which will be served.
	Client *kivik.Client
	// UserStore provides access to the user database. This is passed to auth
	// handlers, and is used to authenticate sessions. If unset, a nil UserStore
	// will be used which authenticates all uses. PERPETUAL ADMIN PARTY!
	UserStore authdb.UserStore
	// AuthHandler is a slice of authentication handlers. If no auth
	// handlers are configured, the server will operate as a PERPETUAL
	// ADMIN PARTY!
	AuthHandlers []auth.Handler
	// CompatVersion is the compatibility version to report to clients. Defaults
	// to 1.6.1.
	CompatVersion string
	// VendorVersion is the vendor version string to report to clients. Defaults to the library
	// version.
	VendorVersion string
	// VendorName is the vendor name string to report to clients. Defaults to the library
	// vendor string.
	VendorName string
	// Favicon is the path to a file to serve as favicon.ico. If unset, a default
	// image is used.
	Favicon string
	// RequestLogger receives logging information for each request.
	RequestLogger logger.RequestLogger

	// ConfigFile is the path to a config file to read during startup.
	ConfigFile string

	// Config is a complete config object. If this is set, config loading is
	// bypassed.
	Config *conf.Conf
	// contains filtered or unexported fields
}

Service defines a CouchDB-like service to serve. You will define one of these per server endpoint.

func GetService

func GetService(r *http.Request) *Service

GetService extracts the Kivik service from the request.

func (*Service) Bind

func (s *Service) Bind(addr string) error

Bind sets the HTTP daemon bind address and port.

func (*Service) Conf

func (s *Service) Conf() *conf.Conf

Conf returns the initialized server configuration.

func (*Service) CreateAuthToken

func (s *Service) CreateAuthToken(ctx context.Context, name, salt string, time int64) (string, error)

CreateAuthToken hashes a user name, salt, timestamp, and the server secret into an authentication token.

func (*Service) Init

func (s *Service) Init() (http.Handler, error)

Init initializes a configured server. This is automatically called when Start() is called, so this is meant to be used if you want to bind the server yourself.

func (*Service) Start

func (s *Service) Start() error

Start begins serving connections.

func (*Service) ValidateCookie

func (s *Service) ValidateCookie(ctx context.Context, user *authdb.UserContext, cookie string) (bool, error)

ValidateCookie validates a cookie against a user context.

Directories

Path Synopsis
Package couchserver aims to provide a CouchDB-compatible HTTP server interface to a kivik.Client.
Package couchserver aims to provide a CouchDB-compatible HTTP server interface to a kivik.Client.

Jump to

Keyboard shortcuts

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