多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> ### Zip压缩 ~~~ package main import ( "archive/zip" "path/filepath" "os" "io" "fmt" ) func Zip(srcFile string, destZip string) error { zipfile, err := os.Create(destZip) if err != nil { return err } defer zipfile.Close() archive := zip.NewWriter(zipfile) defer archive.Close() filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error { if err != nil { return err } header, err := zip.FileInfoHeader(info) if err != nil { return err } header.Name = path if info.IsDir() { header.Name += "/" } else { header.Method = zip.Deflate } writer, err := archive.CreateHeader(header) if err != nil { return err } if ! info.IsDir() { file, err := os.Open(path) if err != nil { return err } defer file.Close() _, err = io.Copy(writer, file) } return err }) return err } func main() { if err := Zip(os.Args[1], os.Args[2]); err != nil { fmt.Println(err.Error()) } } ~~~