package main
import (
"archive/zip"
"fmt"
"io"
"os"
"path/filepath"
"strings"
)
func main() {
var (
Path = os.Args[1]
Name = os.Args[2]
)
File, _ := os.Create(Name)
PS := strings.Split(Path, "\\")
PathName := strings.Join(PS[:len(PS)-1], "\\")
os.Chdir(PathName)
Path = PS[len(PS)-1]
defer File.Close()
Zip := zip.NewWriter(File)
defer Zip.Close()
walk := func(Path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
return err
}
if info.IsDir() {
return nil
}
Src, _ := os.Open(Path)
defer Src.Close()
fmt.Println(Path)
FileName, _ …Run Code Online (Sandbox Code Playgroud) 谁能推荐一个可用于获取系统信息的模块,例如 Python 的psutil?
当我尝试时>go get github.com/golang/sys get 'sys',我收到以下信息:
Report Error:
package github.com/golang/sys
imports github.com/golang/sys
imports github.com/golang/sys: no buildable Go source files in D:\go_source\src\github.com\golang\sys
Run Code Online (Sandbox Code Playgroud)
这是我的系统环境:
# native compiler windows amd64
GOROOT=D:\Go
#GOBIN=
GOARCH=amd64
GOOS=windows
CGO_ENABLED=1
PATH=c:\mingw64\bin;%GOROOT%\bin;%PATH%
LITEIDE_GDB=gdb64
LITEIDE_MAKE=mingw32-make
LITEIDE_TERM=%COMSPEC%
LITEIDE_TERMARGS=
LITEIDE_EXEC=%COMSPEC%
LITEIDE_EXECOPT=/C
Run Code Online (Sandbox Code Playgroud) 如何使用正则表达式匹配URL,它决定使用相应的函数处理
package main
import(
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/pattern", resolve)
http.ListenAndServe(":8080", nil)
}
func resolve(w http.ResponseWriter, r * http.Request) {
fmt.Println(r.URL.Host)
}
Run Code Online (Sandbox Code Playgroud)