Skip to content

Instantly share code, notes, and snippets.

@sang-w0o
Created February 28, 2022 08:36
Show Gist options
  • Save sang-w0o/65bd22313d082215d47402d32348a4a9 to your computer and use it in GitHub Desktop.
Save sang-w0o/65bd22313d082215d47402d32348a4a9 to your computer and use it in GitHub Desktop.
grpc_gateway_1.go
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