(w http.ResponseWriter, r *http.Request)
| 12 | ) |
| 13 | |
| 14 | func Engine(w http.ResponseWriter, r *http.Request) { |
| 15 | service, err := validate(w, r) |
| 16 | if err != nil { |
| 17 | return |
| 18 | } |
| 19 | b, _ := config.Srv.Balance.Get(r.URL.Path) |
| 20 | domain,err :=b.(balance.Balancing).Balance(service.([]string)) |
| 21 | if err != nil { |
| 22 | config.Log.Error("get domain err", err) |
| 23 | errResult.SendErrorResponse(w, config.ErrorFailed) |
| 24 | return |
| 25 | } |
| 26 | config.Log.Debug(domain) |
| 27 | result, err := app.App(r.Method, getDomain(domain, r), r.Body) |
| 28 | if err != nil { |
| 29 | degradation(r.URL.Path) |
| 30 | errResult.SendErrorResponse(w, config.Error) |
| 31 | config.Log.Error("this service is can not conn") |
| 32 | return |
| 33 | } |
| 34 | config.Log.Debug("service result %v,service method %v,domain %v, body %v", result, r.Method, getDomain(domain, r), r.Body) |
| 35 | config.Log.Debug("engine result is header %s", result.Header) |
| 36 | resp := basic.GetApp(result.Body) |
| 37 | defer func() { |
| 38 | result.Body.Close() |
| 39 | basic.Clean(r, resp) |
| 40 | }() |
| 41 | getHeader(w, result) |
| 42 | config.Log.Debug("engine body is %v", resp.String()) |
| 43 | io.WriteString(w, resp.String()) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | func validate(w http.ResponseWriter, ctx *http.Request) (interface{}, error) { |
| 48 | service, ok := config.Srv.Service.Get(ctx.URL.Path) |
nothing calls this directly
no test coverage detected