gateway

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 76 Imported by: 0

Documentation

Overview

Package gateway defines gateway service

Index

Constants

View Source
const (
	DQLBootstrapPrecedenceRoutesWins   = "routes_wins"
	DQLBootstrapPrecedenceDQLWins      = "dql_wins"
	DQLBootstrapPrecedenceErrorOnMixed = "error_on_conflict"
)
View Source
const (
	RouteUnspecifiedKind = iota
	RouteWarmupKind
	RouteOpenAPIKind
)
View Source
const (
	PackageFile = "datly.pkg"
)

Variables

This section is empty.

Functions

func CommonURL added in v0.8.0

func CommonURL(URLs ...string) (string, error)

func NewCacheFs added in v0.8.0

func NewCacheFs(URL string) afs.Service

func NewFs added in v0.8.0

func NewFs(configURL string, fs afs.Service) afs.Service

func ResetSingleton added in v0.2.2

func ResetSingleton()

Types

type ApiKeyWrapper added in v0.8.0

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

func (*ApiKeyWrapper) Namespaces added in v0.8.0

func (a *ApiKeyWrapper) Namespaces() []string

func (*ApiKeyWrapper) URI added in v0.8.0

func (a *ApiKeyWrapper) URI() string

type AvailableRoutesError added in v0.8.0

type AvailableRoutesError struct {
	Message string
	Paths   []*contract.Path
}

func (*AvailableRoutesError) Error added in v0.8.0

func (a *AvailableRoutesError) Error() string

type ChangeDetection added in v0.8.0

type ChangeDetection struct {
	NumOfRetries     int
	RetryIntervalInS int
	// contains filtered or unexported fields
}

func (*ChangeDetection) Init added in v0.8.0

func (d *ChangeDetection) Init()

type Config

type Config struct {
	ExposableConfig
	SensitiveConfig `json:",omitempty" yaml:",omitempty"`
}

func NewConfigFromURL

func NewConfigFromURL(ctx context.Context, fs afs.Service, URL string) (*Config, error)

func (*Config) Discovery added in v0.2.1

func (c *Config) Discovery() bool

func (*Config) Init

func (c *Config) Init(ctx context.Context) error

func (*Config) ShouldShowAvailableRoutes added in v0.39.0

func (c *Config) ShouldShowAvailableRoutes() bool

func (*Config) SyncFrequency added in v0.8.0

func (c *Config) SyncFrequency() time.Duration

func (*Config) Validate

func (c *Config) Validate() error

type DQLBootstrap added in v0.37.0

type DQLBootstrap struct {
	Sources             []string
	Exclude             []string
	FailFast            *bool
	Precedence          string
	CompileProfile      string
	MixedMode           string
	UnknownNonReadMode  string
	ColumnDiscoveryMode string
	DQLPathMarker       string
	RoutesRelativePath  string
}

func (*DQLBootstrap) EffectivePrecedence added in v0.37.0

func (d *DQLBootstrap) EffectivePrecedence() string

func (*DQLBootstrap) ShouldFailFast added in v0.37.0

func (d *DQLBootstrap) ShouldFailFast() bool

type ExposableConfig added in v0.8.0

type ExposableConfig struct {
	APIPrefix           string //like /v1/api/
	RouteURL            string
	ShowAvailableRoutes *bool
	GoBootstrap         *GoBootstrap
	DQLBootstrap        *DQLBootstrap
	ContentURL          string
	PluginsURL          string
	DependencyURL       string
	JobURL              string
	FailedJobURL        string
	MaxJobs             int
	UseCacheFS          bool
	SyncFrequencyMs     int
	config.Config
	Logging              logging.Config
	Meta                 meta.Config
	AutoDiscovery        *bool
	ChangeDetection      *ChangeDetection
	DisableCors          bool
	CacheConnectorPrefix string
	Version              string
	CORS                 *path.Cors //Default CORS configuration
	MCP                  *ModelContextProtocol
}

type GoBootstrap added in v0.38.0

type GoBootstrap struct {
	Packages []string
	Exclude  []string
}

type HttpError added in v0.8.0

type HttpError struct {
	Code int
	Err  error
}

func (*HttpError) Error added in v0.8.0

func (h *HttpError) Error() string

func (*HttpError) Message added in v0.8.0

func (h *HttpError) Message() string

func (*HttpError) StatusCode added in v0.8.0

func (h *HttpError) StatusCode() int

type ModelContextProtocol added in v0.17.0

