librest

package
v0.0.0-...-6afd062 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler() func(http.Handler) http.Handler

ErrorHandler is a middleware that handles application errors. Kept for backward compatibility.

func HandleError

func HandleError(ctx context.Context, w http.ResponseWriter, err error)

HandleError writes a structured error response and records the error on the active OTel span. Call once at the HTTP boundary — never in internal layers.

func ObsTagsMiddleware

func ObsTagsMiddleware(next http.Handler) http.Handler

ObsTagsMiddleware reads the X-Obs-Tags request header and injects the listed tags as W3C Baggage members so they propagate automatically to all downstream service calls and NATS messages.

Header format: X-Obs-Tags: cache,persistence,domain Supported tags: cache, persistence, domain, all

Downstream code checks tags via libobs.Has(ctx, "cache").

func PanicRecoveryMiddleware

func PanicRecoveryMiddleware(next http.Handler) http.Handler

PanicRecoveryMiddleware recovers from panics, records them on the active span, force-flushes the tracer provider so the span is not lost, and returns a 500. Must be the outermost middleware.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware generates or propagates a request ID, attaches it to the span, the response header, and the request context.

Types

type Definition

type Definition struct {
	Translator     *libtranslator.ServiceDefinition
	GenDomain      string
	Create         *RequestConfig
	Update         *RequestConfig
	Delete         *RequestConfig
	CustomQueries  []*libtranslator.CustomRequest
	CustomCommands []*libtranslator.CustomRequest
	DisableSelect  bool
	DisableCreate  bool
	DisableUpdate  bool
	DisableDelete  bool
	Event          bool
	// contains filtered or unexported fields
}

Definition is used to declare the information of a model, so it can generate its code.

func (*Definition) Aggregate

func (d *Definition) Aggregate() *libtranslator.AggregateDefinition

func (*Definition) CustomRequests

func (d *Definition) CustomRequests() []*libtranslator.CustomRequest

type Definitions

type Definitions struct {
	Prefix         string
	Name           string
	Repository     string
	TranslatorPath string
	Tenant         bool
	Auth           bool
	// contains filtered or unexported fields
}

Definitions contains all the graphql definitions in the service.

func (*Definitions) GetByID

func (ds *Definitions) GetByID(id string) *Definition

GetByID return the specified definition by its ID.

func (*Definitions) GetTitle

func (ds *Definitions) GetTitle() string

GetTitle is used to return the name of the definition with InitCap

func (*Definitions) Register

func (ds *Definitions) Register(d *Definition)

Register is used to register a new definition into the service.

func (*Definitions) Slice

func (ds *Definitions) Slice() []*Definition

Slice return the definitions as a slice.

type ErrorBody

type ErrorBody struct {
	Code      string   `json:"code"`
	Message   string   `json:"message"`
	Details   []string `json:"details,omitempty"`
	RequestID string   `json:"request_id,omitempty"`
	TraceID   string   `json:"trace_id,omitempty"`
}

ErrorBody is the standard error response shape across all services.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorBody `json:"error"`
}

ErrorResponse is the top-level error response envelope.

type Metrics

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

Metrics holds the OTel instruments for HTTP request observability.

func NewMetrics

func NewMetrics(serviceName string) (*Metrics, error)

NewMetrics initialises the metric instruments for a service. serviceName should match the OTel service.name resource attribute.

func (*Metrics) MetricsMiddleware

func (m *Metrics) MetricsMiddleware(next http.Handler) http.Handler

MetricsMiddleware records request count and duration. Wrap after otelhttp so the span already exists when this runs. Pass the tenant_id attribute if available.

func (*Metrics) RecordError

func (m *Metrics) RecordError(r *http.Request, errorCode string)

RecordError records an application error code in the error counter.

type RequestConfig

type RequestConfig struct{}

type Translation

type Translation struct {
	Key         gclient.String
	Translation gclient.String
}

type TranslationInput

type TranslationInput struct {
	Key         gclient.String
	Translation gclient.String
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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