使用Ubuntu系统部署FastDFS系统,参见:
https://www.cnblogs.com/Leo_wl/p/6731647.html
如果编译安装过程中有报错,可用以下办法解决:
下载最新版nginx: wget -c https:
//nginx.org/download/nginx-1.12.1.tar.gz
下载最新版fastdfs-nginx-module: wget
https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
下载最新版libfastcommon: wget
https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
目前go语言没有发布使用api,可参看:
git clone https://github.com/tedcy/fdfs_client
测试程序如下:
package main
import (
"fdfs_client"
"fmt"
"sync"
)
func TestUpload() {
client, err := fdfs_client.NewClientWithConfig("fdfs.conf")
defer client.Destory()
if err != nil {
fmt.Println("NewClientWithConfig", err.Error())
return
}
fileId, err := client.UploadByFilename("ddd.txt")
if err != nil {
fmt.Println("UploadByFilename", err.Error())
return
}
fmt.Println("fileId:", fileId)
if err := client.DownloadToFile(fileId, "tempFile", 0, 0); err != nil {
fmt.Println("UploadByFilename:", err.Error())
return
}
if buffer, err := client.DownloadToBuffer(fileId, 0, 0); err != nil {
fmt.Println("DownloadToBuffer:", err.Error())
} else {
fmt.Println("DownloadToBuffer:", string(buffer))
}
if err := client.DeleteFile(fileId); err != nil {
fmt.Println("DeleteFile", err.Error())
return
}
}
func TestUploadFile100() {
client, err := fdfs_client.NewClientWithConfig("fdfs.conf")
defer client.Destory()
if err != nil {
fmt.Println(err.Error())
return
}
var wg sync.WaitGroup
for i := 0; i != 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j != 10; j++ {
if fileId, err := client.UploadByFilename("ddd.txt"); err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(fileId)
if _, err := client.DownloadToBuffer(fileId, 0, 0); err != nil {
fmt.Println(err.Error())
}
if err := client.DeleteFile(fileId); err != nil {
fmt.Println(err.Error())
}
}
}
}()
}
wg.Wait()
}
func TestUploadBuffer100() {
client, err := fdfs_client.NewClientWithConfig("fdfs.conf")
defer client.Destory()
if err != nil {
fmt.Println(err.Error())
return
}
var wg sync.WaitGroup
for i := 0; i != 1; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j != 1; j++ {
if fileId, err := client.UploadByBuffer([]byte("hello world"), "go"); err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(fileId)
if _, err := client.DownloadToBuffer(fileId, 0, 0); err != nil {
fmt.Println(err.Error())
}
//if err := client.DeleteFile(fileId); err != nil {
// fmt.Println(err.Error())
// }
}
}
}()
}
wg.Wait()
}
func main() {
//TestUpload()
//TestUploadFile100()
TestUploadBuffer100()
}