type ModelContextProtocol struct {
	Port              *int
	OAuth2ConfigURL   string
	IssuerURL         string
	ResourceURL       string
	AuthorizerMode    string
	BFFExchangeHeader string
	BFFRedirectURI    string
}

func (*ModelContextProtocol) ProtectedResourceURL added in v0.39.0

func (m *ModelContextProtocol) ProtectedResourceURL() string

ProtectedResourceURL returns the RFC 9728 resource-server identifier used in MCP authorization challenges and protected-resource metadata.

type Option added in v0.8.0

type Option func(*options)

Option represents a service option

func WithConfig added in v0.8.0

func WithConfig(config *Config) Option

WithConfig sets a config

func WithConfigURL added in v0.8.0

func WithConfigURL(configURL string) Option

func WithEmbedFs added in v0.8.0

func WithEmbedFs(embedFs *embed.FS) Option

WithEmbedFs sets an embed file system

func WithExtensions added in v0.8.0

func WithExtensions(registry *extension.Registry) Option

WithExtensions sets an extension registry

func WithInitializer added in v0.11.0

func WithInitializer(initializer func(config *Config, fs *embed.FS) error) Option

func WithMetrics added in v0.8.0

func WithMetrics(metrics *gmetric.Service) Option

WithMetrics sets a metrics service

func WithRefreshDisabled added in v0.38.0

func WithRefreshDisabled(enabled bool) Option

func WithRepository added in v0.8.0

func WithRepository(repository *repository.Service) Option

WithRepository sets a repository service

func WithStatusHandler added in v0.8.0

func WithStatusHandler(handler http.Handler) Option

type Route added in v0.8.0

type Route struct {
	Path          *contract.Path
	MCP           *contract.ModelContextProtocol
	Meta          *contract.Meta
	Kind          int
	ApiKeys       []*path.APIKey
	Providers     []*repository.Provider
	NewMultiRoute func(routes []*contract.Path) *Route                                       `json:"-"`
	Handler       func(ctx context.Context, response http.ResponseWriter, req *http.Request) `json:"-"`
	logging.Config
	Version string

	// Counter is an optional per-route metrics counter
	Counter dlogger.Counter `json:"-"`
}

func (*Route) CanHandle added in v0.8.0

func (r *Route) CanHandle(req *http.Request) bool

func (*Route) Handle added in v0.8.0

func (r *Route) Handle(res http.ResponseWriter, req *http.Request) int

func (*Route) Namespaces added in v0.8.0

func (r *Route) Namespaces() []string

func (*Route) URI added in v0.8.0

func (r *Route) URI() string

type Router added in v0.8.0

type Router struct {
	OpenAPIInfo openapi3.Info
	// contains filtered or unexported fields
}

func NewRouter added in v0.8.0

func NewRouter(ctx context.Context, components *repository.Service, config *Config, metrics *gmetric.Service, statusHandler http.Handler, mcpRegistry *serverproto.Registry) (*Router, error)

NewRouter creates new router

func (*Router) DispatchStorageEvent added in v0.8.0

func (r *Router) DispatchStorageEvent(ctx context.Context, object storage.Object) error

func (*Router) EnsureCors added in v0.20.7

func (r *Router) EnsureCors(paths ...*path.Path) *path.Cors

func (*Router) Handle added in v0.8.0

func (r *Router) Handle(writer http.ResponseWriter, request *http.Request)

func (*Router) HandleJob added in v0.8.0

func (r *Router) HandleJob(ctx context.Context, aJob *async.Job) error

func (*Router) Match added in v0.8.0

func (r *Router) Match(method, URL string, req *http.Request) (*Route, error)

func (*Router) NewConfigRoute added in v0.8.0

func (r *Router) NewConfigRoute() *Route

func (*Router) NewContentRoute added in v0.8.0

func (r *Router) NewContentRoute(aPath *path.Path) []*Route

func (*Router) NewGlobalMetricRoutes added in v0.39.0

func (r *Router) NewGlobalMetricRoutes(URI string) []*Route

func (*Router) NewMetricRoute added in v0.8.0

func (r *Router) NewMetricRoute(URI string) *Route

func (*Router) NewOpenAPIAggregateRoute added in v0.39.0

func (r *Router) NewOpenAPIAggregateRoute(URL string, components *repository.Service, providers ...*repository.Provider) *Route

NewOpenAPIAggregateRoute builds a route that serves a single OpenAPI 3.0.1 spec covering all supplied (public) providers. It defaults to JSON and can return YAML when the request asks for it via ?format=yaml or an Accept header containing yaml.

