/
main.go
47 lines (38 loc) · 1.11 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
package main
import (
"fmt"
"log"
"net"
"net/http"
"github.com/Azanul/wuphf-dot-com/user/gen"
"github.com/Azanul/wuphf-dot-com/user/internal/controller/user"
grpchandler "github.com/Azanul/wuphf-dot-com/user/internal/handler/grpc"
httphandler "github.com/Azanul/wuphf-dot-com/user/internal/handler/http"
"google.golang.org/grpc"
"github.com/Azanul/wuphf-dot-com/user/internal/repository/memory"
)
func main() {
log.Println("Starting the user service")
repo := memory.New()
ctrl := user.New(repo)
h := httphandler.New(ctrl)
g := grpchandler.New(ctrl)
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 50051))
if err != nil {
log.Fatal("Failed to listen:", err)
}
srv := grpc.NewServer()
gen.RegisterAuthServiceServer(srv, g)
go func() {
if err := srv.Serve(lis); err != nil {
log.Fatal("Failed to start the gRPC server:", err)
}
}()
// Endpoints
http.Handle("/user", http.HandlerFunc(h.User))
http.Handle("/auth/register", http.HandlerFunc(h.Register))
http.Handle("/auth/login", http.HandlerFunc(h.Login))
if err := http.ListenAndServe(":8081", nil); err != nil {
panic(err)
}
}