| @@ -8,12 +8,13 @@ require ( | |||||
| github.com/go-ping/ping v1.1.0 | github.com/go-ping/ping v1.1.0 | ||||
| github.com/imdario/mergo v0.3.15 | github.com/imdario/mergo v0.3.15 | ||||
| github.com/ipfs/go-ipfs-api v0.6.0 | github.com/ipfs/go-ipfs-api v0.6.0 | ||||
| github.com/magefile/mage v1.15.0 | |||||
| github.com/mitchellh/mapstructure v1.5.0 | github.com/mitchellh/mapstructure v1.5.0 | ||||
| github.com/otiai10/copy v1.12.0 | |||||
| github.com/samber/lo v1.36.0 | github.com/samber/lo v1.36.0 | ||||
| github.com/sirupsen/logrus v1.9.2 | github.com/sirupsen/logrus v1.9.2 | ||||
| github.com/smartystreets/goconvey v1.8.0 | github.com/smartystreets/goconvey v1.8.0 | ||||
| github.com/zyedidia/generic v1.2.1 | github.com/zyedidia/generic v1.2.1 | ||||
| gitlink.org.cn/cloudream/proto v0.0.0 | |||||
| go.etcd.io/etcd/client/v3 v3.5.9 | go.etcd.io/etcd/client/v3 v3.5.9 | ||||
| golang.org/x/exp v0.0.0-20230519143937-03e91628a987 | golang.org/x/exp v0.0.0-20230519143937-03e91628a987 | ||||
| ) | ) | ||||
| @@ -66,4 +67,4 @@ require ( | |||||
| ) | ) | ||||
| // 运行go mod tidy时需要将下面几行取消注释 | // 运行go mod tidy时需要将下面几行取消注释 | ||||
| replace gitlink.org.cn/cloudream/proto => ../proto | |||||
| //replace gitlink.org.cn/cloudream/proto => ../proto | |||||
| @@ -54,6 +54,8 @@ github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFG | |||||
| github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= | github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= | ||||
| github.com/libp2p/go-libp2p v0.26.3 h1:6g/psubqwdaBqNNoidbRKSTBEYgaOuKBhHl8Q5tO+PM= | github.com/libp2p/go-libp2p v0.26.3 h1:6g/psubqwdaBqNNoidbRKSTBEYgaOuKBhHl8Q5tO+PM= | ||||
| github.com/libp2p/go-libp2p v0.26.3/go.mod h1:x75BN32YbwuY0Awm2Uix4d4KOz+/4piInkp4Wr3yOo8= | github.com/libp2p/go-libp2p v0.26.3/go.mod h1:x75BN32YbwuY0Awm2Uix4d4KOz+/4piInkp4Wr3yOo8= | ||||
| github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= | |||||
| github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | |||||
| github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= | github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= | ||||
| github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= | github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= | ||||
| github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||||
| @@ -78,6 +80,9 @@ github.com/multiformats/go-multistream v0.4.1 h1:rFy0Iiyn3YT0asivDUIR05leAdwZq3d | |||||
| github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= | github.com/multiformats/go-multistream v0.4.1/go.mod h1:Mz5eykRVAjJWckE2U78c6xqdtyNUEhKSM0Lwar2p77Q= | ||||
| github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= | github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= | ||||
| github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= | github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= | ||||
| github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY= | |||||
| github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww= | |||||
| github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks= | |||||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| @@ -0,0 +1,101 @@ | |||||
| package magefiles | |||||
| import ( | |||||
| "errors" | |||||
| "fmt" | |||||
| "os" | |||||
| "path/filepath" | |||||
| "strings" | |||||
| "github.com/magefile/mage/sh" | |||||
| cp "github.com/otiai10/copy" | |||||
| ) | |||||
| var Global = struct { | |||||
| OS string | |||||
| Arch string | |||||
| }{ | |||||
| Arch: "amd64", | |||||
| } | |||||
| type BuildArgs struct { | |||||
| OutputName string | |||||
| OutputDir string | |||||
| AssetsDir string | |||||
| } | |||||
| type goBuildArgs struct { | |||||
| Env map[string]string | |||||
| OutputExt string | |||||
| } | |||||
| func Build(args BuildArgs) error { | |||||
| fullOutputDir, err := filepath.Abs(args.OutputDir) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| goBuildArgs, err := makeGoBuildArgs() | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| binPath := filepath.Join(fullOutputDir, args.OutputName+goBuildArgs.OutputExt) | |||||
| fmt.Printf("building to %s\n", binPath) | |||||
| err = sh.RunWith(goBuildArgs.Env, "go", "build", "-o", binPath) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| if args.AssetsDir != "" { | |||||
| outputAssetsPath := fullOutputDir | |||||
| fmt.Printf("copying asset to %s\n", outputAssetsPath) | |||||
| return CopyAssets(args.AssetsDir, outputAssetsPath) | |||||
| } | |||||
| return nil | |||||
| } | |||||
| func makeGoBuildArgs() (goBuildArgs, error) { | |||||
| args := goBuildArgs{ | |||||
| Env: make(map[string]string), | |||||
| } | |||||
| if Global.OS == "win" { | |||||
| args.OutputExt = ".exe" | |||||
| args.Env["CGO_ENABLE"] = "0" | |||||
| args.Env["GOOS"] = "windows" | |||||
| } else if Global.OS == "linux" { | |||||
| args.OutputExt = "" | |||||
| args.Env["CGO_ENABLE"] = "0" | |||||
| args.Env["GOOS"] = "linux" | |||||
| } else if Global.OS != "" { | |||||
| return goBuildArgs{}, fmt.Errorf("unknow os type: %s", Global.OS) | |||||
| } | |||||
| var pltParts []string | |||||
| if Global.OS != "" { | |||||
| pltParts = append(pltParts, Global.OS) | |||||
| } | |||||
| if Global.Arch != "" { | |||||
| pltParts = append(pltParts, Global.Arch) | |||||
| } | |||||
| if len(pltParts) == 0 { | |||||
| fmt.Print("building platform is not set, will build for current machine.\n") | |||||
| } else { | |||||
| fmt.Printf("building for %s.\n", strings.Join(pltParts, "-")) | |||||
| } | |||||
| return args, nil | |||||
| } | |||||
| func CopyAssets(assrtDir string, targetDir string) error { | |||||
| info, err := os.Stat(assrtDir) | |||||
| if errors.Is(err, os.ErrNotExist) || !info.IsDir() { | |||||
| return nil | |||||
| } | |||||
| return cp.Copy(assrtDir, targetDir) | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| package targets | |||||
| import ( | |||||
| "gitlink.org.cn/cloudream/common/magefiles" | |||||
| ) | |||||
| // [配置项]设置编译平台为windows | |||||
| func Win() { | |||||
| magefiles.Global.OS = "win" | |||||
| } | |||||
| // [配置项]设置编译平台为linux | |||||
| func Linux() { | |||||
| magefiles.Global.OS = "linux" | |||||
| } | |||||
| // [配置项]设置编译架构为amd64 | |||||
| func AMD64() { | |||||
| magefiles.Global.Arch = "amd64" | |||||
| } | |||||
| @@ -1,5 +1,7 @@ | |||||
| package grpc | package grpc | ||||
| // TODO 拆分到存储服务的common包里去 | |||||
| /* | |||||
| import ( | import ( | ||||
| "context" | "context" | ||||
| "fmt" | "fmt" | ||||
| @@ -118,3 +120,4 @@ func SendFileAsStream(client proto.FileTransportClient) (myio.PromiseWriteCloser | |||||
| stream: stream, | stream: stream, | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| */ | |||||