server

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const TokenClaimsKey contextKey = "tokenClaims"

Variables

View Source
var (
	DbPlugins               atomic.Pointer[map[string]easyrest.DBPlugin]
	CachePlugins            atomic.Pointer[map[string]easyrest.CachePlugin]
	AuthPlugins             atomic.Pointer[map[string]easyrest.AuthPlugin]
	AuthSecurityDefinitions atomic.Pointer[map[string]map[string]any]

	PreservedCachePlugins map[string]PreservedPluginFactory[easyrest.CachePlugin]
	PreservedDbPlugins    map[string]PreservedPluginFactory[easyrest.DBPlugin]
	PreservedAuthPlugins  map[string]PreservedPluginFactory[easyrest.AuthPlugin]

	AllowedOps = map[string]string{
		"eq":    "=",
		"neq":   "!=",
		"lt":    "<",
		"lte":   "<=",
		"gt":    ">",
		"gte":   ">=",
		"like":  "LIKE",
		"ilike": "ILIKE",
		"is":    "IS",
		"in":    "IN",
	}
)

Global configuration and dbPlugins loaded only once.

Functions

func AccessLogMiddleware added in v0.1.1

func AccessLogMiddleware(next http.Handler) http.Handler

AccessLogMiddleware logs incoming HTTP requests if enabled.

func Authenticate

func Authenticate(r *http.Request) (string, *http.Request, error)

Authenticate extracts and validates the JWT token.

func BuildPluginContext added in v0.1.1

func BuildPluginContext(r *http.Request) map[string]any

BuildPluginContext extracts context variables from the HTTP request.

func CheckScope added in v0.1.1

func CheckScope(claims jwt.MapClaims, required string) bool

CheckScope verifies if the claims contain the required scope.

func DecodeTokenWithoutValidation

func DecodeTokenWithoutValidation(tokenStr string) (jwt.MapClaims, error)

DecodeTokenWithoutValidation decodes a JWT token without validating its signature.

func GetConfig added in v0.3.1

func GetConfig() config.Config

GetConfig loads configuration only once.

func InitOtel added in v0.8.8

func InitOtel(otelCfg config.OtelConfig) (shutdown func(context.Context) error, err error)

func IsAllowedFunction added in v0.1.1

func IsAllowedFunction(item string) bool

IsAllowedFunction checks if the provided function name is allowed.

func LoadPlugins added in v0.6.0

func LoadPlugins()

LoadPlugins loads all configured database and cache plugins.

func ParseCSV added in v0.1.1

func ParseCSV(s string) []string

ParseCSV splits a comma-separated string.

func ParseWhereClause added in v0.1.1

func ParseWhereClause(values map[string][]string, flatCtx map[string]string, pluginCtx map[string]any) (map[string]any, error)

ParseWhereClause converts query parameters starting with "where." into a map, performing context substitution for values.

func ReloadConfig added in v0.5.0

func ReloadConfig()

func ResetClaimsCache added in v0.8.5

func ResetClaimsCache()

func Run

func Run(conf config.Config)

Run starts the HTTP server.

func SetConfig added in v0.3.1

func SetConfig(newConfig config.Config)

SetConfig sets a new configuration.

func SetupRouter

func SetupRouter() *mux.Router

SetupRouter initializes the router and endpoints.

func StopPlugins added in v0.6.0

func StopPlugins()

Types

type Operation added in v0.8.1

type Operation struct {
	Summary     string           `json:"summary"`
	Description string           `json:"description"`
	Parameters  []Parameter      `json:"parameters"`
	Security    []map[string]any `json:"security"`
	Responses   map[string]any   `json:"responses"`
}

Operation represents a Swagger operation object.

type Parameter added in v0.8.1

type Parameter struct {
	Name             string `json:"name"`
	In               string `json:"in"`
	Description      string `json:"description"`
	Required         bool   `json:"required"`
	Type             string `json:"type,omitempty"`
	Items            any    `json:"items,omitempty"`
	Schema           any    `json:"schema,omitempty"`
	CollectionFormat string `json:"collectionFormat,omitempty"`
}

Parameter represents a Swagger parameter object.

type PathItem added in v0.8.1

type PathItem struct {
	Get    *Operation `json:"get,omitempty"`
	Post   *Operation `json:"post,omitempty"`
	Patch  *Operation `json:"patch,omitempty"`
	Delete *Operation `json:"delete,omitempty"`
}

PathItem represents a Swagger path item object.

type PreservedPluginFactory added in v0.9.0

type PreservedPluginFactory[T any] func() T

type SwaggerInfo added in v0.8.1

type SwaggerInfo struct {
	Title   string `json:"title"`
	Version string `json:"version"`
}

type SwaggerSpec added in v0.8.1

type SwaggerSpec struct {
	Swagger             string         `json:"swagger"`
	Info                SwaggerInfo    `json:"info"`
	Host                string         `json:"host"`
	BasePath            string         `json:"basePath"`
	Schemes             []string       `json:"schemes"`
	Consumes            []string       `json:"consumes"`
	Produces            []string       `json:"produces"`
	Definitions         map[string]any `json:"definitions"`
	SecurityDefinitions map[string]any `json:"securityDefinitions"`
	Paths               map[string]any `json:"paths"`
}

SwaggerSpec represents the Swagger 2.0 specification structure.

Jump to

Keyboard shortcuts

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