Created
February 28, 2022 08:36
-
-
Save sang-w0o/65bd22313d082215d47402d32348a4a9 to your computer and use it in GitHub Desktop.
grpc_gateway_1.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func New() { | |
// Chi Router 초기화 | |
router := chi.NewRouter() | |
// Middleware 적용 | |
router.Use(authorizeMiddleware()) | |
router.Use(middleWare()) | |
router.Use(anotherMiddleware()) | |
// grpc-gateway 사용을 위한 코드 | |
mux := runtime.NewServeMux() | |
opts := []grpc.DialOption{ | |
grpc.WithTransportCredentials(insecure.NewCredentials()), | |
} | |
err = adminRPC.RegisterAdminHandlerFromEndpoint(ctx, mux, fmt.Sprintf("localhost:%d", RPCPort), opts) | |
if err != nil { | |
// handle error | |
} | |
router.Route("/api/", func(r chi.Router) { | |
r.HandleFunc("/admin/ex1", func(w http.ResponseWriter, r *http.Request) { | |
mux.ServeHTTP(w, r) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment