MCPcopy
hub / github.com/fabiolb/fabio / customRoutes

Function customRoutes

registry/custom/custom.go:14–90  ·  view source on GitHub ↗
(cfg *config.Custom, ch chan string)

Source from the content-addressed store, hash-verified

12)
13
14func customRoutes(cfg *config.Custom, ch chan string) {
15
16 var Routes *[]route.RouteDef
17 var trans *http.Transport
18 var URL string
19
20 if !cfg.CheckTLSSkipVerify {
21 trans = &http.Transport{}
22
23 } else {
24 trans = &http.Transport{
25 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
26 }
27 }
28
29 client := &http.Client{
30 Transport: trans,
31 Timeout: cfg.Timeout,
32 }
33
34 if cfg.QueryParams != "" {
35 URL = fmt.Sprintf("%s://%s/%s?%s", cfg.Scheme, cfg.Host, cfg.Path, cfg.QueryParams)
36 } else {
37 URL = fmt.Sprintf("%s://%s/%s", cfg.Scheme, cfg.Host, cfg.Path)
38 }
39
40 req, err := http.NewRequest("GET", URL, nil)
41 if err != nil {
42 log.Printf("[ERROR] Can not generate new HTTP request")
43 }
44 req.Close = true
45
46 for {
47 func() {
48 log.Printf("[DEBUG] Custom Registry starting request %s \n", time.Now())
49 resp, err := client.Do(req)
50 if resp != nil {
51 defer func() {
52 if err := resp.Body.Close(); err != nil {
53 log.Printf("Error Can not close HTTP resp body - %s -%s \n", URL, err.Error())
54 }
55 }()
56 }
57 if err != nil {
58 ch <- fmt.Sprintf("Error Sending HTTPs Request To Custom be - %s -%s", URL, err.Error())
59 time.Sleep(cfg.PollInterval)
60 return
61 }
62
63 if resp.StatusCode != 200 {
64 ch <- fmt.Sprintf("Error Non-200 return (%v) from -%s", resp.StatusCode, URL)
65 time.Sleep(cfg.PollInterval)
66 return
67 }
68 log.Printf("[DEBUG] Custom Registry begin decoding json %s \n", time.Now())
69 decoder := json.NewDecoder(resp.Body)
70 err = decoder.Decode(&Routes)
71 if err != nil {

Callers 2

WatchServicesMethod · 0.85
TestCustomRoutesFunction · 0.85

Calls 4

NewTableCustomFunction · 0.92
SetTableFunction · 0.92
ErrorMethod · 0.80
CloseMethod · 0.65

Tested by 1

TestCustomRoutesFunction · 0.68