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
type ServeMux struct { | |
// handlers maps HTTP method to a list of handlers. | |
handlers map[string][]handler | |
//.. | |
} | |
type handler struct { | |
pat Pattern | |
h HandlerFunc | |
} |
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() { | |
router := chi.NewRouter() | |
//.. | |
router.Route("/api/", func(r chi.Router) { | |
r.Post("/1", func(w http.ResponseWriter, r *http.Request) { | |
mux.ServeHTTP(w, r) | |
}) | |
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 setContextFromMetadata(ctx context.Context) (context.Context, error) { | |
md, ok := metadata.FromIncomingContext(ctx) | |
if !ok { | |
// handle error | |
} | |
data := md.Get("value1") | |
if len(data) == 0 { | |
return nil, fmt.Errorf("some error occured.") | |
} |
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 초기화 및 middleware 적용 | |
// gRPC Service 구현체에 context를 넘기기 위한 코드 | |
annotationFunc := func(ctx context.Context, request *http.Request) metadata.MD { | |
return metadata.New(map[string]string{ | |
"key1": "value1", | |
"key2": "value2", | |
}) |
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 사용을 위한 코드 |
NewerOlder