package squad import ( "encoding/json" "fmt" "strconv" ) // FlexSessionID 兼容历史 workspace.json 中 session_id 为数字 0 的格式。 type FlexSessionID string func (f FlexSessionID) String() string { return string(f) } func (f FlexSessionID) MarshalJSON() ([]byte, error) { return json.Marshal(string(f)) } func (f *FlexSessionID) UnmarshalJSON(b []byte) error { var s string if err := json.Unmarshal(b, &s); err == nil { *f = FlexSessionID(s) return nil } var n int64 if err := json.Unmarshal(b, &n); err == nil { if n == 0 { *f = "" } else { *f = FlexSessionID(strconv.FormatInt(n, 10)) } return nil } return fmt.Errorf("invalid session_id") }