mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-19 02:37:28 +00:00
feat: add doubao video 1.5
This commit is contained in:
55
dto/values.go
Normal file
55
dto/values.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type IntValue int
|
||||
|
||||
func (i *IntValue) UnmarshalJSON(b []byte) error {
|
||||
var n int
|
||||
if err := json.Unmarshal(b, &n); err == nil {
|
||||
*i = IntValue(n)
|
||||
return nil
|
||||
}
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
v, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*i = IntValue(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i IntValue) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(int(i))
|
||||
}
|
||||
|
||||
type BoolValue bool
|
||||
|
||||
func (b *BoolValue) UnmarshalJSON(data []byte) error {
|
||||
var boolean bool
|
||||
if err := json.Unmarshal(data, &boolean); err == nil {
|
||||
*b = BoolValue(boolean)
|
||||
return nil
|
||||
}
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
if str == "true" {
|
||||
*b = BoolValue(true)
|
||||
} else if str == "false" {
|
||||
*b = BoolValue(false)
|
||||
} else {
|
||||
return json.Unmarshal(data, &boolean)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (b BoolValue) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(bool(b))
|
||||
}
|
||||
Reference in New Issue
Block a user