Documentation ¶
Index ¶
- func Authenticate(ctx context.Context) (context.Context, error)
- func ExtractUserFromMD(ctx context.Context) (string, bool)
- func GetUser(ctx context.Context) (string, bool)
- func TimingInterceptor(ctx context.Context, metod string, req interface{}, reply interface{}, ...) error
- func TimingServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- type Metrics
- type Server
- func (s *Server) DeferShutdown()
- func (s *Server) GetIP() string
- func (s *Server) GetPort() int
- func (s *Server) GracefulStop()
- func (s *Server) ListenAndServe() error
- func (s *Server) Register(unregister bool)
- func (s *Server) Serve(l net.Listener) error
- func (s *Server) ServiceAuthFunc(ctx context.Context) (context.Context, error)
- func (s *Server) Stop()
- func (s *Server) UnRegister()
- type ServerOption
- func DisbaleRecovery() ServerOption
- func DisbaleValidation() ServerOption
- func SetAuth(service *authorize.Authorize) ServerOption
- func SetConsul(addr string, interval time.Duration, ttl int) ServerOption
- func SetCritical(val uint) ServerOption
- func SetDescription(description string) ServerOption
- func SetDomain(domain string) ServerOption
- func SetExtract() ServerOption
- func SetLogger(logger *log.Logger) ServerOption
- func SetSetting(verbose int, debug bool, prom bool) ServerOption
- func Use(item grpc.UnaryServerInterceptor) ServerOption
- func UseStream(item grpc.StreamServerInterceptor) ServerOption
- type TapHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
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 ¶
extractUserFromMD extracts the user from gRPC metadata.
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) IncrementCalls ¶
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) 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 ¶
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 ¶
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 ¶
Serve accepts incoming connections Serve will return a non-nil error unless Stop or GracefulStop is called.
func (*Server) ServiceAuthFunc ¶
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 SetAuth ¶
func SetAuth(service *authorize.Authorize) ServerOption
SetAuth устанавливаем значения для авторизации
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 UseStream ¶
func UseStream(item grpc.StreamServerInterceptor) ServerOption
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