-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (44 loc) · 1.34 KB
/
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
47
48
49
50
51
52
53
54
package main
import (
"context"
"log"
"net"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
pbIndriyas "github.com/tejashwi-07/DummyGrpcServer/proto/indriyas"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type indriyasServer struct {
pbIndriyas.UnimplementedIndriyasServiceServer
}
// IndpbIndriyasService implementation
func (*indriyasServer) HealthCheck(ctx context.Context, request *pbIndriyas.HealthCheckRequest) (*pbIndriyas.HealthCheckResponse, error) {
if request.RequestValue == 1 {
return &pbIndriyas.HealthCheckResponse{HealthStatus: true}, nil
}
return &pbIndriyas.HealthCheckResponse{HealthStatus: false}, status.Errorf(codes.Unauthenticated, "Wrong Request")
}
func main() {
// Create a listener on TCP port
lis, err := net.Listen("tcp", ":10002")
if err != nil {
log.Fatalln("Failed to listen:", err)
}
// Create a gRPC server object
s := grpc.NewServer()
pbIndriyas.RegisterIndriyasServiceServer(s, &indriyasServer{})
log.Println("Serving gRPC on 0.0.0.0:10002")
go func() {
log.Fatalln(s.Serve(lis))
}()
gwmux := runtime.NewServeMux()
// Create a new HTTP server for the gRPC-Gateway
gwServer := &http.Server{
Addr: ":8091",
Handler: gwmux,
}
log.Println("Serving gRPC-Gateway on http://0.0.0.0:8091")
log.Fatalln(gwServer.ListenAndServe())
}