github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/backend/interface/http/api_debug.go (about) 1 package http 2 3 import ( 4 "net/http" 5 "os" 6 "strings" 7 ) 8 9 // GET /api/debug/envVar 10 func (s *server) getAPIDebugEnvVar(w http.ResponseWriter, r *http.Request) { 11 debugKey := r.FormValue("debugKey") 12 envDebugKey := os.Getenv("DEBUG_KEY") 13 if debugKey != "" && debugKey == envDebugKey { 14 vars := make(map[string]string) 15 for _, v := range os.Environ() { 16 kv := strings.SplitN(v, "=", 2) 17 if kv[0] == "ENCRYPTION_KEY" || kv[0] == "DEBUG_KEY" { 18 continue 19 } 20 vars[kv[0]] = kv[1] 21 } 22 writeJSON(w, http.StatusOK, vars) 23 } else { 24 writeJSON(w, http.StatusOK, struct{}{}) 25 } 26 } 27 28 // GET /api/debug/httpHeader 29 func (s *server) getAPIDebugHTTPHeader(w http.ResponseWriter, r *http.Request) { 30 debugKey := r.FormValue("debugKey") 31 envDebugKey := os.Getenv("DEBUG_KEY") 32 if debugKey != "" && debugKey == envDebugKey { 33 headers := make(map[string]string) 34 for name := range r.Header { 35 headers[name] = r.Header.Get(name) 36 } 37 writeJSON(w, http.StatusOK, headers) 38 } else { 39 writeJSON(w, http.StatusOK, struct{}{}) 40 } 41 }