分享一个go-fastdfs client
package utils
import (
"github.com/astaxie/beego/httplib"
)
type FastDFSClient struct {
Req *httplib.BeegoHTTPRequest
}
func NewFastDFSClient(serverUrl string)*FastDFSClient{
client:=new(FastDFSClient)
client.Req= httplib.Post(serverUrl)
return client
}
func (this *FastDFSClient) Upload(filePath string)(info map[string]interface{},err error) {
info=make(map[string]interface{},0)
//clientReq:=httplib.Post(this.Url)
// only fill the file path value
this.Req.PostFile("file",filePath)
this.Req.Param("output","json")
this.Req.Param("scene","")
this.Req.Param("path","")
err=this.Req.ToJSON(&info)
return
}
package common_use
import (
"api_quant_manage_system/utils"
"github.com/spf13/viper"
"sync"
)
var fastDfsClient *utils.FastDFSClient
func InitFastDFSClient(viper *viper.Viper){
if fastDfsClient==nil{
one:=sync.Once{}
one.Do(func() {
if fastDfsClient==nil{
fastDfsClient=utils.NewFastDFSClient(viper.GetString("server_addr"))
}
})
}
}
func GetFastDfsClient()*utils.FastDFSClient{
return fastDfsClient
}