-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 976 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"net"
"reflect"
hello_proto "github.com/WisdomEnigma/micro-peers/hello"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
type helloServer struct {
hello_proto.UnimplementedService
}
func NewServer() *helloServer { return &helloServer{} }
func (helloServer) Hello(resp *hello_proto.HelloRequest) (*hello_proto.HelloResponse, error) {
if reflect.DeepEqual(resp, &hello_proto.HelloRequest{Message: ""}) {
return &hello_proto.HelloResponse{Message: ""}, errors.Wrap(errors.New("user doesnot provide valid data"), "empty fields")
}
return &hello_proto.HelloResponse{Message: resp.Message}, nil
}
const Address = "127.0.0.1:9001"
func Server_init() {
listen, err := net.Listen("tcp", Address)
if err != nil {
return
}
var opts []grpc.ServerOption
server := grpc.NewServer(opts...)
hello_proto.RegisterService(server, NewServer())
server.Serve(listen)
}
func main() {
log.Println("Starting server...")
Server_init()
}