From be71c34bd712369c539952d9196cee54463eef01 Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Tue, 15 Nov 2022 14:46:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=A7=A3=E5=8E=8B=E8=BD=AF?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go_to_http/demo03/main.exe.manifest | 9 ++ .../data_func/go_to_http/demo03/main.go | 91 ++++++++++++++++++ .../data_func/go_to_http/demo03/main.ico | Bin 0 -> 4286 bytes .../data_func/go_to_http/demo03/main.syso | Bin 0 -> 5122 bytes .../data_func/go_to_nuxui/demo01/main.go | 5 +- 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 golang_learn/data_func/go_to_http/demo03/main.exe.manifest create mode 100644 golang_learn/data_func/go_to_http/demo03/main.go create mode 100644 golang_learn/data_func/go_to_http/demo03/main.ico create mode 100644 golang_learn/data_func/go_to_http/demo03/main.syso 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 0000000000000000000000000000000000000000..ef587a649bc815566271185f2ca6d9ae2333cfae GIT binary patch literal 4286 zcmc&$ODMHn6n=f~g=Fw$pxmz+AO^}nF)$!Wl8J%ba!HCL6Jn;MqzFZ#Kcp}q_e+UH z?#iV^E|H1k&ic=@zSe1fdJhNr|8-ht?{~lZUC+Ajt!Wm9pNEHrf9)S80YEfiNJV%OW5}vdW!+O z-Xq{$US875$_iayU-MS1>G6AVK6-a`bw%sz>ohbpMD_Lcl%JnZadB}J7#K*-&dy|r zC2eeM81ePwK_@+*$=h=?$W z-_p{;_^?k;zTTSHj(3NLhb-IF-}3S@g@%UmYc&R9|5xx;osgfP$HzymQ`8O^&!F+~ zaS96ye zc#Ek%OZ|6ucT;a~uc+~t|INjRTOyUhnGaO18GPG&woR_7oQvbB|H|F7y5Uee(DBr=Ff3 zf-OEiK8!E*{gM4r|B#0>wm$wx3_1x$;rta1IQj79VOTfhJUe!{7yFFt@rKK@`R8*7^5B{pIt~Nen4!Xa;=h0mM zBj+QJ*Rf&W(V8 z0N$dm3w~o`qp^3WIM6|@2UEJ?j*I&*?!LIQgV76oeSNu);~c52tz~@4Nj!*u_V)JJ ze_2^s6cZD}-#I!u>gpu=sk)(G&d$zquSUNHBM)%zL;pm5m?G65vIjbzpPv)%t^NJ| ztb2BLHpRxqvRyb|MGuSz2M6-0$x&?8+W;L93-EjU@Gah7TwJhCIIHXG>Nwx<4&Ouf exBQVze5(@l0Yi@H^^tCRepF@Z%?-Z$U+G`w3)6o9 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..745aab40fad866bd92a5b9ae0f804f0a7648dc48 GIT binary patch literal 5122 zcmc&&YiJZ#6rN3@af=D5?T`ErT*p@oCT7z_8rf(hA}LKO64TT_!e)0iS+g?}cXmw| z|3vghL6A@p6cr*?DJp{c!{A#35)p%Miw_V*4O;s{#J8T_@5H-K!fak*d)Tx0F?Y^) z9`~GknQE6y0sZ}rqV)ALT!m398sOQ!zu(0(pXm087L+cyf`1rEO6U1JMQO_xQ@@Bd zSG2#0R<7u4T}qnhR5;ALGZdw>|6(z6vD}sv>$@G+!;X#=>;DqZdIkTPBmO>8``3!{ ztsIE<4>A6y&lx-`Y*IXeD+If^CpzN&E@3EG5`6}J`0#pq7DV!*D!2zXDPJfWVR9(wld885}06Avb5sAo@~KBdc-FVmqzhp4^1 zotm4Qsj8}qX3m^RIXO8bVo6u7TuI_P$%9T#K9g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^T7{LSuA4?drD?>XX2eoI zSuqDT3~ohByde?}{HP_Cn$4Ps#GKNy(uO%D-jb3)Amj~(R8PcjG{*gnY&4tW_RV%Q n;L|kQ>6HBWv$%T(ldu}lSDyg-?X{ktAMZ>1~ZgPZa%Mb3@1 literal 0 HcmV?d00001 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`, }, - }))*/ + })) }