func (s *Server) handle() grpc.UnaryServerInterceptor {
	return func(ctx context.Context, req interface{}, args *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
		var (
			cancel func()
			addr   string
		)
		s.mutex.RLock()
		conf := s.conf
		s.mutex.RUnlock()
		timeout := time.Duration(conf.Timeout)
		if dl, ok := ctx.Deadline(); ok {
			ctimeout := time.Until(dl)
			if ctimeout-time.Millisecond*20 > 0 {
				ctimeout = ctimeout - time.Millisecond*20
			}
			if timeout > ctimeout {
				timeout = ctimeout
			}
		}
		ctx, cancel = context.WithTimeout(ctx, timeout)
		defer cancel()
		var t trace.Trace
		cmd := nmd.MD{}
		if gmd, ok := metadata.FromIncomingContext(ctx); ok {
			t, _ = trace.Extract(trace.GRPCFormat, gmd)
			for key, vals := range gmd {
				if nmd.IsIncomingKey(key) {
					cmd[key] = vals[0]
				}
			}
		}
		if t == nil {
			t = trace.New(args.FullMethod)
		} else {
			t.SetTitle(args.FullMethod)
		}
		if pr, ok := peer.FromContext(ctx); ok {
			addr = pr.Addr.String()
			t.SetTag(trace.String(trace.TagAddress, addr))
		}
		defer t.Finish(&err)
		ctx = nmd.NewContext(ctx, cmd)
		ctx = trace.NewContext(ctx, t)
		resp, err = handler(ctx, req)
		return resp, status.FromError(err).Err()
	}
}
handle return a new unary server interceptor for OpenTracing\Logging\LinkTimeout.
package warden
import (
	"context"
	"flag"
	"fmt"
	"math"
	"net"
	"os"
	"strings"
	"sync"
	"time"
	"github.com/mapgoo-lab/atreus/pkg/conf/dsn"
	"github.com/mapgoo-lab/atreus/pkg/log"
	nmd "github.com/mapgoo-lab/atreus/pkg/net/metadata"
	"github.com/mapgoo-lab/atreus/pkg/net/trace"
	xtime "github.com/mapgoo-lab/atreus/pkg/time"
	_ "github.com/mapgoo-lab/atreus/pkg/net/rpc/warden/internal/encoding/json"
	"github.com/mapgoo-lab/atreus/pkg/net/rpc/warden/internal/status"
	"github.com/mapgoo-lab/atreus/pkg/conf/env"
	"github.com/mapgoo-lab/atreus/pkg/net/ip"
	"github.com/mapgoo-lab/atreus/pkg/naming"
	"github.com/pkg/errors"
	"google.golang.org/grpc"
	_ "google.golang.org/grpc/encoding/gzip"  
	"google.golang.org/grpc/keepalive"
	"google.golang.org/grpc/metadata"
	"google.golang.org/grpc/peer"
	"google.golang.org/grpc/reflection"
)
var (
	_grpcDSN        string
	_defaultSerConf = &ServerConfig{
		Network:           "tcp",
		Addr:              "0.0.0.0:9000",
		Timeout:           xtime.Duration(time.Second),
		IdleTimeout:       xtime.Duration(time.Second * 60),
		MaxLifeTime:       xtime.Duration(time.Hour * 2),
		ForceCloseWait:    xtime.Duration(time.Second * 20),
		KeepAliveInterval: xtime.Duration(time.Second * 60),
		KeepAliveTimeout:  xtime.Duration(time.Second * 20),
	}
	_abortIndex int8 = math.MaxInt8 / 2
)
type ServerConfig struct {
	Network string `dsn:"network"`
	Addr string `dsn:"address"`
	Timeout xtime.Duration `dsn:"query.timeout"`
	IdleTimeout xtime.Duration `dsn:"query.idleTimeout"`
	MaxLifeTime xtime.Duration `dsn:"query.maxLife"`
	ForceCloseWait xtime.Duration `dsn:"query.closeWait"`
	KeepAliveInterval xtime.Duration `dsn:"query.keepaliveInterval"`
	KeepAliveTimeout xtime.Duration `dsn:"query.keepaliveTimeout"`
	LogFlag int8 `dsn:"query.logFlag"`
}
type Server struct {
	conf  *ServerConfig
	mutex sync.RWMutex
	server   *grpc.Server
	handlers []grpc.UnaryServerInterceptor
}