Skip to content

Commit

Permalink
Config: Correctly marshal Int32Range to JSON (#4234)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiguous authored Jan 1, 2025
1 parent 8a6a538 commit 632e510
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions infra/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package conf

import (
"encoding/json"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -258,6 +259,18 @@ type Int32Range struct {
To int32
}

func (v Int32Range) MarshalJSON() ([]byte, error) {
return json.Marshal(v.String())
}

func (v Int32Range) String() string {
if v.Left == v.Right {
return strconv.Itoa(int(v.Left))
} else {
return fmt.Sprintf("%d-%d", v.Left, v.Right)
}
}

func (v *Int32Range) UnmarshalJSON(data []byte) error {
defer v.ensureOrder()
var str string
Expand Down

0 comments on commit 632e510

Please sign in to comment.