How to use SaveFile method of minio Package

Best Testkube code snippet using minio.SaveFile

CloudStoreModel.go

Source:CloudStoreModel.go Github

copy

Full Screen

1package models2import (3 "errors"4 "fmt"5 "io/ioutil"6 "os"7 "strings"8 "github.com/PuerkitoBio/goquery"9 CloudStore2 "github.com/TruthHun/CloudStore"10 "github.com/TruthHun/DocHub/helper"11)12type CloudStore struct {13 Private bool14 StoreType helper.ConfigCate15 CanGZIP bool16 client interface{}17 config interface{}18 expire int6419 publicDomain string20 privateDomain string21}22// 创建云存储23func NewCloudStore(private bool) (cs *CloudStore, err error) {24 storeType := helper.ConfigCate(GlobalSys.StoreType)25 modelConfig := NewConfig()26 config := modelConfig.GetGlobalConfigWithStruct(storeType)27 return NewCloudStoreWithConfig(config, storeType, private)28}29var errWithoutConfig = errors.New("云存储配置不正确")30func NewCloudStoreWithConfig(storeConfig interface{}, storeType helper.ConfigCate, private bool) (cs *CloudStore, err error) {31 cs = &CloudStore{32 StoreType: storeType,33 config: storeConfig,34 }35 cs.Private = private36 switch cs.StoreType {37 case StoreOss:38 cfg := cs.config.(*ConfigOss)39 bucket := cfg.PublicBucket40 domain := cfg.PublicBucketDomain41 if cs.Private {42 bucket = cfg.PrivateBucket43 domain = cfg.PrivateBucketDomain44 if cfg.Expire <= 0 {45 cfg.Expire = 180046 }47 cs.expire = cfg.Expire48 }49 cs.privateDomain = cfg.PrivateBucketDomain50 cs.publicDomain = cfg.PublicBucketDomain51 if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.Endpoint == "" || bucket == "" {52 err = errWithoutConfig53 return54 }55 cs.client, err = CloudStore2.NewOSS(cfg.AccessKey, cfg.SecretKey, cfg.Endpoint, bucket, domain)56 cs.CanGZIP = true57 case StoreObs:58 cfg := cs.config.(*ConfigObs)59 bucket := cfg.PublicBucket60 domain := cfg.PublicBucketDomain61 if cs.Private {62 bucket = cfg.PrivateBucket63 domain = cfg.PrivateBucketDomain64 if cfg.Expire <= 0 {65 cfg.Expire = 180066 }67 cs.expire = cfg.Expire68 }69 cs.privateDomain = cfg.PrivateBucketDomain70 cs.publicDomain = cfg.PublicBucketDomain71 if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.Endpoint == "" || bucket == "" {72 err = errWithoutConfig73 return74 }75 cs.client, err = CloudStore2.NewOBS(cfg.AccessKey, cfg.SecretKey, bucket, cfg.Endpoint, domain)76 case StoreQiniu:77 cfg := cs.config.(*ConfigQiniu)78 bucket := cfg.PublicBucket79 domain := cfg.PublicBucketDomain80 if cs.Private {81 bucket = cfg.PrivateBucket82 domain = cfg.PrivateBucketDomain83 if cfg.Expire <= 0 {84 cfg.Expire = 180085 }86 cs.expire = cfg.Expire87 }88 cs.privateDomain = cfg.PrivateBucketDomain89 cs.publicDomain = cfg.PublicBucketDomain90 if cfg.AccessKey == "" || cfg.SecretKey == "" || bucket == "" {91 err = errWithoutConfig92 return93 }94 cs.client, err = CloudStore2.NewQINIU(cfg.AccessKey, cfg.SecretKey, bucket, domain)95 case StoreUpyun:96 cfg := cs.config.(*ConfigUpYun)97 bucket := cfg.PublicBucket98 domain := cfg.PublicBucketDomain99 if cs.Private {100 bucket = cfg.PrivateBucket101 domain = cfg.PrivateBucketDomain102 if cfg.Expire <= 0 {103 cfg.Expire = 1800104 }105 cs.expire = cfg.Expire106 }107 cs.privateDomain = cfg.PrivateBucketDomain108 cs.publicDomain = cfg.PublicBucketDomain109 if cfg.Operator == "" || cfg.Password == "" || bucket == "" {110 err = errWithoutConfig111 return112 }113 cs.client = CloudStore2.NewUpYun(bucket, cfg.Operator, cfg.Password, domain, cfg.Secret)114 case StoreMinio:115 cfg := cs.config.(*ConfigMinio)116 bucket := cfg.PublicBucket117 domain := cfg.PublicBucketDomain118 if cs.Private {119 bucket = cfg.PrivateBucket120 domain = cfg.PrivateBucketDomain121 if cfg.Expire <= 0 {122 cfg.Expire = 1800123 }124 cs.expire = cfg.Expire125 }126 cs.privateDomain = cfg.PrivateBucketDomain127 cs.publicDomain = cfg.PublicBucketDomain128 if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.Endpoint == "" || bucket == "" {129 err = errWithoutConfig130 return131 }132 cs.client, err = CloudStore2.NewMinIO(cfg.AccessKey, cfg.SecretKey, bucket, cfg.Endpoint, domain)133 cs.CanGZIP = true134 case StoreBos:135 cfg := cs.config.(*ConfigBos)136 bucket := cfg.PublicBucket137 domain := cfg.PublicBucketDomain138 if cs.Private {139 bucket = cfg.PrivateBucket140 domain = cfg.PrivateBucketDomain141 if cfg.Expire <= 0 {142 cfg.Expire = 1800143 }144 cs.expire = cfg.Expire145 }146 cs.privateDomain = cfg.PrivateBucketDomain147 cs.publicDomain = cfg.PublicBucketDomain148 if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.Endpoint == "" || bucket == "" {149 err = errWithoutConfig150 return151 }152 cs.client, err = CloudStore2.NewBOS(cfg.AccessKey, cfg.SecretKey, bucket, cfg.Endpoint, domain)153 cs.CanGZIP = true154 case StoreCos:155 cfg := cs.config.(*ConfigCos)156 bucket := cfg.PublicBucket157 domain := cfg.PublicBucketDomain158 if cs.Private {159 bucket = cfg.PrivateBucket160 domain = cfg.PrivateBucketDomain161 if cfg.Expire <= 0 {162 cfg.Expire = 1800163 }164 cs.expire = cfg.Expire165 }166 cs.privateDomain = cfg.PrivateBucketDomain167 cs.publicDomain = cfg.PublicBucketDomain168 if cfg.AccessKey == "" || cfg.SecretKey == "" || cfg.AppId == "" || bucket == "" || cfg.Region == "" {169 err = errWithoutConfig170 return171 }172 cs.client, err = CloudStore2.NewCOS(cfg.AccessKey, cfg.SecretKey, bucket, cfg.AppId, cfg.Region, domain)173 cs.CanGZIP = true174 }175 return176}177func (c *CloudStore) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error) {178 switch c.StoreType {179 case StoreCos:180 err = c.client.(*CloudStore2.COS).Upload(tmpFile, saveFile, headers...)181 case StoreOss:182 err = c.client.(*CloudStore2.OSS).Upload(tmpFile, saveFile, headers...)183 case StoreBos:184 err = c.client.(*CloudStore2.BOS).Upload(tmpFile, saveFile, headers...)185 case StoreObs:186 err = c.client.(*CloudStore2.OBS).Upload(tmpFile, saveFile, headers...)187 case StoreUpyun:188 err = c.client.(*CloudStore2.UpYun).Upload(tmpFile, saveFile, headers...)189 case StoreMinio:190 err = c.client.(*CloudStore2.MinIO).Upload(tmpFile, saveFile, headers...)191 case StoreQiniu:192 err = c.client.(*CloudStore2.QINIU).Upload(tmpFile, saveFile, headers...)193 }194 return195}196func (c *CloudStore) Delete(objects ...string) (err error) {197 switch c.StoreType {198 case StoreCos:199 err = c.client.(*CloudStore2.COS).Delete(objects...)200 case StoreOss:201 err = c.client.(*CloudStore2.OSS).Delete(objects...)202 case StoreBos:203 err = c.client.(*CloudStore2.BOS).Delete(objects...)204 case StoreObs:205 err = c.client.(*CloudStore2.OBS).Delete(objects...)206 case StoreUpyun:207 err = c.client.(*CloudStore2.UpYun).Delete(objects...)208 case StoreMinio:209 err = c.client.(*CloudStore2.MinIO).Delete(objects...)210 case StoreQiniu:211 err = c.client.(*CloudStore2.QINIU).Delete(objects...)212 }213 return214}215// err 返回 nil,表示文件存在,否则表示文件不存在216func (c *CloudStore) IsExist(object string) (err error) {217 switch c.StoreType {218 case StoreCos:219 err = c.client.(*CloudStore2.COS).IsExist(object)220 case StoreOss:221 err = c.client.(*CloudStore2.OSS).IsExist(object)222 case StoreBos:223 err = c.client.(*CloudStore2.BOS).IsExist(object)224 case StoreObs:225 err = c.client.(*CloudStore2.OBS).IsExist(object)226 case StoreUpyun:227 err = c.client.(*CloudStore2.UpYun).IsExist(object)228 case StoreMinio:229 err = c.client.(*CloudStore2.MinIO).IsExist(object)230 case StoreQiniu:231 err = c.client.(*CloudStore2.QINIU).IsExist(object)232 }233 return234}235func GetImageFromCloudStore(picture string, ext ...string) (link string) {236 cs, err := NewCloudStore(false)237 if err != nil {238 helper.Logger.Error(err.Error())239 }240 return cs.getImageFromCloudStore(picture, ext...)241}242//设置默认图片243//@param picture 图片文件或者图片文件md5等244//@param ext 图片扩展名,如果图片文件参数(picture)的值为md5时,需要加上后缀扩展名245//@return link 图片url链接246func (c *CloudStore) getImageFromCloudStore(picture string, ext ...string) (link string) {247 if len(ext) > 0 {248 picture = picture + "." + ext[0]249 } else if !strings.Contains(picture, ".") && len(picture) > 0 {250 picture = picture + ".jpg"251 }252 if c == nil || c.client == nil {253 return254 }255 return c.GetSignURL(picture)256}257func (c *CloudStore) GetSignURL(object string) (link string) {258 var err error259 switch c.StoreType {260 case StoreCos:261 link, err = c.client.(*CloudStore2.COS).GetSignURL(object, c.expire)262 case StoreOss:263 link, err = c.client.(*CloudStore2.OSS).GetSignURL(object, c.expire)264 case StoreBos:265 link, err = c.client.(*CloudStore2.BOS).GetSignURL(object, c.expire)266 case StoreObs:267 link, err = c.client.(*CloudStore2.OBS).GetSignURL(object, c.expire)268 case StoreUpyun:269 link, err = c.client.(*CloudStore2.UpYun).GetSignURL(object, c.expire)270 case StoreMinio:271 link, err = c.client.(*CloudStore2.MinIO).GetSignURL(object, c.expire)272 case StoreQiniu:273 link, err = c.client.(*CloudStore2.QINIU).GetSignURL(object, c.expire)274 }275 if err != nil {276 helper.Logger.Error("GetSignURL:%v", err.Error())277 }278 return279}280func (c *CloudStore) ImageWithDomain(htmlOld string) (htmlNew string) {281 doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlOld))282 if err != nil {283 helper.Logger.Error(err.Error())284 return htmlOld285 }286 doc.Find("img").Each(func(i int, s *goquery.Selection) {287 // For each item found, get the band and title288 if src, exist := s.Attr("src"); exist {289 if !(strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://")) {290 s.SetAttr("src", c.GetSignURL(src))291 }292 }293 })294 htmlNew, _ = doc.Find("body").Html()295 return296}297func (c *CloudStore) ImageWithoutDomain(htmlOld string) (htmlNew string) {298 doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlOld))299 if err != nil {300 helper.Logger.Error(err.Error())301 return htmlOld302 }303 domain := c.GetPublicDomain()304 doc.Find("img").Each(func(i int, s *goquery.Selection) {305 // For each item found, get the band and title306 if src, exist := s.Attr("src"); exist {307 //不存在http开头的图片链接,则更新为绝对链接308 if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") {309 src = strings.TrimPrefix(src, domain)310 s.SetAttr("src", src)311 }312 }313 })314 htmlNew, _ = doc.Find("body").Html()315 return316}317//从HTML中提取图片文件,并删除318func (c *CloudStore) DeleteImageFromHtml(htmlStr string) {319 doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlStr))320 if err != nil {321 helper.Logger.Error(err.Error())322 return323 }324 var objects []string325 domain := c.GetPublicDomain()326 doc.Find("img").Each(func(i int, s *goquery.Selection) {327 // For each item found, get the band and title328 if src, exist := s.Attr("src"); exist {329 //不存在http开头的图片链接,则更新为绝对链接330 if !(strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://")) {331 objects = append(objects, src)332 } else {333 src = strings.TrimPrefix(src, domain)334 objects = append(objects, src)335 }336 }337 })338 if err = c.Delete(objects...); err != nil {339 helper.Logger.Error(err.Error())340 }341}342func (c *CloudStore) PingTest() (err error) {343 tmpFile := "dochub-test-file.txt"344 saveFile := "dochub-test-file.txt"345 text := "hello world"346 defer func() {347 if err != nil {348 err = fmt.Errorf("Bucket是否私有:%v,错误信息:%v", c.Private, err.Error())349 }350 }()351 err = ioutil.WriteFile(tmpFile, []byte(text), os.ModePerm)352 if err != nil {353 return err354 }355 defer os.Remove(tmpFile)356 if err = c.Upload(tmpFile, saveFile); err != nil {357 return358 }359 if err = c.IsExist(saveFile); err != nil {360 return361 }362 if !helper.Debug {363 if err = c.Delete(saveFile); err != nil {364 return365 }366 }367 return368}369func (c *CloudStore) GetPublicDomain() (domain string) {370 object := "test.dochub.test"371 link := c.GetSignURL(object)372 return strings.TrimRight(strings.Split(link, object)[0], "/")373}...

