使用 gops 查看 當前 Go 程序的相關資訊

Go 的程式在執行,到底跑得怎麼樣呢?使用多少資源呢?可以使用 Go 專用的 ps 來查看~

閱讀全文〈使用 gops 查看 當前 Go 程序的相關資訊〉

如何將 Go 程式編譯成 WebAssembly

Go 1.11 之後的版本,支援可以直接將 Go 寫的內容編譯成 WebAssembly (wasm),然後搭配已經寫好的 wasm_exec.html 和 wasm_exec.js 就可以直接在頁面上執行。

  • 註:WebAssembly 在 Firefox 52+ 和 Chrome 57+/latest Opera 是預設支持的

閱讀全文〈如何將 Go 程式編譯成 WebAssembly〉

Linux CLI 查看 Git Repository 紀錄工具:GRV

Linux CLI 要查看 Git repository 的圖形顯示,可以使用 tig,視窗顯示查看可以使用 Gitk。

不過 tig 能看的比較有限,操作還是比較偏向 Git 命令列,而不是像 Gitk 上下左右的視窗可以即時看 Log、diff 等等的資料。

grv 就類同 CLI 版的 Gitk,而且執行速度很快,有空可以玩玩看~

閱讀全文〈Linux CLI 查看 Git Repository 紀錄工具:GRV〉

gorun:使用 Go 當 Script language

Golang 除了 Compile (build) 外,平常可以使用 go run 直接執行。

gorun 的作者想要在 go 的程式第一行加上類似 #!/usr/bin/go 就可以執行 .go 的作法

  • 詳見:GitHub - erning/gorun: gorun is a tool enabling one to put a "bang line" in the source code of a Go program to run it, or to run such a source code file explicitly. It was created in an attempt to make experimenting with Go more appealing to people used to Python and similar languages which operate most visibly with source code.

閱讀全文〈gorun:使用 Go 當 Script language〉

Golang 編譯給 Raspberry PI (ARM) 執行的程式

Golang 的程式寫好後,一般在 amd64 的環境編譯、執行都很簡單,但是遇到 ARM 的就需要另外指定一下。

go build example.go # 產生 example 執行檔,丟到 ARM 的機器上執行,會如下述訊息:

  • $ ./example
    -bash: ./example: cannot execute binary file: Exec format error

閱讀全文〈Golang 編譯給 Raspberry PI (ARM) 執行的程式〉

Golang 使用 mux 做 router 遇到 %2F、%0A 的解法

Go 想要做 REST API 或者要對 router、dispatcher 等等的處理,可以使用 mux 的套件。

不過 mux 的套件在 GET 資料,若內容有 "/" 就是 %2F 的話,程式會直接給 404,程式就直接結束,無法處理,要怎麼解決這個問題呢?

  • 註:%0A 是換行字元

閱讀全文〈Golang 使用 mux 做 router 遇到 %2F、%0A 的解法〉