You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
4 years ago
|
package internal
|
||
4 years ago
|
|
||
|
import (
|
||
4 years ago
|
"github.com/tal-tech/go-zero/core/stat"
|
||
4 years ago
|
"google.golang.org/grpc"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
RegisterFn func(*grpc.Server)
|
||
|
|
||
|
Server interface {
|
||
|
AddOptions(options ...grpc.ServerOption)
|
||
|
AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor)
|
||
|
AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor)
|
||
|
SetName(string)
|
||
|
Start(register RegisterFn) error
|
||
|
}
|
||
|
|
||
|
baseRpcServer struct {
|
||
|
address string
|
||
|
metrics *stat.Metrics
|
||
|
options []grpc.ServerOption
|
||
|
streamInterceptors []grpc.StreamServerInterceptor
|
||
|
unaryInterceptors []grpc.UnaryServerInterceptor
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func newBaseRpcServer(address string, metrics *stat.Metrics) *baseRpcServer {
|
||
|
return &baseRpcServer{
|
||
|
address: address,
|
||
|
metrics: metrics,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (s *baseRpcServer) AddOptions(options ...grpc.ServerOption) {
|
||
|
s.options = append(s.options, options...)
|
||
|
}
|
||
|
|
||
|
func (s *baseRpcServer) AddStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) {
|
||
|
s.streamInterceptors = append(s.streamInterceptors, interceptors...)
|
||
|
}
|
||
|
|
||
|
func (s *baseRpcServer) AddUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) {
|
||
|
s.unaryInterceptors = append(s.unaryInterceptors, interceptors...)
|
||
|
}
|
||
|
|
||
|
func (s *baseRpcServer) SetName(name string) {
|
||
|
s.metrics.SetName(name)
|
||
|
}
|