sing-box/option/debug.go

44 lines
1.1 KiB
Go
Raw Normal View History

2023-03-17 06:51:09 +00:00
package option
import (
2023-09-20 06:12:08 +00:00
"github.com/sagernet/sing-box/common/humanize"
"github.com/sagernet/sing/common/json"
2023-03-17 06:51:09 +00:00
)
type DebugOptions struct {
2023-04-22 07:58:25 +00:00
Listen string `json:"listen,omitempty"`
2023-03-17 06:51:09 +00:00
GCPercent *int `json:"gc_percent,omitempty"`
MaxStack *int `json:"max_stack,omitempty"`
MaxThreads *int `json:"max_threads,omitempty"`
PanicOnFault *bool `json:"panic_on_fault,omitempty"`
TraceBack string `json:"trace_back,omitempty"`
2023-09-20 06:12:08 +00:00
MemoryLimit MemoryBytes `json:"memory_limit,omitempty"`
2023-03-17 06:51:09 +00:00
OOMKiller *bool `json:"oom_killer,omitempty"`
}
2023-09-20 06:12:08 +00:00
type MemoryBytes uint64
2023-03-17 06:51:09 +00:00
2023-09-20 06:12:08 +00:00
func (l MemoryBytes) MarshalJSON() ([]byte, error) {
return json.Marshal(humanize.MemoryBytes(uint64(l)))
2023-03-17 06:51:09 +00:00
}
2023-09-20 06:12:08 +00:00
func (l *MemoryBytes) UnmarshalJSON(bytes []byte) error {
2023-03-17 06:51:09 +00:00
var valueInteger int64
err := json.Unmarshal(bytes, &valueInteger)
if err == nil {
2023-09-20 06:12:08 +00:00
*l = MemoryBytes(valueInteger)
2023-03-17 06:51:09 +00:00
return nil
}
var valueString string
err = json.Unmarshal(bytes, &valueString)
if err != nil {
return err
}
2023-09-20 06:12:08 +00:00
parsedValue, err := humanize.ParseMemoryBytes(valueString)
2023-03-17 06:51:09 +00:00
if err != nil {
return err
}
2023-09-20 06:12:08 +00:00
*l = MemoryBytes(parsedValue)
2023-03-17 06:51:09 +00:00
return nil
}