core

package
v0.0.0-...-f265c88 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2015 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK             Status = "OK"
	StatusItemNotFound          = "ItemNotFound"
	StatusError                 = "Error"
	StatusQueryNotUnique        = "QueryNotUnique"
)

Variables

View Source
var (
	ResultOK = Result{Status: StatusOK, Result: nil, Error: nil}

	ErrorCmdNotFound    = errrs.New("Command not found!")
	ErrorNotAllowed     = errrs.New("You are not allowed to do that!")
	ErrorNotLoggedIn    = errrs.New("You are not allowed to do that; you need to be logged in!")
	ErrorNotImplemented = errrs.New("Sorry, this feature is not implemented yet.")
	ErrorUserNotFound   = errrs.New("User not found!")
	ErrorInvalidQuery   = errrs.New("Invalid Query!")
)

Functions

This section is empty.

Types

type ArgMap

type ArgMap map[string][]string

type AuthLevel

type AuthLevel uint
const (
	// Guests can only view public data
	AuthGuest AuthLevel = iota

	// Users can view and edit their own data
	AuthUser

	// Admins can edit other user data and most configuration
	AuthAdmin

	// Roots can edit all configuration, do database maintenance
	// and stop the server
	AuthRoot
)

type Command

type Command struct {
	Verbs        []string
	Description  string
	ArgsHelp     map[string]string
	MinAuthLevel AuthLevel
	Handler      func(ctx CommandContext) Result
}

type CommandContext

type CommandContext struct {
	Cmd  string // Command given
	Args ArgMap // arguments of the request

	AuthLevel AuthLevel // permission level of current user
	UserId    *int64    // logged in User ID or nil
}

type Core

type Core interface {
	Start() error
	Shutdown() error
	Version() string

	RegisterCommand(Command)
	UnregisterCommand(Command)
	CmdLine()
	Cmd(ctx CommandContext) Result
	IsCmdAllowed(level AuthLevel, cmd string) (bool, error)

	// Long-running jobs can use this method to register a shutdown handler.
	// Returned is a channel which should be listened on.
	//
	// When the core is shut down, it will first send a SignalTerminate to each
	// registered job, then wait a few seconds, and then send a SignalKill.
	// After the SignalKill is received, the goroutine will be killed.
	// If necessary, the killing can be delayed by not listening on the channel
	// anymore after receiving the SignalTerminate. Don't wait for too long,
	// though.
	RegisterJob() <-chan JobSignal

	// Use this to unregister your job once it's finished.
	UnregisterJob(job <-chan JobSignal)
}

type JobSignal

type JobSignal int
const (
	SignalNone JobSignal = iota
	SignalTerminate
	SignalKill
)

type Result

type Result struct {
	Status Status      `json:"status"`
	Result interface{} `json:"result,omitempty"`
	Error  error       `json:"error,omitempty"`
	IsRaw  bool        `json:"-"`
}

func ResultByError

func ResultByError(err error) Result

type Status

type Status string

Jump to

Keyboard shortcuts

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