diff --git a/golang_learn/data_func/go_to_http/demo03/main.exe.manifest b/golang_learn/data_func/go_to_http/demo03/main.exe.manifest new file mode 100644 index 0000000..cfd49f2 --- /dev/null +++ b/golang_learn/data_func/go_to_http/demo03/main.exe.manifest @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/golang_learn/data_func/go_to_http/demo03/main.go b/golang_learn/data_func/go_to_http/demo03/main.go new file mode 100644 index 0000000..16c580b --- /dev/null +++ b/golang_learn/data_func/go_to_http/demo03/main.go @@ -0,0 +1,91 @@ +package main + +import ( + "archive/zip" + "io" + "log" + "net/http" + "os" + "path/filepath" +) + +func main() { + + if err := UnZip("help.7z", "./web/static/help"); err != nil { + log.Fatalln(err) + } + if err := UnZip("jsmap.7z", "./src/main/resources/static/jsmap"); err != nil { + log.Fatalln(err) + } + if err := UnZip("template.7z", "./src/main/resources/static/template"); err != nil { + log.Fatalln(err) + } + +} + +func getFile(url, fileName string) { + res, err := http.Get(url) + if err != nil { + panic(err) + } + f, err := os.Create(fileName) + if err != nil { + panic(err) + } + _, _ = io.Copy(f, res.Body) +} + +func UnZip(dst, src string) (err error) { + // 打开压缩文件,这个 zip 包有个方便的 ReadCloser 类型 + // 这个里面有个方便的 OpenReader 函数,可以比 tar 的时候省去一个打开文件的步骤 + zr, err := zip.OpenReader(src) + defer zr.Close() + if err != nil { + return + } + + // 如果解压后不是放在当前目录就按照保存目录去创建目录 + if dst != "" { + if err := os.MkdirAll(dst, 0755); err != nil { + return err + } + } + + // 遍历 zr ,将文件写入到磁盘 + for _, file := range zr.File { + path := filepath.Join(dst, file.Name) + + // 如果是目录,就创建目录 + if file.FileInfo().IsDir() { + if err := os.MkdirAll(path, file.Mode()); err != nil { + return err + } + // 因为是目录,跳过当前循环,因为后面都是文件的处理 + continue + } + + // 获取到 Reader + fr, err := file.Open() + if err != nil { + return err + } + + // 创建要写出的文件对应的 Write + fw, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, file.Mode()) + if err != nil { + return err + } + + _, err = io.Copy(fw, fr) + if err != nil { + return err + } + + // 因为是在循环中,无法使用 defer ,直接放在最后 + // 不过这样也有问题,当出现 err 的时候就不会执行这个了, + // 可以把它单独放在一个函数中,这里是个实验,就这样了 + fw.Close() + fr.Close() + } + return nil +} diff --git a/golang_learn/data_func/go_to_http/demo03/main.ico b/golang_learn/data_func/go_to_http/demo03/main.ico new file mode 100644 index 0000000..ef587a6 Binary files /dev/null and b/golang_learn/data_func/go_to_http/demo03/main.ico differ diff --git a/golang_learn/data_func/go_to_http/demo03/main.syso b/golang_learn/data_func/go_to_http/demo03/main.syso new file mode 100644 index 0000000..745aab4 Binary files /dev/null and b/golang_learn/data_func/go_to_http/demo03/main.syso differ diff --git a/golang_learn/data_func/go_to_nuxui/demo01/main.go b/golang_learn/data_func/go_to_nuxui/demo01/main.go index 4663825..7c35246 100644 --- a/golang_learn/data_func/go_to_nuxui/demo01/main.go +++ b/golang_learn/data_func/go_to_nuxui/demo01/main.go @@ -1,11 +1,12 @@ package main import ( + "nuxui.org/nuxui/nux" _ "nuxui.org/nuxui/ui" ) func main() { - /* nux.Run(nux.NewWindow(nux.Attr{ + nux.Run(nux.NewWindow(nux.Attr{ "width": "15%", // screen_width x 15% "height": "2:1", // width : height = 2 : 1 "title": "hello", @@ -13,6 +14,6 @@ func main() { "type": "nuxui.org/nuxui/ui.Text", "text": `Hello nuxui`, }, - }))*/ + })) }