github.com/qiniu/go-sdk/v7@v7.27.0/storagev2/apis/get_objects/api.go (about)

     1  // THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY!
     2  
     3  // 列举指定存储空间里的所有对象条目
     4  package get_objects
     5  
     6  import (
     7  	"encoding/json"
     8  
     9  	credentials "github.com/qiniu/go-sdk/v7/storagev2/credentials"
    10  	errors "github.com/qiniu/go-sdk/v7/storagev2/errors"
    11  )
    12  
    13  // 调用 API 所用的请求
    14  type Request struct {
    15  	Bucket      string                          // 指定存储空间
    16  	Marker      string                          // 上一次列举返回的位置标记,作为本次列举的起点信息
    17  	Limit       int64                           // 本次列举的条目数,范围为 1-1000
    18  	Prefix      string                          // 指定前缀,只有资源名匹配该前缀的资源会被列出
    19  	Delimiter   string                          // 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)
    20  	NeedParts   bool                            // 如果文件是通过分片上传的,是否返回对应的分片信息
    21  	Credentials credentials.CredentialsProvider // 鉴权参数,用于生成鉴权凭证,如果为空,则使用 HTTPClientOptions 中的 CredentialsProvider
    22  }
    23  
    24  // 获取 API 所用的响应
    25  type Response struct {
    26  	Marker         string         // 有剩余条目则返回非空字符串,作为下一次列举的参数传入,如果没有剩余条目则返回空字符串
    27  	CommonPrefixes CommonPrefixes // 公共前缀的数组,如没有指定 delimiter 参数则不返回
    28  	Items          ListedObjects  // 条目的数组,不能用来判断是否还有剩余条目
    29  }
    30  
    31  // 公共前缀的数组
    32  type CommonPrefixes = []string
    33  
    34  // 每个分片的大小
    35  type PartSizes = []int64
    36  
    37  // 对象条目,包含对象的元信息
    38  type ListedObjectEntry struct {
    39  	Key             string            // 对象名称
    40  	PutTime         int64             // 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒
    41  	Hash            string            // 文件的哈希值
    42  	Size            int64             // 对象大小,单位为字节
    43  	MimeType        string            // 对象 MIME 类型
    44  	Type            int64             // 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储
    45  	EndUser         string            // 资源内容的唯一属主标识
    46  	RestoringStatus int64             // 归档存储文件的解冻状态,`2` 表示解冻完成,`1` 表示解冻中;归档文件冻结时,不返回该字段,仅对 stat 指令才有效
    47  	Status          int64             // 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用
    48  	Md5             string            // 对象 MD5 值,只有通过直传文件和追加文件 API 上传的文件,服务端确保有该字段返回
    49  	Metadata        map[string]string // 对象存储元信息
    50  	Parts           PartSizes         // 每个分片的大小,如没有指定 need_parts 参数则不返回
    51  }
    52  type jsonListedObjectEntry struct {
    53  	Key             string            `json:"key"`                     // 对象名称
    54  	PutTime         int64             `json:"putTime"`                 // 文件上传时间,UNIX 时间戳格式,单位为 100 纳秒
    55  	Hash            string            `json:"hash"`                    // 文件的哈希值
    56  	Size            int64             `json:"fsize,omitempty"`         // 对象大小,单位为字节
    57  	MimeType        string            `json:"mimeType"`                // 对象 MIME 类型
    58  	Type            int64             `json:"type,omitempty"`          // 对象存储类型,`0` 表示普通存储,`1` 表示低频存储,`2` 表示归档存储
    59  	EndUser         string            `json:"endUser,omitempty"`       // 资源内容的唯一属主标识
    60  	RestoringStatus int64             `json:"restoreStatus,omitempty"` // 归档存储文件的解冻状态,`2` 表示解冻完成,`1` 表示解冻中;归档文件冻结时,不返回该字段,仅对 stat 指令才有效
    61  	Status          int64             `json:"status,omitempty"`        // 文件的存储状态,即禁用状态和启用状态间的的互相转换,`0` 表示启用,`1`表示禁用
    62  	Md5             string            `json:"md5,omitempty"`           // 对象 MD5 值,只有通过直传文件和追加文件 API 上传的文件,服务端确保有该字段返回
    63  	Metadata        map[string]string `json:"x-qn-meta,omitempty"`     // 对象存储元信息
    64  	Parts           PartSizes         `json:"parts,omitempty"`         // 每个分片的大小,如没有指定 need_parts 参数则不返回
    65  }
    66  
    67  func (j *ListedObjectEntry) MarshalJSON() ([]byte, error) {
    68  	if err := j.validate(); err != nil {
    69  		return nil, err
    70  	}
    71  	return json.Marshal(&jsonListedObjectEntry{Key: j.Key, PutTime: j.PutTime, Hash: j.Hash, Size: j.Size, MimeType: j.MimeType, Type: j.Type, EndUser: j.EndUser, RestoringStatus: j.RestoringStatus, Status: j.Status, Md5: j.Md5, Metadata: j.Metadata, Parts: j.Parts})
    72  }
    73  
    74  func (j *ListedObjectEntry) UnmarshalJSON(data []byte) error {
    75  	var nj jsonListedObjectEntry
    76  	if err := json.Unmarshal(data, &nj); err != nil {
    77  		return err
    78  	}
    79  	j.Key = nj.Key
    80  	j.PutTime = nj.PutTime
    81  	j.Hash = nj.Hash
    82  	j.Size = nj.Size
    83  	j.MimeType = nj.MimeType
    84  	j.Type = nj.Type
    85  	j.EndUser = nj.EndUser
    86  	j.RestoringStatus = nj.RestoringStatus
    87  	j.Status = nj.Status
    88  	j.Md5 = nj.Md5
    89  	j.Metadata = nj.Metadata
    90  	j.Parts = nj.Parts
    91  	return nil
    92  }
    93  
    94  func (j *ListedObjectEntry) validate() error {
    95  	if j.Key == "" {
    96  		return errors.MissingRequiredFieldError{Name: "Key"}
    97  	}
    98  	if j.PutTime == 0 {
    99  		return errors.MissingRequiredFieldError{Name: "PutTime"}
   100  	}
   101  	if j.Hash == "" {
   102  		return errors.MissingRequiredFieldError{Name: "Hash"}
   103  	}
   104  	if j.MimeType == "" {
   105  		return errors.MissingRequiredFieldError{Name: "MimeType"}
   106  	}
   107  	return nil
   108  }
   109  
   110  // 条目的数组,不能用来判断是否还有剩余条目
   111  type ListedObjects = []ListedObjectEntry
   112  
   113  // 本次列举的对象条目信息
   114  type (
   115  	ListedObjectEntries = Response
   116  	jsonResponse        struct {
   117  		Marker         string         `json:"marker,omitempty"`         // 有剩余条目则返回非空字符串,作为下一次列举的参数传入,如果没有剩余条目则返回空字符串
   118  		CommonPrefixes CommonPrefixes `json:"commonPrefixes,omitempty"` // 公共前缀的数组,如没有指定 delimiter 参数则不返回
   119  		Items          ListedObjects  `json:"items"`                    // 条目的数组,不能用来判断是否还有剩余条目
   120  	}
   121  )
   122  
   123  func (j *Response) MarshalJSON() ([]byte, error) {
   124  	if err := j.validate(); err != nil {
   125  		return nil, err
   126  	}
   127  	return json.Marshal(&jsonResponse{Marker: j.Marker, CommonPrefixes: j.CommonPrefixes, Items: j.Items})
   128  }
   129  
   130  func (j *Response) UnmarshalJSON(data []byte) error {
   131  	var nj jsonResponse
   132  	if err := json.Unmarshal(data, &nj); err != nil {
   133  		return err
   134  	}
   135  	j.Marker = nj.Marker
   136  	j.CommonPrefixes = nj.CommonPrefixes
   137  	j.Items = nj.Items
   138  	return nil
   139  }
   140  
   141  func (j *Response) validate() error {
   142  	if len(j.Items) == 0 {
   143  		return errors.MissingRequiredFieldError{Name: "Items"}
   144  	}
   145  	for _, value := range j.Items {
   146  		if err := value.validate(); err != nil {
   147  			return err
   148  		}
   149  	}
   150  	return nil
   151  }