func (*Router) NewOpenAPIDocRoute added in v0.39.0

func (r *Router) NewOpenAPIDocRoute(URL string, specURL string) *Route

NewOpenAPIDocRoute serves an interactive Swagger UI page that renders the aggregate OpenAPI spec located at specURL.

func (*Router) NewOpenAPIRoute added in v0.8.0

func (r *Router) NewOpenAPIRoute(URL string, components *repository.Service, providers ...*repository.Provider) *Route

func (*Router) NewOptionsRoute added in v0.8.0

func (r *Router) NewOptionsRoute(uri string, paths []*path.Path) *Route

func (*Router) NewRouteHandler added in v0.8.0

func (r *Router) NewRouteHandler(handler *router.Handler) *Route

func (*Router) NewStateRoute added in v0.8.0

func (r *Router) NewStateRoute(URL string, provider *repository.Provider) *Route

func (*Router) NewStatusRoute added in v0.8.0

func (r *Router) NewStatusRoute() *Route

func (*Router) NewStructRoute added in v0.8.0

func (r *Router) NewStructRoute(URL string, provider *repository.Provider) *Route

func (*Router) NewViewMetaHandler added in v0.8.0

func (r *Router) NewViewMetaHandler(URL string, provider *repository.Provider) *Route

func (*Router) NewWarmupRoute added in v0.8.0

func (r *Router) NewWarmupRoute(URL string, providers ...*repository.Provider) *Route

func (*Router) PreCacheables added in v0.8.0

func (r *Router) PreCacheables(ctx context.Context, method string, uri string) ([]*view.View, error)

type SensitiveConfig added in v0.8.0

type SensitiveConfig struct {
	APIKeys path.APIKeys
}

type Service

type Service struct {
	Config *Config
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, opts ...Option) (*Service, error)

New creates gateway Service. It is important to call Service.Close before Service got Garbage collected.

func Singleton

func Singleton(ctx context.Context, options ...Option) (*Service, error)

func (*Service) Close added in v0.8.0

func (r *Service) Close() error

func (*Service) JWTSigner added in v0.8.0

func (r *Service) JWTSigner() *signer.Service

func (*Service) MCP added in v0.15.4

func (r *Service) MCP() *serverproto.Registry

func (*Service) PreCachables added in v0.2.11

func (r *Service) PreCachables(ctx context.Context, method string, uri string) ([]*view.View, error)

func (*Service) Router added in v0.8.0

func (r *Service) Router() (*Router, bool)

func (*Service) ServeHTTP added in v0.8.0

func (r *Service) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type Session added in v0.8.0

type Session struct {
	FailureCounter      map[string]int
	DeletedDependencies map[string]bool
	UpdatedDependencies map[string]bool
	DeletedRouters      map[string]bool
	UpdatedRouters      map[string]bool
	Routers             map[string]*router.Resource
	Dependencies        map[string]*view.Resource
	// contains filtered or unexported fields
}

func NewSession added in v0.8.0

func NewSession(config *ChangeDetection) *Session

func (*Session) AddRouter added in v0.8.0

func (s *Session) AddRouter(URL string, resource *router.Resource)

func (*Session) OnDependencyDeleted added in v0.8.0

func (s *Session) OnDependencyDeleted(URLs ...string)

func (*Session) OnDependencyUpdated added in v0.8.0

func (s *Session) OnDependencyUpdated(URLs ...string)

func (*Session) OnFileChange added in v0.8.0

func (s *Session) OnFileChange(URLs ...string)

func (*Session) OnRouterDeleted added in v0.8.0

func (s *Session) OnRouterDeleted(URLs ...string)

func (*Session) OnRouterUpdated added in v0.8.0

func (s *Session) OnRouterUpdated(URLs ...string)

func (*Session) UpdateFailureCounter added in v0.8.0

func (s *Session) UpdateFailureCounter()

type StatusCodeError added in v0.8.0

type StatusCodeError interface {
	StatusCode() int
	Error() string
	Message() string
}

Directories

Path Synopsis
apigw
Package apigw defines apigw lambda datly runtime
Package apigw defines apigw lambda datly runtime
apigw/app command
gcf
Package gcf defines Google Cloud Functions entry point
Package gcf defines Google Cloud Functions entry point
gcr
Package gcr defines Google Cloud Exec entry point
Package gcr defines Google Cloud Exec entry point
lambda
Package lambda defines lambda datly runtime
Package lambda defines lambda datly runtime
lambda/app command

Jump to

Keyboard shortcuts

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