builder

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Service-host package

This is a very basic package that allows users to create and manage GRPC and REST services.

The service factory allows creating a service instance based on the API configuration. The service manager allows controlling multiple services and provides basic dependency management.

Example of a very basic eds reader service creation and start:

...
edgeAPI  := builder.API{}
edgeAPI.GRPC.ListenAddress  =  "localhost:8080"
edgeAPI.Gateway.ListenAddress  =  "localhost:8081"

edgeDir, err  := eds.New(&directory.Config{DBPath: "/tmp/my.db", Seed: true}, &logger)
if err !=  nil {
  log.Fatal(err)
}

edgeReader, err  := factoryInstance.CreateService(&edgeAPI, opts, func(server *grpc.Server) {
reader.RegisterReaderServer(server, edgeDir)
}, func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error {
return reader.RegisterReaderHandlerFromEndpoint(ctx, mux, grpcEndpoint, opts)
}, true)

if err !=  nil {
log.Fatal(err)
}
managerInstance.AddGRPCServer(edgeReader)
managerInstance.StartServers(ctx)
...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultGatewayAllowedHeaders = []string{
	headers.Authorization,
	headers.ContentType,
	headers.IfMatch,
	headers.IfNoneMatch,
	"Depth",
}
View Source
var DefaultGatewayAllowedMethods = []string{
	http.MethodGet,
	http.MethodPost,
	http.MethodHead,
	http.MethodDelete,
	http.MethodPut,
	http.MethodPatch,
	"PROPFIND",
	"MKCOL",
	"COPY",
	"MOVE",
}
View Source
var DefaultGatewayAllowedOrigins = []string{
	"http://localhost",
	"http://localhost:*",
	"https://localhost",
	"https://localhost:*",
	"http://127.0.0.1",
	"http://127.0.0.1:*",
	"https://127.0.0.1",
	"https://127.0.0.1:*",
}

Functions

This section is empty.

Types

type API

type API struct {
	Needs []string `json:"needs"`
	GRPC  struct {
		FQDN          string `json:"fqdn"`
		ListenAddress string `json:"listen_address"`
		// Default connection timeout is 120 seconds
		// https://godoc.org/google.golang.org/grpc#ConnectionTimeout
		ConnectionTimeoutSeconds uint32               `json:"connection_timeout_seconds"`
		Certs                    certs.TLSCredsConfig `json:"certs"`
	} `json:"grpc"`
	Gateway struct {
		FQDN              string               `json:"fqdn"`
		ListenAddress     string               `json:"listen_address"`
		AllowedOrigins    []string             `json:"allowed_origins"`
		AllowedHeaders    []string             `json:"allowed_headers"`
		AllowedMethods    []string             `json:"allowed_methods"`
		Certs             certs.TLSCredsConfig `json:"certs"`
		HTTP              bool                 `json:"http"`
		ReadTimeout       time.Duration        `json:"read_timeout"`
		ReadHeaderTimeout time.Duration        `json:"read_header_timeout"`
		WriteTimeout      time.Duration        `json:"write_timeout"`
		IdleTimeout       time.Duration        `json:"idle_timeout"`
	} `json:"gateway"`
}

type GRPCOptions added in v0.0.9

type GRPCOptions struct {
	ServerOptions []grpc.ServerOption
	Registrations GRPCRegistrations
}

type GRPCRegistrations

type GRPCRegistrations func(server *grpc.Server)

type Gateway

type Gateway struct {
	Server *http.Server
	Mux    *http.ServeMux
	Certs  *certs.TLSCredsConfig
}

func (*Gateway) AddHandler added in v0.0.3

func (g *Gateway) AddHandler(pattern string, handler http.HandlerFunc)

type GatewayOptions added in v0.0.9

type GatewayOptions struct {
	HandlerRegistrations HandlerRegistrations
	ErrorHandler         runtime.ErrorHandlerFunc
}

type HandlerRegistrations

type HandlerRegistrations func(ctx context.Context, mux *runtime.ServeMux, grpcEndpoint string, opts []grpc.DialOption) error

type Health added in v0.0.6

type Health struct {
	Server     *health.Server
	GRPCServer *grpc.Server
	Address    string
}

func (*Health) SetServiceStatus added in v0.0.6

func (h *Health) SetServiceStatus(service string, status healthpb.HealthCheckResponse_ServingStatus)

type Server

type Server struct {
	Config   *API
	Server   *grpc.Server
	Listener net.Listener
	Gateway  Gateway
	Started  chan bool
	Cleanup  []func()
}

type ServiceFactory

type ServiceFactory struct{}

func NewServiceFactory

func NewServiceFactory() *ServiceFactory

func (*ServiceFactory) CreateService

func (f *ServiceFactory) CreateService(
	config *API,
	grpcOpts *GRPCOptions,
	gatewayOpts *GatewayOptions,
	cleanup ...func(),
) (*Server, error)

type ServiceInterface

type ServiceInterface interface {
	Start(context.Context) error
	Stop(context.Context) error
}

type ServiceManager

type ServiceManager struct {
	Context context.Context

	Servers       map[string]*Server
	DependencyMap map[string][]string
	HealthServer  *Health
	MetricServer  *http.Server
	// contains filtered or unexported fields
}

func NewServiceManager

func NewServiceManager(logger *zerolog.Logger) *ServiceManager

func (*ServiceManager) AddGRPCServer

func (s *ServiceManager) AddGRPCServer(server *Server) error

func (*ServiceManager) SetupHealthServer added in v0.0.6

func (s *ServiceManager) SetupHealthServer(address string, certificates *certs.TLSCredsConfig) error

func (*ServiceManager) SetupMetricsServer added in v0.0.6

func (s *ServiceManager) SetupMetricsServer(address string, certificates *certs.TLSCredsConfig, enableZpages bool) ([]grpc.ServerOption,
	error,
)

func (*ServiceManager) StartServers

func (s *ServiceManager) StartServers(ctx context.Context) error

func (*ServiceManager) StopServers

func (s *ServiceManager) StopServers(ctx context.Context)

func (*ServiceManager) WithShutdownTimeout added in v0.0.6

func (s *ServiceManager) WithShutdownTimeout(seconds int) *ServiceManager

Jump to

Keyboard shortcuts

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