mirror of https://github.com/Xhofe/alist
feat(alist_v3): add IntSlice type for JSON unmarshalling (#9247)
- Add `IntSlice` type to handle both single int and array in JSON. - Modify `MeResp` struct to use `IntSlice` for `Role` field. - Import `encoding/json` for JSON operations.pull/9249/head v3.48.0
parent
52da07e8a7
commit
85fe4e5bb3
|
@ -1,6 +1,7 @@
|
|||
package alist_v3
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
|
@ -76,7 +77,7 @@ type MeResp struct {
|
|||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
BasePath string `json:"base_path"`
|
||||
Role []int `json:"role"`
|
||||
Role IntSlice `json:"role"`
|
||||
Disabled bool `json:"disabled"`
|
||||
Permission int `json:"permission"`
|
||||
SsoId string `json:"sso_id"`
|
||||
|
@ -168,3 +169,17 @@ type DecompressReq struct {
|
|||
PutIntoNewDir bool `json:"put_into_new_dir"`
|
||||
SrcDir string `json:"src_dir"`
|
||||
}
|
||||
|
||||
type IntSlice []int
|
||||
|
||||
func (s *IntSlice) UnmarshalJSON(data []byte) error {
|
||||
if len(data) > 0 && data[0] == '[' {
|
||||
return json.Unmarshal(data, (*[]int)(s))
|
||||
}
|
||||
var single int
|
||||
if err := json.Unmarshal(data, &single); err != nil {
|
||||
return err
|
||||
}
|
||||
*s = []int{single}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue