debug.go 1.0 KB

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