Documentation
¶
Overview ¶
Package serverops provides core infrastructure for server operations including data persistence, state management, error handling, and security utilities and other primitives or wiring for libraries.
Subpackages are prohibited from cross-importing. Shared utilities in other words: subpackages of serverops are NEVER allowed to use other subpackages of serverops.
Index ¶
- Constants
- Variables
- func CheckResourceAuthorization(ctx context.Context, resource string, requiredPermission store.Permission) error
- func CheckServiceAuthorization[T ServiceMeta](ctx context.Context, s T, permission store.Permission) error
- func CreateAuthToken(subject string, permissions store.AccessList) (string, time.Time, error)
- func Decode[T any](r *http.Request) (T, error)
- func Encode[T any](w http.ResponseWriter, _ *http.Request, status int, v T) error
- func Error(w http.ResponseWriter, r *http.Request, err error, op Operation) error
- func GetIdentity(ctx context.Context) (string, error)
- func LoadConfig[T any](cfg *T) error
- func NewServiceManager(config *Config) error
- func RefreshPlainToken(ctx context.Context, token string, withGracePeriod *time.Duration) (string, bool, time.Time, error)
- func RefreshToken(ctx context.Context) (string, bool, time.Time, error)
- func ValidateConfig(cfg *Config) error
- type Config
- type ConfigTokenizerService
- type ErrBadPathValue
- type LLMChatClient
- type LLMEmbedClient
- type LLMStreamClient
- type Message
- type Operation
- type ServiceManager
- type ServiceMeta
Constants ¶
const DefaultAdminUser = "admin@admin.com"
const DefaultDefaultServiceGroup = "admin_panel"
const DefaultServerGroup = "server"
Variables ¶
var ErrDecodeInvalidJSON = errors.New("serverops: decoding failing, invalid json")
var ErrEncodeInvalidJSON = errors.New("serverops: encoding failing, invalid json")
var ErrFileEmpty = errors.New("serverops: file cannot be empty")
ErrFileEmpty indicates an attempt to upload an empty file.
var ErrFileSizeLimitExceeded = errors.New("serverops: file size limit exceeded")
ErrFileSizeLimitExceeded indicates the specific file exceeded its allowed size limit.
Functions ¶
func CheckResourceAuthorization ¶
func CheckResourceAuthorization(ctx context.Context, resource string, requiredPermission store.Permission) error
CheckResourceAuthorization checks if the user has the required permission for a given resource.
func CheckServiceAuthorization ¶
func CheckServiceAuthorization[T ServiceMeta](ctx context.Context, s T, permission store.Permission) error
func CreateAuthToken ¶
func GetIdentity ¶
GetIdentity extracts the identity from the context using the JWT secret from the ServiceManager.
func LoadConfig ¶
func NewServiceManager ¶
NewServiceManager creates a new instance of server.
func RefreshPlainToken ¶
func ValidateConfig ¶
Types ¶
type Config ¶
type Config struct {
DatabaseURL string `json:"database_url"`
Port string `json:"port"`
Addr string `json:"addr"`
AllowedAPIOrigins string `json:"allowed_api_origins"`
AllowedMethods string `json:"allowed_methods"`
AllowedHeaders string `json:"allowed_headers"`
SigningKey string `json:"signing_key"`
EncryptionKey string `json:"encryption_key"`
JWTSecret string `json:"jwt_secret"`
JWTExpiry string `json:"jwt_expiry"`
TiKVPDEndpoint string `json:"tikv_pd_endpoint"`
NATSURL string `json:"nats_url"`
NATSUser string `json:"nats_user"`
NATSPassword string `json:"nats_password"`
SecurityEnabled string `json:"security_enabled"`
OpensearchURL string `json:"opensearch_url"`
ProxyOrigin string `json:"proxy_origin"`
UIBaseURL string `json:"ui_base_url"`
TokenizerServiceURL string `env:"TOKENIZER_SERVICE_URL" envDefault:"tokenizer:50051"`
}
type ConfigTokenizerService ¶
type ErrBadPathValue ¶
type ErrBadPathValue string
func (ErrBadPathValue) Error ¶
func (v ErrBadPathValue) Error() string
type LLMChatClient ¶
Client interfaces for different capabilities
type LLMEmbedClient ¶
type LLMStreamClient ¶
type ServiceManager ¶
type ServiceManager interface {
RegisterServices(s ...ServiceMeta) error
GetServices() ([]ServiceMeta, error)
IsSecurityEnabled(serviceName string) bool
HasValidLicenseFor(serviceName string) bool
GetSecret() string
GetTokenExpiry() time.Duration
}
func GetManagerInstance ¶
func GetManagerInstance() ServiceManager