grpc

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 16 Imported by: 0

README

ose-grpc

A standardized gRPC server module for Go microservices. Designed to work beautifully with your own tracing setup (e.g. ose-micro), metrics, recovery, and structured logging.

Go Reference Go Report Card License

✨ Features

  • Custom tracing interceptor (OpenTelemetry-compatible)
  • Logging via Zap (with context)
  • Panic recovery
  • Prometheus metrics-ready
  • Health + reflection auto-registration
  • Unary and stream interceptors supported

🚀 Usage

logger, _ := logger.NewZap(logger.Config{
    Environment: "",
    Level: "info",
})
tracer, _ := tracing.NewOtel(tracing.Config{
    Endpoint: "localhost:4317",
    ServiceName: "ose-grpc-test",
    SampleRatio: 1.0,
}, logger)

if err := ose_grpc.StartServer(ose_grpc.Config{
		Port: 50051,
	},ose_grpc.Param{
		RegisterFn: func(s *grpc.Server) {
			// pb.RegisterYourServiceServer(s, &YourService{})
		},
		Logger: logger,
		Tracer: tracer,
	}); err != nil {
    logger.Fatal(err)
}

License

MIT License


© 2025 Moriba

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToStruct added in v0.0.6

func ConvertToStruct(data map[string]interface{}) (*structpb.Struct, error)

convertToStruct converts map[string]interface{} to *structpb.Struct

func ConvertToValue added in v0.0.6

func ConvertToValue(data map[string]interface{}) (map[string]*structpb.Value, error)

func ToProtoValue added in v0.0.6

func ToProtoValue(v interface{}) (*structpb.Value, error)

func WithStreamTracing

func WithStreamTracing(tracer tracing.Tracer) grpc.StreamServerInterceptor

func WithTracing

func WithTracing(tracer tracing.Tracer) grpc.UnaryServerInterceptor

Types

type Config

type Config struct {
	Port int64 `mapstructure:"port"`
}

type Params added in v0.0.2

type Params struct {
	UnaryInterceptors  []grpc.UnaryServerInterceptor
	StreamInterceptors []grpc.StreamServerInterceptor
	Logger             logger.Logger
	Tracer             tracing.Tracer
	EnablePprof        bool // Optional: enable pprof
	MonitorGoroutines  bool // Optional: monitor goroutine count
}

type Server added in v0.0.2

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

func New added in v0.0.2

func New(params Params) (*Server, error)

func (*Server) Instance added in v0.0.7

func (s *Server) Instance() *grpc.Server

func (*Server) Serve added in v0.0.2

func (s *Server) Serve(lis net.Listener, registerFn func(*grpc.Server)) error

func (*Server) Stop added in v0.0.2

func (s *Server) Stop() error

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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