server

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseMiddleware

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

func DatabaseMiddlewareStd added in v0.1.2

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

func DatabaseMiddlewareWithName added in v0.1.2

func DatabaseMiddlewareWithName(server *Server, dbname string) 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 TableDeleteHandler added in v0.1.2

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

func TableGetHandler added in v0.1.2

func TableGetHandler(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 TableUpdateHandler added in v0.1.2

func TableUpdateHandler(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 WriteHTMLString added in v0.2.1

func WriteHTMLString(w http.ResponseWriter, status int, html string) (int, error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, obj any) (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:4000)"`
	AllowAnon            bool            `comment:"Allow unauthenticated connections (default: false)"`
	JWTSecret            string          `comment:"Secret for JWT tokens"`
	SessionMode          string          `comment:"Session mode: none, role (default: role)"`
	EnableAdminRoute     bool            `comment:"Enable administration of databases and tables (default: false)"`
	EnableAPIRoute       bool            `comment:"Enable API access (default: true)"`
	BaseAPIURL           string          `comment:"Base URL for the API (default: /api)"`
	ShortAPIURL          bool            `comment:"Avoid database name in API URL (needs a single allowed database)"`
	BaseAdminURL         string          `comment:"Base URL for the Admin API (default: /admin)"`
	CORSAllowedOrigins   []string        `comment:"CORS Access-Control-Allow-Origin (default: [*] for all)"`
	CORSAllowCredentials bool            `comment:"CORS Access-Control-Allow-Credentials (default: false)"`
	EnableDebugRoute     bool            `comment:"Enable debug access (default: false)"`
	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 GetDatabaseNameFn added in v0.1.2

type GetDatabaseNameFn func(ctx context.Context, r heligo.Request, server *Server) string

type Server

type Server struct {
	Config *Config
	Logger *logging.Logger
	DBE    *database.DbEngine
	HTTP   *http.Server

	OnBeforeStart    func(*Server)
	OnBeforeShutdown func(*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) Run added in v0.1.2

func (s *Server) Run()

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
}

A Session for SmoothDB is the way to cache information about a user and his connection to a database

func AcquireSession

func AcquireSession(ctx context.Context, r heligo.Request, server *Server, forceDBE bool, getDBName GetDatabaseNameFn) (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
}

SessionManager manages user sessions and monitors them efficiently. When disabled, it simply returns Sessions without managing or monitoring.

type SessionStatistics added in v0.2.1

type SessionStatistics struct {
	Count int
	InUse int
	Users int
}

Jump to

Keyboard shortcuts

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