server

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(ctx context.Context) (context.Context, error)

authenticate takes the user from the gRPC metadata and adds it into the context values, if available. Otherwise an error with gRPC code Unauthenticated is returned.

func ExtractUserFromMD

func ExtractUserFromMD(ctx context.Context) (string, bool)

extractUserFromMD extracts the user from gRPC metadata.

func GetUser

func GetUser(ctx context.Context) (string, bool)

getUser returns the user previously added via authenticate.

func TimingInterceptor

func TimingInterceptor(ctx context.Context, metod string, req interface{}, reply interface{}, cc *grpc.ClientConn, invocer grpc.UnaryInvoker, opts ...grpc.CallOption) error

func TimingServerInterceptor

func TimingServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)

Types

type Metrics

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

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) Calls

func (m *Metrics) Calls() uint64

func (*Metrics) IncrementCalls

func (m *Metrics) IncrementCalls(delta uint64) uint64

type Server

type Server struct {
	Name        string
	Namespace   string
	Domain      string
	Description string
	Version     string
	Conn        *grpc.Server
	Addr        string

	HealthChecks []string

	ServiceID     string
	ConsulAddress string

	Critical uint

	LogrusEntry *log.Entry

	AuthFunc  *grpcauth.AuthFunc
	Authorize *authorize.Authorize
	// contains filtered or unexported fields
}

Server structure gRPC server

func NewServer

func NewServer(name string, namespace string, addr string, ip string, port int, options ...ServerOption) (server *Server)

NewServer creates a gRPC server which has no service registered and has not started to accept requests yet.

func (*Server) DeferShutdown

func (s *Server) DeferShutdown()

func (*Server) GetIP

func (s *Server) GetIP() string

GetIP - внешний IP gRPC сервера

func (*Server) GetPort

func (s *Server) GetPort() int

GetPort порт gRPC сервера

func (*Server) GracefulStop

func (s *Server) GracefulStop()

GracefulStop stops the gRPC server gracefully. It stops the server from accepting new connections and RPCs and blocks until all the pending RPCs are finished.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives. If srv.Addr is blank, ":http" is used. ListenAndServe always returns a non-nil error.

func (*Server) Register

func (s *Server) Register(unregister bool)

Register is the helper function to self-register service into Consul server target - consul dial address, for example: "127.0.0.1:8500" interval - interval of self-register to etcd ttl - ttl of the register information

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve accepts incoming connections Serve will return a non-nil error unless Stop or GracefulStop is called.

func (*Server) ServiceAuthFunc

func (s *Server) ServiceAuthFunc(ctx context.Context) (context.Context, error)

ServiceAuthFunc authenticated function

func (*Server) Stop

func (s *Server) Stop()

Stop stops the gRPC server. It immediately closes all open connections and listeners. It cancels all active RPCs on the server side and the corresponding pending RPCs on the client side will get notified by connection errors.

func (*Server) UnRegister

func (s *Server) UnRegister()

UnRegister is the helper function to unregister service into Consul server

type ServerOption

type ServerOption func(*Server)

A ServerOption sets options such as credentials, codec and keepalive parameters, etc.

func DisbaleRecovery

func DisbaleRecovery() ServerOption

DisbaleRecovery отключаем ывостановление

func DisbaleValidation

func DisbaleValidation() ServerOption

DisbaleValidation отключаем проверки

func SetAuth

func SetAuth(service *authorize.Authorize) ServerOption

SetAuth устанавливаем значения для авторизации

func SetConsul

func SetConsul(addr string, interval time.Duration, ttl int) ServerOption

func SetCritical

func SetCritical(val uint) ServerOption

SetCritical критичекое количество сервисов

0 - некритично
число работающих екземпляров сервиса  например 1 если сервисов будет меньше одного то произойдет событие

func SetDescription

func SetDescription(description string) ServerOption

func SetDomain

func SetDomain(domain string) ServerOption

func SetExtract

func SetExtract() ServerOption

SetExtract - CodeGenRequestFieldExtractor is a function that relies on code-generated functions that export log fields from requests. These are usually coming from a protoc-plugin that generates additional information based on custom field options.

func SetLogger

func SetLogger(logger *log.Logger) ServerOption

SetLogger устанавливаем значения для Logrus

func SetSetting

func SetSetting(verbose int, debug bool, prom bool) ServerOption

SetSetting разные настройки

func Use

Use - custom Unary middleware

func UseStream

UseStream - custom stream middleware

type TapHandler

type TapHandler struct {
	tap.ServerInHandle
	// contains filtered or unexported fields
}

func NewTapHandler

func NewTapHandler(metrics *Metrics, qps rate.Limit, burst int) *TapHandler

func (*TapHandler) Handle

func (h *TapHandler) Handle(ctx context.Context, info *tap.Info) (context.Context, error)

Jump to

Keyboard shortcuts

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