-
Notifications
You must be signed in to change notification settings - Fork 85
/
debug_sdn.go
49 lines (40 loc) · 1.15 KB
/
debug_sdn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2019 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"fmt"
"net/http"
moovhttp "github.com/moov-io/base/http"
"github.com/go-kit/kit/log"
)
const (
debugSDNPath = "/debug/sdn/{sdnId}"
)
func debugSDNHandler(logger log.Logger, searcher *searcher) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sdnID := getSDNId(w, r)
if sdnID == "" {
return
}
if requestID := moovhttp.GetRequestID(r); requestID != "" {
logger.Log("admin", fmt.Sprintf("debug route for SDN=%s", sdnID), "requestID", requestID)
}
var response struct {
SDN *SDN
Debug struct {
IndexedName string `json:"indexedName"`
ParsedRemarksID string `json:"parsedRemarksId"`
} `json:"debug"`
}
response.SDN = searcher.debugSDN(sdnID)
if response.SDN != nil {
response.Debug.IndexedName = response.SDN.name
response.Debug.ParsedRemarksID = response.SDN.id
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}
}