initial import
This commit is contained in:
11
example/tracing/user/etc/config.json
Normal file
11
example/tracing/user/etc/config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Name": "user.rpc",
|
||||
"ListenOn": "localhost:3457",
|
||||
"Etcd": {
|
||||
"Hosts": [
|
||||
"localhost:2379"
|
||||
],
|
||||
"Key": "user"
|
||||
},
|
||||
"Timeout": 500
|
||||
}
|
||||
55
example/tracing/user/server.go
Normal file
55
example/tracing/user/server.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"zero/core/conf"
|
||||
"zero/example/tracing/remote/user"
|
||||
"zero/rpcx"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/config.json", "the config file")
|
||||
|
||||
type UserServer struct {
|
||||
lock sync.Mutex
|
||||
alive bool
|
||||
downTime time.Time
|
||||
}
|
||||
|
||||
func NewUserServer() *UserServer {
|
||||
return &UserServer{
|
||||
alive: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (gs *UserServer) GetGrade(ctx context.Context, req *user.UserRequest) (*user.UserResponse, error) {
|
||||
fmt.Println("=>", req)
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.UserResponse{
|
||||
Response: "hello from " + hostname,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c rpcx.RpcServerConf
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
server := rpcx.MustNewServer(c, func(grpcServer *grpc.Server) {
|
||||
user.RegisterUserServer(grpcServer, NewUserServer())
|
||||
})
|
||||
server.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user