MCPcopy Create free account
hub / github.com/EpochCloud/quick / Engine

Function Engine

engine/engine.go:14–45  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

12)
13
14func 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
47func validate(w http.ResponseWriter, ctx *http.Request) (interface{}, error) {
48 service, ok := config.Srv.Service.Get(ctx.URL.Path)

Callers

nothing calls this directly

Calls 9

validateFunction · 0.85
getDomainFunction · 0.85
degradationFunction · 0.85
getHeaderFunction · 0.85
ErrorMethod · 0.80
SendErrorResponseMethod · 0.80
DebugMethod · 0.80
CloseMethod · 0.80
BalanceMethod · 0.65

Tested by

no test coverage detected