Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config: Correctly marshal Int32Range to JSON #4234

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading