server

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 5 Imported by: 0

README

grpc server

Generic grpc server.

Example of use

	import "github.com/go-dev-frame/sponge/pkg/grpc/server"

	port := 8282
	registerFn := func(s *grpc.Server) {
		pb.RegisterGreeterServer(s, &greeterServer{})
	}
	
	server.Run(port, registerFn,
		//server.WithSecure(credentials),
		//server.WithUnaryInterceptor(unaryInterceptors...),
		//server.WithStreamInterceptor(streamInterceptors...),
		//server.WithServiceRegister(func() {}),
		//server.WithStatConnections(metrics.WithConnectionsLogger(logger.Get()), metrics.WithConnectionsGauge()),  // show connections or set prometheus metrics
	)

	select{}

Examples of practical use https://github.com/zhufuyi/grpc_examples/blob/main/usage/server/main.go

Documentation

Overview

Package server is generic grpc server-side.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(port int, registerFn RegisterFn, options ...Option)

Run grpc server

Types

type Option

type Option func(*options)

Option set server option

func WithSecure

func WithSecure(credential credentials.TransportCredentials) Option

WithSecure set secure

func WithServiceRegister

func WithServiceRegister(fn ServiceRegisterFn) Option

WithServiceRegister set service register

func WithStatConnections

func WithStatConnections(opts ...metrics.ConnectionOption) Option

WithStatConnections enable stat connections

func WithStreamInterceptor

func WithStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) Option

WithStreamInterceptor set stream interceptor

func WithUnaryInterceptor

func WithUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) Option

WithUnaryInterceptor set unary interceptor

type RegisterFn

type RegisterFn func(srv *grpc.Server)

RegisterFn register object

type ServiceRegisterFn

type ServiceRegisterFn func()

ServiceRegisterFn service register

Jump to

Keyboard shortcuts

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