gitee.com/h79/goutils@v1.22.10/common/file/config/config.go (about) 1 package config 2 3 import ( 4 "io" 5 "os" 6 "time" 7 ) 8 9 type Config struct { 10 Access 11 Type string `yaml:"type" json:"type"` // aliyun, qiniu... 12 Cdn string `yaml:"fileCdn" json:"fileCdn"` 13 TmpPath string `yaml:"tmpPath" json:"tmpPath"` //本地的临时文件 14 TokenCallbackUrl string `yaml:"tokenCallbackUrl" json:"tokenCallbackUrl"` 15 MinChunkSize int64 `yaml:"minChunkSize" json:"minChunkSize"` 16 Expires int64 `yaml:"expires" json:"expires"` //TOKEN 过期秒 17 UseHTTPS bool `yaml:"useHttps" json:"useHttps"` //是否使用https域名 18 UseCdn bool `yaml:"useCdn" json:"useCdn"` //上传是否使用CDN上传加速 19 } 20 21 type Access struct { 22 AccessKey string `yaml:"acsKey" json:"acsKey"` 23 SecretKey string `yaml:"secret" json:"secret"` 24 EndPoint string `yaml:"endpoint" json:"endpoint"` 25 Region string `yaml:"region" json:"region"` 26 } 27 28 type Base struct { 29 Dir string 30 Key string 31 Bucket string 32 FileName string 33 } 34 35 type Bucket struct { 36 Name string `yaml:"name" json:"name"` 37 Host string `yaml:"host" json:"host"` 38 DefaultUploadDir string `yaml:"defaultUploadDir" json:"defaultUploadDir"` 39 AllowExt string `yaml:"allowExt" json:"allowExt"` 40 AppId string `yaml:"appId" json:"appId"` 41 ConfKey string `yaml:"confKey" json:"confKey"` 42 } 43 44 // File is a file inside an archive. 45 type File struct { 46 Info FileInfo `yaml:"info,omitempty" json:"info,omitempty"` 47 Source string `yaml:"src,omitempty" json:"src,omitempty"` 48 Destination string `yaml:"dst,omitempty" json:"dst,omitempty"` 49 Dir bool `yaml:"dir,omitempty" json:"dir,omitempty"` 50 StripParent bool `yaml:"strip_parent,omitempty" json:"strip_parent,omitempty"` 51 Default bool `yaml:"-" json:"-"` 52 } 53 54 // FileInfo is the file info of a file. 55 type FileInfo struct { 56 Mode os.FileMode `yaml:"mode,omitempty" json:"mode,omitempty"` 57 Owner string `yaml:"owner,omitempty" json:"owner,omitempty"` 58 Group string `yaml:"group,omitempty" json:"group,omitempty"` 59 MTime string `yaml:"mtime,omitempty" json:"mtime,omitempty"` 60 ParsedMTime time.Time `yaml:"-" json:"-"` 61 } 62 63 // Unmarshal is a custom unmarshaler that wraps strings in arrays. 64 func (f *File) Unmarshal(unmarshal func(interface{}) error) error { 65 type t File 66 var str string 67 if err := unmarshal(&str); err == nil { 68 *f = File{Source: str} 69 return nil 70 } 71 72 var file t 73 if err := unmarshal(&file); err != nil { 74 return err 75 } 76 *f = File(file) 77 return nil 78 } 79 80 type ReaderStream interface { 81 OnReader(r io.ReadSeeker) 82 } 83 84 type ReaderStreamFunc func(r io.ReadSeeker) 85 86 func (s ReaderStreamFunc) OnReader(r io.ReadSeeker) { 87 s(r) 88 } 89 90 type WriteStream interface { 91 OnWriter(r io.WriteSeeker) 92 } 93 94 type WriterStreamFunc func(r io.WriteSeeker) 95 96 func (s WriterStreamFunc) OnWriter(r io.WriteSeeker) { 97 s(r) 98 } 99 100 // Stream 文件流 101 type Stream struct { 102 Base 103 Seeker io.Seeker 104 Reader io.Reader 105 Size int64 106 } 107 108 func (sm *Stream) Seek(offset int64, whence int) (int64, error) { 109 if sm.Seeker != nil { 110 return sm.Seeker.Seek(offset, whence) 111 } 112 return 0, nil 113 } 114 115 type Result struct { 116 TaskId string `json:"task_id,omitempty"` //异步时 117 Id string `json:"id,omitempty"` //文件id值 118 Key string `json:"key"` //文件key 119 Url string `json:"url,omitempty"` //文件url 120 Name string `json:"name,omitempty"` //文件名 121 Type string `json:"type"` //文件类型 122 Path string `json:"-"` //本地文件路径 123 Version string `json:"version,omitempty"` //版本 124 Method int32 `json:"method,omitempty"` //存储方法 125 Size int64 `json:"size,omitempty"` //文件大小 126 CreateAt int64 `json:"create_at"` //创建的时间 127 Duration int64 `json:"duration"` //所消耗时间豪秒 128 Business any `json:"business,omitempty"` //业务定义数据 129 } 130 131 type Results struct { 132 Results []Result `json:"results"` 133 } 134 135 type ChunkResult struct { 136 Key string `json:"key,omitempty"` 137 Chunks []Chunk `json:"chunks"` 138 } 139 140 type Chunk struct { 141 Number int `json:"number"` // Chunk number 142 Offset int64 `json:"offset"` // Chunk offset 143 Size int64 `json:"size"` // Chunk size. 144 } 145 146 type Path struct { 147 Id string `json:"id"` //作品ID: vid-nums, 其它id 148 Product string `json:"product"` //产品名 149 Biz string `json:"biz"` //业务名 150 Type string `json:"type"` //类型 151 Name string `json:"name"` //原始文件名 152 RealName string `json:"real_name"` //实际文件名 153 Ext string `json:"ext"` //扩展名 154 Md5 string `json:"md5"` //md5 155 Version string `json:"version"` //版本 156 Dir []string `json:"dir"` //多级目录 157 Business any `json:"-"` //业务自定义数据 158 Method int32 `json:"method"` 159 TenantId int64 `json:"tenantId"` // 租户id 160 BizId int32 `json:"biz_id"` // 业务 161 Source int32 `json:"source"` //`来源 162 CreateAt int64 `json:"create_at"` 163 ProductId int64 `json:"product_id"` // 产品 164 Size int64 `json:"size"` 165 }