-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (45 loc) · 1.33 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
55
package main
import (
"context"
"fmt"
"log"
"github.com/dpakach/zwitter/pkg/auth"
"github.com/dpakach/zwitter/pkg/config"
zlog "github.com/dpakach/zwitter/pkg/log"
"github.com/dpakach/zwitter/pkg/service"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/dpakach/zwitter/users/api"
"github.com/dpakach/zwitter/users/api/userspb"
"google.golang.org/grpc"
)
func main() {
cfg, err := config.NewServerconfig("config/config.yaml")
if err != nil {
panic(fmt.Errorf("Failed to read config: %s", err))
}
err, AuthEndpoint := cfg.GetNodeAddr("Auth")
if err != nil {
log.Fatal(err)
}
conn, AuthClient := auth.NewAuthClient(AuthEndpoint)
defer conn.Close()
logger := zlog.New()
service := &service.Service{
Config: cfg,
AuthRPCs: []string{
"SetProfile",
"GetProfile",
},
RegisterGrpcServer: func(serv *grpc.Server, log *zlog.ZwitLogger) {
userspb.RegisterUsersServiceServer(serv, &api.Server{Log: log})
},
RegisterRestServer: func(ctx context.Context, mux *runtime.ServeMux, grpcAddr string, opts []grpc.DialOption) error {
return userspb.RegisterUsersServiceHandlerFromEndpoint(ctx, mux, grpcAddr, opts)
},
AuthServiceClient: AuthClient,
RPCBasePath: "/userspb.UsersService/",
SwaggerFile: "./swagger/user_api.swagger.json",
Log: logger,
}
service.Start()
}