api

package
v3.0.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHTTPRouter

func MakeHTTPRouter(db lurkcoin.Database, config *Config) *httprouter.Router

func OpenDatabase

func OpenDatabase(config *Config) (lurkcoin.Database, error)

func StartServer

func StartServer(config *Config)

Types

type AdminLoginDetails

type AdminLoginDetails map[string]struct {
	PasswordHash          string `yaml:"password_hash"`
	HashAlgorithm         string `yaml:"hash_algorithm"`
	PasswordSalt          string `yaml:"password_salt"`
	AllowEditing          bool   `yaml:"allow_editing"`
	AllowDatabaseDownload bool   `yaml:"allow_database_download"`
}

func (AdminLoginDetails) Validate

func (self AdminLoginDetails) Validate(username, password string) bool

TODO: Provide a more secure hashing function.

type Config

type Config struct {
	// The name of this service (for example "lurkcoin"). This is also used as
	// the default server name for the v2 API.
	Name string `yaml:"name"`

	// The network protocol to use when binding to the socket. Defaults to
	// "tcp", can be set to "unix" for example.
	NetworkProtocol string `yaml:"network_protocol"`

	// The address to bind to (optional) and port.
	Address string `yaml:"address"`
	Port    uint16 `yaml:"port"`

	// An optional logfile
	Logfile string `yaml:"logfile"`

	Database struct {
		Type     string            `yaml:"type"`
		Location string            `yaml:"location"`
		Options  map[string]string `yaml:"options"`
	} `yaml:"database"`

	// TLS
	TLS struct {
		Enable   bool   `yaml:"enable"`
		CertFile string `yaml:"cert_file"`
		KeyFile  string `yaml:"key_file"`
	} `yaml:"tls"`

	// Admin pages
	AdminPages struct {
		Enable bool              `yaml:"enable"`
		Users  AdminLoginDetails `yaml:"users"`
	} `yaml:"admin_pages"`

	// HTTP redirects
	Redirects map[string]string `yaml:"redirects"`

	// The minimum HTTPS API version to support.
	MinAPIVersion uint8 `yaml:"min_api_version"`

	// Suppresses any HTTP-related logs such as TLS handshake errors.
	SuppressHTTPLogs bool `yaml:"suppress_http_logs"`

	// Disables HTTP keep-alives.
	DisableHTTPKeepAlives bool `yaml:"disable_http_keepalives"`
}

func LoadConfig

func LoadConfig(filename string) (*Config, error)

type HTTPHandler

type HTTPHandler func(*HTTPRequest) (interface{}, error)

type HTTPRequest

type HTTPRequest struct {
	Server        *lurkcoin.Server
	Database      lurkcoin.Database
	DbTransaction *lurkcoin.DatabaseTransaction
	Request       *http.Request
	Params        httprouter.Params
}

A HTTP server wrapper

func MakeHTTPRequest

func MakeHTTPRequest(db lurkcoin.Database, request *http.Request, params httprouter.Params) *HTTPRequest

func (*HTTPRequest) AbortTransaction

func (self *HTTPRequest) AbortTransaction()

func (*HTTPRequest) Authenticate

func (self *HTTPRequest) Authenticate(otherServers ...string) error

func (*HTTPRequest) AuthenticateV2

func (self *HTTPRequest) AuthenticateV2(query v2Form, otherServers ...string) error

func (*HTTPRequest) FinishTransaction

func (self *HTTPRequest) FinishTransaction()

func (*HTTPRequest) Unmarshal

func (self *HTTPRequest) Unmarshal(v interface{}) error

Unmarshals JSON sent in the HTTP request into v.

Jump to

Keyboard shortcuts

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