mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
f794438335
Code to support react based UI for diagnostics: * pprof, prometheus and diagnistics rationalized to use a single router (i.e. they can all run in the same port) * support_cmd updated to support node routing (was only first node) * Multi content support in router tunnel (application/octet-stream & appliaction/json) * Routing requests changed from using http forms to rest + query params * REST query requests can now be made against erigon base port and diagnostics with the same url format/params --------- Co-authored-by: dvovk <vovk.dimon@gmail.com> Co-authored-by: Mark Holt <mark@disributed.vision>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package diagnostics
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func SetupFlagsAccess(ctx *cli.Context, metricsMux *http.ServeMux) {
|
|
metricsMux.HandleFunc("/flags", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Content-Type", "application/json")
|
|
flags := map[string]interface{}{}
|
|
|
|
ctxFlags := map[string]struct{}{}
|
|
|
|
for _, flagName := range ctx.FlagNames() {
|
|
ctxFlags[flagName] = struct{}{}
|
|
}
|
|
|
|
for _, flag := range ctx.App.Flags {
|
|
name := flag.Names()[0]
|
|
value := ctx.Value(name)
|
|
|
|
switch typed := value.(type) {
|
|
case string:
|
|
if typed == "" {
|
|
continue
|
|
}
|
|
case cli.UintSlice:
|
|
value = typed.Value()
|
|
}
|
|
|
|
var usage string
|
|
|
|
if docFlag, ok := flag.(cli.DocGenerationFlag); ok {
|
|
usage = docFlag.GetUsage()
|
|
}
|
|
|
|
_, inCtx := ctxFlags[name]
|
|
|
|
flags[name] = struct {
|
|
Value interface{} `json:"value,omitempty"`
|
|
Usage string `json:"usage,omitempty"`
|
|
Default bool `json:"default"`
|
|
}{
|
|
Value: value,
|
|
Usage: usage,
|
|
Default: !inCtx,
|
|
}
|
|
}
|
|
json.NewEncoder(w).Encode(flags)
|
|
})
|
|
}
|