github.com/rolandhe/saber@v0.0.4/example/nfour/rpc/server/handler/register.go (about)

     1  package handler
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/rolandhe/saber/nfour/rpc"
     6  	"github.com/rolandhe/saber/nfour/rpc/proto"
     7  )
     8  
     9  func RegisterAll(router *rpc.SrvRouter[proto.JsonProtoReq, proto.JsonProtoRes]) {
    10  	router.Register("rpc.test", func(req *proto.JsonProtoReq) (*proto.JsonProtoRes, error) {
    11  
    12  		rpcResult, _ := json.Marshal(&Result[string]{
    13  			Code: 200,
    14  			Data: string(req.Body),
    15  		})
    16  		res := &proto.JsonProtoRes{
    17  			Key:  req.Key,
    18  			Body: rpcResult,
    19  		}
    20  		return res, nil
    21  	})
    22  }