Skip to content
Browse files

Name translator => handler

  • Loading branch information...
1 parent 5931f16 commit 3f13f736fb155847a33648f44ae38f8b73e6aa32 @asim asim committed
Showing with 17 additions and 18 deletions.
  1. +2 −2 api/README.md
  2. +12 −13 api/api.go
  3. +3 −3 main.go
View
4 api/README.md
@@ -12,7 +12,7 @@ The API serves requests in three ways.
- Requests are sent to a special type of API service which takes the request api.Request and response api.Response.
- Definitions can be found at [micro/api/proto](https://github.com/micro/micro/tree/master/api/proto)
-3. /[service] proxy set via `--api_translator=proxy`
+3. /[service] proxy set via `--api_handler=proxy`
- The request will be reverse proxied to the served resolved by the first element in the path
- This allows REST to be implemented behind the API
@@ -116,7 +116,7 @@ A working example can be found here [Greeter Service](https://github.com/micro/m
You can serve a RESTful API by using the API as a proxy and implementing RESTful paths with libraries such as [go-restful](https://github.com/emicklei/go-restful).
An example of a REST API service can be found at [greeter/api/go-restful](https://github.com/micro/micro/tree/master/examples/greeter/api/go-restful).
-Starting the API with `--api_translator=proxy` will reverse proxy requests to backend services within the served API namespace (default: go.micro.api).
+Starting the API with `--api_handler=proxy` will reverse proxy requests to backend services within the served API namespace (default: go.micro.api).
Example
View
25 api/api.go
@@ -74,28 +74,27 @@ func run(ctx *cli.Context) {
// create the router
r := mux.NewRouter()
+ s := &srv{r}
+ var h http.Handler = s
+
+ if ctx.GlobalBool("enable_stats") {
+ st := stats.New()
+ r.HandleFunc("/stats", st.StatsHandler)
+ h = st.ServeHTTP(s)
+ st.Start()
+ defer st.Stop()
+ }
log.Infof("Registering RPC Handler at %s", RPCPath)
r.HandleFunc(RPCPath, handler.RPC)
- switch ctx.GlobalString("api_translator") {
+ switch ctx.GlobalString("api_handler") {
case "proxy":
log.Infof("Registering API Proxy Handler at %s", ProxyPath)
r.PathPrefix(ProxyPath).Handler(handler.Proxy(Namespace, false))
default:
log.Infof("Registering API Handler at %s", APIPath)
- r.HandleFunc(APIPath, restHandler)
- }
-
- s := &srv{r}
- var h http.Handler = s
-
- if ctx.GlobalBool("enable_stats") {
- st := stats.New()
- s.HandleFunc("/stats", st.StatsHandler)
- h = st.ServeHTTP(s)
- st.Start()
- defer st.Stop()
+ r.PathPrefix(APIPath).HandlerFunc(restHandler)
}
// create the server
View
6 main.go
@@ -59,9 +59,9 @@ func setup(app *ccli.App) {
Usage: "Register interval in seconds",
},
ccli.StringFlag{
- Name: "api_translator",
- Usage: "Specify the request translator to be used mapping to backend services. e.g api, proxy",
- EnvVar: "MICRO_API_TRANSLATOR",
+ Name: "api_handler",
+ Usage: "Specify the request handler to be used for mapping HTTP requests to services. e.g api, proxy",
+ EnvVar: "MICRO_API_HANDLER",
},
ccli.StringFlag{
Name: "api_namespace",

0 comments on commit 3f13f73

Please sign in to comment.
Something went wrong with that request. Please try again.