httpapi

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(w io.Writer, config *api.AuthConfig, apikey string, s SessionStore, inventoryDB, skywardDB *sql.DB) http.Handler

NewRouter returns an HTTP router for the HTTP API

Types

type ErrorResponse

type ErrorResponse struct {
	Code        int    `json:"code"`
	Error       string `json:"error"`
	Description string `json:"description"`
}

ErrorResponse represents an HTTP error

type MemorySessionStore

type MemorySessionStore struct {
	// contains filtered or unexported fields
}

MemorySessionStore represents a SessionStore that uses an in-memory map

func NewMemorySessionStore

func NewMemorySessionStore(duration time.Duration) *MemorySessionStore

NewMemorySessionStore returns a new MemorySessionStore with the given expiration duration.

func (*MemorySessionStore) Check

func (m *MemorySessionStore) Check(sessionID string) (session *Session, err error)

Check returns whether or not sessionID is a valid session. If sessionID is not valid, session will be nil. err will always be nil.

func (*MemorySessionStore) Create

func (m *MemorySessionStore) Create(user *api.User) (sessionID string, err error)

Create returns a new sessionID with the given User. err will always be nil.

type Session

type Session struct {
	User    *api.User
	Expires time.Time
}

Session represents a login session

type SessionStore

type SessionStore interface {
	//Create returns a new sessionID with the given User. If the backend malfunctions,
	//sessionID will be an empty string and err will be non-nil.
	Create(user *api.User) (sessionID string, err error)

	//Check returns whether or not sessionID is a valid session.
	//If sessionID is not valid, session will be nil.
	//If the backend malfunctions, session will be nil and err will be non-nil.
	Check(sessionID string) (session *Session, err error)
}

SessionStore is an interface to an arbitrary session backend.

Jump to

Keyboard shortcuts

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