用 gorush 來談談 Google Go

By | March 7, 2017

一直都好想寫一個 Push Notification 的 portal/server,來提供 HTTP RESTFul API 給需要 push notification 的 program。這樣可以集中處埋 push notification,各 program 不用重覆 push notification 的部份,不用 “reinventing the wheel”。

結果,我在 GitHub 這個大寶藏發現了個 grouch

gorush支援 iOS 及 Android 的 push notification,可以用 command line 快速測試,也可以用 server mode 長駐。它本身帶有 portal 及 stat API,用來查看 server 及 push 狀態,可謂一應俱全。它用 GO 寫成,這個是它的一大好處。何解?那就談談 GO。

GO 是 Google 的產品,它的歷史可以自行 Google。我第一次寫 GO 大約是 2010 年的事,近年 GO 開始廣泛使用,最著名要算得上是 Docker

GO 是 strong type 及 compiled 語言,由於 compile 成 native machine code,效能接近 C/C++,而 compile 出來的 binary 是以 static linking。Compile 出來的 binary「很大」,以 Linux x64 gorush 為例子,就有 9.7MB,但絕對值得,因為你只需把 gorush 這個單一執行檔放到 server 便可運行。由於沒有依賴庫 (library dependencies),不論放到 Ubuntu、CentOS、Fedora、Debian 或其他 Linux 都可以一檔走天下。

設定好個 YAML config,gorush 便可以 server mode 長駐運行,其他 programs 只需以 HTTP POST JSON payload 便可做到 push notification,非常簡單。