github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/option/debug.go (about) 1 package option 2 3 import ( 4 "encoding/json" 5 6 "github.com/dustin/go-humanize" 7 ) 8 9 type DebugOptions struct { 10 Listen string `json:"listen,omitempty"` 11 GCPercent *int `json:"gc_percent,omitempty"` 12 MaxStack *int `json:"max_stack,omitempty"` 13 MaxThreads *int `json:"max_threads,omitempty"` 14 PanicOnFault *bool `json:"panic_on_fault,omitempty"` 15 TraceBack string `json:"trace_back,omitempty"` 16 MemoryLimit BytesLength `json:"memory_limit,omitempty"` 17 OOMKiller *bool `json:"oom_killer,omitempty"` 18 } 19 20 type BytesLength int64 21 22 func (l BytesLength) MarshalJSON() ([]byte, error) { 23 return json.Marshal(humanize.IBytes(uint64(l))) 24 } 25 26 func (l *BytesLength) UnmarshalJSON(bytes []byte) error { 27 var valueInteger int64 28 err := json.Unmarshal(bytes, &valueInteger) 29 if err == nil { 30 *l = BytesLength(valueInteger) 31 return nil 32 } 33 var valueString string 34 err = json.Unmarshal(bytes, &valueString) 35 if err != nil { 36 return err 37 } 38 parsedValue, err := humanize.ParseBytes(valueString) 39 if err != nil { 40 return err 41 } 42 *l = BytesLength(parsedValue) 43 return nil 44 }