小编xic*_*hen的帖子

使用Go的存档/ zip创建包含Unicode文件名的zip存档

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)

string unicode zip go

4
推荐指数
1
解决办法
991
查看次数

Go中如何获取系统信息?

谁能推荐一个可用于获取系统信息的模块,例如 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)

go

2
推荐指数
2
解决办法
1万
查看次数

如何在golang中使用regexp获取url模式?

如何使用正则表达式匹配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)

regex http url-routing go

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

go ×3

http ×1

regex ×1

string ×1

unicode ×1

url-routing ×1

zip ×1