Documentation ¶
Index ¶
- Constants
- func GetFreePort() (string, error)
- func IsPortFree(port string) bool
- func StartAndWait(address string, parentUI *ui.UI, services ...*Service) error
- func StartSecureAndWait(address string, certDir, pubKeyFile, privKeyFile, clientCAFile string, ...) error
- type APIError
- type HealthCheckResponse
- func (r *HealthCheckResponse) JSON(pp bool) ([]byte, error)
- func (r *HealthCheckResponse) String() string
- func (r *HealthCheckResponse) Stringf(format string) string
- func (r *HealthCheckResponse) TOML() ([]byte, error)
- func (r *HealthCheckResponse) Write(w http.ResponseWriter)
- func (r *HealthCheckResponse) YAML() ([]byte, error)
- type RegisterHandlerFromEndpoint
- type Server
- func (s *Server) AddService(name string, service *Service) *Server
- func (s *Server) AddServices(services Services) *Server
- func (s *Server) AllowCORS() *Server
- func (s *Server) Err() error
- func (s *Server) GenerateCertificates(certDir, pubKeyFile, privKeyFile, caFile string) (err error)
- func (s *Server) IsHealthy() bool
- func (s *Server) IsServiceNotServing(name string) bool
- func (s *Server) IsServiceServing(name string) bool
- func (s *Server) IsServing(service string) bool
- func (s *Server) LoadCertificates(certDir, pubKeyFile, privKeyFile, caFile string) (err error)
- func (s *Server) RegisterHealthCheck() *Server
- func (s *Server) ResumeService(name string) *Server
- func (s *Server) ResumeServices() *Server
- func (s *Server) SetCORS(enabled bool) *Server
- func (s *Server) SetServiceStatus(name string, status grpc_health_v1.HealthCheckResponse_ServingStatus) *Server
- func (s *Server) SetTLS(enabled bool, certDir, pubKeyFile, privKeyFile, caFile string) *Server
- func (s *Server) ShutdownService(name string) *Server
- func (s *Server) ShutdownServices() *Server
- func (s *Server) Start(port string, ports ...string) *Server
- func (s *Server) StartGRPC(port string) *Server
- func (s *Server) StartHTTP(port string) *Server
- func (s *Server) StartHealthz() *Server
- func (s *Server) StartMux(port string) *Server
- func (s *Server) Stop() *Server
- func (s *Server) StopGRPC() *Server
- func (s *Server) StopHTTP() *Server
- func (s *Server) StopMux() *Server
- func (s *Server) Wait() *Server
- func (s *Server) WithHealthCheck(port string) *Server
- func (s *Server) WithSwagger() *Server
- func (s *Server) WithTLS(certDir, pubKeyFile, privKeyFile, caFile string) *Server
- type Service
- type ServiceRegisterable
- type Services
Constants ¶
const EnvTLSServerPassword = "KUBEKIT_SERVER_TLS_PASS"
EnvTLSServerPassword is the name of the environment variable to store/pass the password of the CA key
Variables ¶
This section is empty.
Functions ¶
func GetFreePort ¶
GetFreePort returns an available port in the system
func IsPortFree ¶
IsPortFree checks if the given port is available to use
func StartAndWait ¶
StartAndWait starts the HTTP/REST and gRPC server on the same port. It returns when the server is manually stopped or due to an error, returning such error
func StartSecureAndWait ¶
func StartSecureAndWait(address string, certDir, pubKeyFile, privKeyFile, clientCAFile string, parentUI *ui.UI, services ...*Service) error
StartSecureAndWait starts the HTTP/REST and gRPC server on the same port using TLS. It returns when the server is manually stopped or due to an error, returning such error
Types ¶
type APIError ¶
type APIError struct { StatusCode int `json:"code" yaml:"code" toml:"code"` Status string `json:"status" yaml:"status" toml:"status"` Message string `json:"message" yaml:"message" toml:"message"` Target string `json:"target" yaml:"target" toml:"target"` }
APIError represents an error to return to the HTTP/REST API, usually in JSON format
func (*APIError) Write ¶
func (e *APIError) Write(w http.ResponseWriter)
Write writes the error to the given http response writer
type HealthCheckResponse ¶
type HealthCheckResponse struct { StatusCode int `json:"code" yaml:"code" toml:"code"` Status string `json:"status" yaml:"status" toml:"status"` Message string `json:"message" yaml:"message" toml:"message"` Service string `json:"service" yaml:"service" toml:"service"` // contains filtered or unexported fields }
HealthCheckResponse encapsulate the server response of the Health Check
func HealthzResponse ¶
func HealthzResponse(code int, service string, message ...string) *HealthCheckResponse
HealthzResponse creates a HealthCheck Response. Uses a default message if the message is not provided
func HealthzResponsef ¶
func HealthzResponsef(code int, service, message string, a ...interface{}) *HealthCheckResponse
HealthzResponsef creates an error with a formatted error message
func (*HealthCheckResponse) JSON ¶
func (r *HealthCheckResponse) JSON(pp bool) ([]byte, error)
JSON returns the API Error in JSON format
func (*HealthCheckResponse) String ¶
func (r *HealthCheckResponse) String() string
func (*HealthCheckResponse) Stringf ¶
func (r *HealthCheckResponse) Stringf(format string) string
Stringf returns the API Error in the given format: json, yaml or toml
func (*HealthCheckResponse) TOML ¶
func (r *HealthCheckResponse) TOML() ([]byte, error)
TOML returns the API Error in TOML format
func (*HealthCheckResponse) Write ¶
func (r *HealthCheckResponse) Write(w http.ResponseWriter)
Write writes the error to the given http response writer
func (*HealthCheckResponse) YAML ¶
func (r *HealthCheckResponse) YAML() ([]byte, error)
YAML returns the API Error in YAML format
type RegisterHandlerFromEndpoint ¶
type RegisterHandlerFromEndpoint func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error
RegisterHandlerFromEndpoint is a function from the gRPC GateWay API to dialing to "endpoint" and closing the connection when "ctx" gets done
type Server ¶
type Server struct { Name string // contains filtered or unexported fields }
Server encapsulate the server configuration
func New ¶
New creates a new Server to expose the HTTP/REST and gRPC API as well as the Swagger configuration
func NewTLS ¶
func NewTLS(ctx context.Context, name, host string, certDir, pubKeyFile, privKeyFile, clientCAFile string, parentUI *ui.UI) *Server
NewTLS creates a new server using TLS
func (*Server) AddService ¶
AddService appends a new service to serve
func (*Server) AddServices ¶
AddServices appends all the given services to serve
func (*Server) GenerateCertificates ¶
GenerateCertificates assign the server certificates either by loading the given files, from the certificates directory or generating them from a self-signed generated CA certificate
func (*Server) IsHealthy ¶
IsHealthy return true if all the services are serving. If one service is not serving, the server is not healthy
func (*Server) IsServiceNotServing ¶
IsServiceNotServing return true if the given service name is serving
func (*Server) IsServiceServing ¶
IsServiceServing return true if the given service name is serving
func (*Server) IsServing ¶
IsServing returns true if given service ("grpc", "http", "mux") is running
func (*Server) LoadCertificates ¶
LoadCertificates assign the server certificates loading the given files or from the certificates directory. Th certificates files (server key, server cert & CA cert) are created by the user.
func (*Server) RegisterHealthCheck ¶
RegisterHealthCheck enable the Health Check for the gRPC server. Health is checked with gRPC using the same gRRPC server using the proto from 'google.golang.org/grpc/health/grpc_health_v1'
func (*Server) ResumeService ¶
ResumeService sets all serving status to SERVING, and configures the server to accept all future status changes.
func (*Server) ResumeServices ¶
ResumeServices sets all serving status to SERVING, and configures the server to accept all future status changes.
func (*Server) SetServiceStatus ¶
func (s *Server) SetServiceStatus(name string, status grpc_health_v1.HealthCheckResponse_ServingStatus) *Server
SetServiceStatus change the status of the given service
func (*Server) SetTLS ¶
SetTLS enable TLS with the given certificates if and only if the first parmeter (enabled) is `true`
func (*Server) ShutdownService ¶
ShutdownService sets all serving status to NOT_SERVING, and configures the server to ignore all future status changes.
func (*Server) ShutdownServices ¶
ShutdownServices sets all serving status to NOT_SERVING, and configures the server to ignore all future status changes.
func (*Server) StartHealthz ¶
StartHealthz starts the Health Check Server on HTTP/REST on the given port
func (*Server) StartMux ¶
StartMux starts a Multiplex server to redirect the traffic to the HTTP/REST and GRPC services, allowing to have both services in one port
func (*Server) WithHealthCheck ¶
WithHealthCheck enable the server to have health check
func (*Server) WithSwagger ¶
WithSwagger enable the HTTP server to present the swagger JSON
type Service ¶
type Service struct { Version string Name string ServiceRegister ServiceRegisterable RegisterHandlerFromEndpoint RegisterHandlerFromEndpoint SwaggerBytes []byte }
Service contain the information a server needs from a service to operate
type ServiceRegisterable ¶
ServiceRegisterable is an interface for a service to implement a function to register itself to a gRPC server