server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseMiddleware

func DatabaseMiddleware(server *Server, forceDBE bool) heligo.Middleware

func GenerateToken

func GenerateToken(role, secret string) (string, error)

func HTTPLogger

func HTTPLogger(logger *logging.Logger) heligo.Middleware

func ReadInputRecords

func ReadInputRecords(r heligo.Request) ([]database.Record, error)

func ReleaseSession

func ReleaseSession(ctx context.Context, status int, server *Server, session *Session)

func TableCreateHandler

func TableCreateHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func TableListHandler

func TableListHandler(c context.Context, w http.ResponseWriter, r heligo.Request) (int, error)

func WriteBadRequest

func WriteBadRequest(w http.ResponseWriter, err error) (int, error)

func WriteEmpty

func WriteEmpty(w http.ResponseWriter, status int) (int, error)

func WriteError

func WriteError(w http.ResponseWriter, err error) (int, error)

func WriteJSON

func WriteJSON[O any](w http.ResponseWriter, status int, obj O) (int, error)

func WriteJSONString

func WriteJSONString(w http.ResponseWriter, status int, json []byte) (int, error)

func WriteServerError

func WriteServerError(w http.ResponseWriter, err error) (int, error)

Types

type Claims

type Claims struct {
	Role string `json:"role"`
	Id   string `json:"id"`
	jwt.RegisteredClaims
}

type Config

type Config struct {
	Address          string          `comment:"Server address and port (default localhost:8082)"`
	AllowAnon        bool            `comment:"Allow unauthenticated connections"`
	JWTSecret        string          `comment:"Secret for JWT tokens"`
	EnableAdminRoute bool            `comment:"Enable administration of databases and tables"`
	SessionMode      string          `comment:"Session mode: none, role (default: role)"`
	BaseAPIURL       string          `comment:"Base URL for the API (default: /api)"`
	BaseAdminURL     string          `comment:"Base URL for the Admin API (default: /admin)"`
	Database         database.Config `comment:"Database configuration"`
	Logging          logging.Config  `comment:"Logging configuration"`
}

Config holds the current configuration

type ConfigOptions

type ConfigOptions struct {
	ConfigFilePath string
	SkipFlags      bool
	SkipEnv        bool
}

type Data

type Data map[string]any

type Server

type Server struct {
	Config *Config
	Logger *logging.Logger
	DBE    *database.DbEngine
	HTTP   *http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer() (*Server, error)

func NewServerWithConfig

func NewServerWithConfig(config map[string]any, configOpts *ConfigOptions) (*Server, error)

func (*Server) GetRouter

func (server *Server) GetRouter() *heligo.Router

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

func (*Server) Start

func (s *Server) Start() error

type Session

type Session struct {
	Claims     *Claims
	LastUsedAt time.Time
	Db         *database.Database
	DbConn     *database.DbPoolConn
	// contains filtered or unexported fields
}

func AcquireSession

func AcquireSession(ctx context.Context, r heligo.Request, server *Server, forceDBE bool) (context.Context, *Session, int, error)

type SessionList

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

type SessionManager

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

Jump to

Keyboard shortcuts

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