-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (40 loc) · 1.45 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
package main
import (
"log"
"net/http"
"os"
"github.com/julienschmidt/httprouter"
"github.com/vahdet/go-auth-service/http/controllers"
"github.com/vahdet/go-auth-service/services"
"github.com/vahdet/go-auth-service/services/interfaces"
reftknstrpb "github.com/vahdet/go-refresh-token-store-redis/proto"
usrstrpb "github.com/vahdet/go-user-store-redis/proto"
"google.golang.org/grpc"
)
// See the Kubernetes .yml for the value of the environment variables
const (
USER_STORE_SERVICE_ENV_VAR_NAME = "USER_STORE_SERVICE_URL"
REFRESH_TOKEN_STORE_SERVICE_ENV_VAR_NAME = "REFRESH_TOKEN_STORE_SERVICE_URL"
)
func main() {
// Set up a connections to the grpc servers.
usrStrConn, err := grpc.Dial(os.Getenv(USER_STORE_SERVICE_ENV_VAR_NAME), grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer usrStrConn.Close()
rfrTknStrConn, err := grpc.Dial(os.Getenv(REFRESH_TOKEN_STORE_SERVICE_ENV_VAR_NAME), grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer rfrTknStrConn.Close()
var srv interfaces.AuthService
srv = services.NewAuthService(usrstrpb.NewUserServiceClient(usrStrConn), reftknstrpb.NewTokenServiceClient(rfrTknStrConn))
// grpc client
router := httprouter.New()
ac := controllers.NewAuthController(srv)
router.POST("/register", ac.Register)
router.PUT("/login/:name", ac.Login)
router.DELETE("/logout/:userid", ac.Logout)
log.Fatal(http.ListenAndServe(":8080", router))
}