gateway

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

Package gateway defines gateway service

Index

Constants

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 Authorizer added in v0.8.0

type Authorizer interface {
	Authorize(writer http.ResponseWriter, request *http.Request) bool
}

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) SyncFrequency added in v0.8.0

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

func (*Config) Validate

func (c *Config) Validate() error

type ExposableConfig added in v0.8.0

type ExposableConfig struct {
	APIPrefix       string //like /v1/api/
	RouteURL        string
	ContentURL      string
	PluginsURL      string
	DependencyURL   string
	JobURL          string
	FailedJobURL    string
	MaxJobs         int
	UseCacheFS      bool
	SyncFrequencyMs int
	auth.Config
	Meta                 meta.Config
	AutoDiscovery        *bool
	ChangeDetection      *ChangeDetection
	DisableCors          bool
	RevealMetric         *bool
	CacheConnectorPrefix 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 Option added in v0.8.0

type Option func(*options)

Option represents a service option

func WithAuthProvider added in v0.8.0

func WithAuthProvider(authProvider func(config *Config, fs *embed.FS) (Authorizer, error)) Option

func WithAuthorizer added in v0.8.0

func WithAuthorizer(authorizer Authorizer) Option

WithAuthorizer sets an authorizer

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 WithMetrics added in v0.8.0

func WithMetrics(metrics *gmetric.Service) Option

WithMetrics sets a metrics service

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
	Kind          int
	ApiKeys       []*path.APIKey
	Providers     []*repository.Provider
	NewMultiRoute func(routes []*contract.Path) *Route
	Handler       func(ctx context.Context, response http.ResponseWriter, req *http.Request)
}

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, authorizer Authorizer) (*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) 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) NewMetricRoute added in v0.8.0

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

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

	JWTSigner *signer.Service
	// 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) LogInitTimeIfNeeded added in v0.8.0

func (r *Service) LogInitTimeIfNeeded(start time.Time, writer http.ResponseWriter)

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)

func (*Service) ShouldRevealMetrics added in v0.8.0

func (r *Service) ShouldRevealMetrics() bool

func (*Service) WrapResponseIfNeeded added in v0.8.0

func (r *Service) WrapResponseIfNeeded(response http.ResponseWriter) http.ResponseWriter

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
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

Jump to

Keyboard shortcuts

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