Full Screen

Full Screen

store_model.go

Source:store_model.go Github

copy

Full Screen

1package instance2import (3 "fmt"4 "github.com/cilidm/toolbox/store/cloud"5 "io/ioutil"6 "os"7 "strings"8)9type Config struct {10 AccessKey string11 SecretKey string12 Endpoint string13 Region string14 AppId string15 PublicBucket string16 PublicBucketDomain string17 PrivateBucket string18 PrivateBucketDomain string19 Expire int6420 CloudType StoreType21}22type StoreType string23var (24 Oss StoreType = "oss" //oss存储25 Minio StoreType = "minio" //minio存储26 Cos StoreType = "cos" //腾讯云存储27 Obs StoreType = "obs" //华为云存储28 Bos StoreType = "bos" //百度云存储29 Qiniu StoreType = "qiniu" //七牛云储存30 Upyun StoreType = "upyun" //又拍云存储31)32type ConfigOss struct {33 AccessKey string `store:"access-key" fieldName:"AccessKey"`34 SecretKey string `store:"secret-key" fieldName:"SecretKey"`35 Endpoint string `store:"endpoint" fieldName:"Endpoint"`36 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`37 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`38 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`39 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`40 Expire int64 `store:"expire" fieldName:"Expire"`41}42type ConfigMinio struct {43 AccessKey string `store:"access-key" fieldName:"AccessKey"`44 SecretKey string `store:"secret-key" fieldName:"SecretKey"`45 Endpoint string `store:"endpoint" fieldName:"Endpoint"`46 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`47 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`48 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`49 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`50 Expire int64 `store:"expire" fieldName:"Expire"`51}52type ConfigCos struct {53 AccessKey string `store:"access-key" fieldName:"AccessKey"`54 SecretKey string `store:"secret-key" fieldName:"SecretKey"`55 Region string `store:"region" fieldName:"Region"`56 AppId string `store:"app-id" fieldName:"AppId"`57 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`58 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`59 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`60 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`61 Expire int64 `store:"expire" fieldName:"Expire"`62}63type ConfigBos struct {64 AccessKey string `store:"access-key" fieldName:"AccessKey"`65 SecretKey string `store:"secret-key" fieldName:"SecretKey"`66 Endpoint string `store:"endpoint" fieldName:"Endpoint"`67 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`68 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`69 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`70 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`71 Expire int64 `store:"expire" fieldName:"Expire"`72}73type ConfigObs struct {74 AccessKey string `store:"access-key" fieldName:"AccessKey"`75 SecretKey string `store:"secret-key" fieldName:"SecretKey"`76 Endpoint string `store:"endpoint" fieldName:"Endpoint"`77 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`78 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`79 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`80 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`81 Expire int64 `store:"expire" fieldName:"Expire"`82}83type ConfigQiniu struct {84 AccessKey string `store:"access-key" fieldName:"AccessKey"`85 SecretKey string `store:"secret-key" fieldName:"SecretKey"`86 Endpoint string `store:"endpoint" fieldName:"Endpoint"`87 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`88 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`89 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`90 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`91 Expire int64 `store:"expire" fieldName:"Expire"`92}93type ConfigUpYun struct {94 AccessKey string `store:"access-key" fieldName:"AccessKey"`95 SecretKey string `store:"secret-key" fieldName:"SecretKey"`96 Endpoint string `store:"endpoint" fieldName:"Endpoint"`97 PublicBucket string `store:"public-bucket" fieldName:"PublicBucket"`98 PublicBucketDomain string `store:"public-bucket-domain" fieldName:"PublicBucketDomain"`99 PrivateBucket string `store:"private-bucket" fieldName:"PrivateBucket"`100 PrivateBucketDomain string `store:"private-bucket-domain" fieldName:"PrivateBucketDomain"`101 Expire int64 `store:"expire" fieldName:"Expire"`102}103type CloudStore struct {104 Private bool105 StoreType StoreType106 CanGZIP bool107 Client interface{}108 Config interface{}109 Expire int64110 PublicDomain string111 PrivateDomain string112}113func (c *CloudStore) Lists(object string) (files []cloud.File, err error) {114 switch c.StoreType {115 case Cos:116 files, err = c.Client.(*cloud.COS).Lists(object)117 case Oss:118 files, err = c.Client.(*cloud.OSS).Lists(object)119 case Bos:120 files, err = c.Client.(*cloud.BOS).Lists(object)121 case Obs:122 files, err = c.Client.(*cloud.OBS).Lists(object)123 case Upyun:124 files, err = c.Client.(*cloud.UpYun).Lists(object)125 case Minio:126 files, err = c.Client.(*cloud.MinIO).Lists(object)127 case Qiniu:128 files, err = c.Client.(*cloud.QINIU).Lists(object)129 }130 return131}132func (c *CloudStore) Upload(tmpFile, saveFile string, headers ...map[string]string) (err error) {133 switch c.StoreType {134 case Cos:135 err = c.Client.(*cloud.COS).Upload(tmpFile, saveFile, headers...)136 case Oss:137 err = c.Client.(*cloud.OSS).Upload(tmpFile, saveFile, headers...)138 case Bos:139 err = c.Client.(*cloud.BOS).Upload(tmpFile, saveFile, headers...)140 case Obs:141 err = c.Client.(*cloud.OBS).Upload(tmpFile, saveFile, headers...)142 case Upyun:143 err = c.Client.(*cloud.UpYun).Upload(tmpFile, saveFile, headers...)144 case Minio:145 err = c.Client.(*cloud.MinIO).Upload(tmpFile, saveFile, headers...)146 case Qiniu:147 err = c.Client.(*cloud.QINIU).Upload(tmpFile, saveFile, headers...)148 }149 return150}151func (c *CloudStore) Delete(objects ...string) (err error) {152 switch c.StoreType {153 case Cos:154 err = c.Client.(*cloud.COS).Delete(objects...)155 case Oss:156 err = c.Client.(*cloud.OSS).Delete(objects...)157 case Bos:158 err = c.Client.(*cloud.BOS).Delete(objects...)159 case Obs:160 err = c.Client.(*cloud.OBS).Delete(objects...)161 case Upyun:162 err = c.Client.(*cloud.UpYun).Delete(objects...)163 case Minio:164 err = c.Client.(*cloud.MinIO).Delete(objects...)165 case Qiniu:166 err = c.Client.(*cloud.QINIU).Delete(objects...)167 }168 return169}170// err 返回 nil,表示文件存在,否则表示文件不存在171func (c *CloudStore) IsExist(object string) (err error) {172 switch c.StoreType {173 case Cos:174 err = c.Client.(*cloud.COS).IsExist(object)175 case Oss:176 err = c.Client.(*cloud.OSS).IsExist(object)177 case Bos:178 err = c.Client.(*cloud.BOS).IsExist(object)179 case Obs:180 err = c.Client.(*cloud.OBS).IsExist(object)181 case Upyun:182 err = c.Client.(*cloud.UpYun).IsExist(object)183 case Minio:184 err = c.Client.(*cloud.MinIO).IsExist(object)185 case Qiniu:186 err = c.Client.(*cloud.QINIU).IsExist(object)187 }188 return189}190func (c *CloudStore) PingTest() (err error) {191 tmpFile := "mybed-test-file.txt"192 saveFile := "mybed-test-file.txt"193 text := "hello world"194 defer func() {195 if err != nil {196 err = fmt.Errorf("Bucket是否私有:%v,错误信息:%v", c.Private, err.Error())197 }198 }()199 err = ioutil.WriteFile(tmpFile, []byte(text), os.ModePerm)200 if err != nil {201 return err202 }203 defer os.Remove(tmpFile)204 if err = c.Upload(tmpFile, saveFile); err != nil {205 return206 }207 if err = c.IsExist(saveFile); err != nil {208 return209 }210 if err = c.Delete(saveFile); err != nil {211 return212 }213 return214}215//设置默认图片216//@param picture 图片文件或者图片文件md5等217//@param ext 图片扩展名,如果图片文件参数(picture)的值为md5时,需要加上后缀扩展名218//@return link 图片url链接219func (c *CloudStore) getImageFromCloudStore(picture string, ext ...string) (link string) {220 if len(ext) > 0 {221 picture = picture + "." + ext[0]222 } else if !strings.Contains(picture, ".") && len(picture) > 0 {223 picture = picture + ".jpg"224 }225 if c == nil || c.Client == nil {226 return227 }228 return c.GetSignURL(picture)229}230func (c *CloudStore) GetSignURL(object string) (link string) {231 var err error232 switch c.StoreType {233 case Cos:234 link, err = c.Client.(*cloud.COS).GetSignURL(object, c.Expire)235 case Oss:236 link, err = c.Client.(*cloud.OSS).GetSignURL(object, c.Expire)237 case Bos:238 link, err = c.Client.(*cloud.BOS).GetSignURL(object, c.Expire)239 case Obs:240 link, err = c.Client.(*cloud.OBS).GetSignURL(object, c.Expire)241 case Upyun:242 link, err = c.Client.(*cloud.UpYun).GetSignURL(object, c.Expire)243 case Minio:244 link, err = c.Client.(*cloud.MinIO).GetSignURL(object, c.Expire)245 case Qiniu:246 link, err = c.Client.(*cloud.QINIU).GetSignURL(object, c.Expire)247 }248 if err != nil {249 fmt.Println(err)250 }251 return252}253func (c *CloudStore) GetPublicDomain() (domain string) {254 object := "test.test"255 link := c.GetSignURL(object)256 return strings.TrimRight(strings.Split(link, object)[0], "/")257}...

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 minioClient, err := minio.New("localhost:9000", "minio", "minio123", true)4 if err != nil {5 log.Fatalln(err)6 }7 err = minioClient.MakeBucket(bucketName, location)8 if err != nil {9 exists, errBucketExists := minioClient.BucketExists(bucketName)10 if errBucketExists == nil && exists {11 log.Printf("We already own %s12 } else {13 log.Fatalln(err)14 }15 } else {16 log.Printf("Successfully created %s17 }18 n, err := minioClient.FPutObject(bucketName, objectName, filePath, "application/zip")19 if err != nil {20 log.Fatalln(err)21 }22 log.Printf("Successfully uploaded %s of size %d23 n, err = minioClient.FPutObject(bucketName, objectName, filePath, "application/zip")24 if err != nil {25 log.Fatalln(err)26 }27 log.Printf("Successfully uploaded %s of size %d28 n, err = minioClient.FPutObject(bucketName, objectName, filePath, "application/zip")29 if err != nil {30 log.Fatalln(err)31 }

Full Screen

Full Screen

SaveFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var k = koanf.New(".")4 if err := k.Load(file.Provider("config.json"), json.Parser()); err != nil {5 panic(err)6 }7 minioClient, err := minio.New(k.String("minio.endpoint"), k.String("minio.accessKeyID"), k.String("minio.secretAccessKey"), k.Bool("minio.useSSL"))8 if err != nil {9 fmt.Println(err)10 }11 err = minioClient.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: location})12 if err != nil {13 exists, errBucketExists := minioClient.BucketExists(context.Background(), bucketName)14 if errBucketExists == nil && exists {15 fmt.Printf("We already own %s16 } else {17 fmt.Println(err)18 }19 } else {20 fmt.Printf("Successfully created %s21 }22 n, err := minioClient.FPutObject(context.Background(), bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})23 if err != nil {24 fmt.Println(err)25 }26 fmt.Println("Successfully uploaded bytes: ", n)27 err = minioClient.FGetObject(context.Background(), bucketName, objectName, "/tmp/my-testfile.zip", minio.GetObjectOptions{})28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println("

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful