Path: blob/dev/pkg/protocols/common/utils/vardump/dump.go
2073 views
package vardump12import (3"strings"45"github.com/projectdiscovery/nuclei/v3/pkg/types"6mapsutil "github.com/projectdiscovery/utils/maps"7"github.com/yassinebenaid/godump"8)910// variables is a map of variables11type variables = map[string]any1213// DumpVariables dumps the variables in a pretty format14func DumpVariables(data variables) string {15d := godump.Dumper{16Indentation: " ",17HidePrivateFields: false,18ShowPrimitiveNamedTypes: true,19}2021d.Theme = godump.Theme{22String: godump.RGB{R: 138, G: 201, B: 38},23Quotes: godump.RGB{R: 112, G: 214, B: 255},24Bool: godump.RGB{R: 249, G: 87, B: 56},25Number: godump.RGB{R: 10, G: 178, B: 242},26Types: godump.RGB{R: 0, G: 150, B: 199},27Address: godump.RGB{R: 205, G: 93, B: 0},28PointerTag: godump.RGB{R: 110, G: 110, B: 110},29Nil: godump.RGB{R: 219, G: 57, B: 26},30Func: godump.RGB{R: 160, G: 90, B: 220},31Fields: godump.RGB{R: 189, G: 176, B: 194},32Chan: godump.RGB{R: 195, G: 154, B: 76},33UnsafePointer: godump.RGB{R: 89, G: 193, B: 180},34Braces: godump.RGB{R: 185, G: 86, B: 86},35}3637return d.Sprint(process(data, Limit))38}3940// process is a helper function that processes the variables41// and returns a new map of variables42func process(data variables, limit int) variables {43keys := mapsutil.GetSortedKeys(data)44vars := make(variables)4546if limit == 0 {47limit = 25548}4950for _, k := range keys {51v := types.ToString(data[k])52v = strings.ReplaceAll(strings.ReplaceAll(v, "\r", " "), "\n", " ")53if len(v) > limit {54v = v[:limit]55v += " [...]"56}5758vars[k] = v59}6061return vars62}636465