GoFrame是一款模塊化、高性能、企業級的Go基礎開發框架。GoFrame不是一款WEB/RPC框架,而是一款通用性的基礎開發框架,是Golang標準庫的一個增強擴展級,包含通用核心的基礎開發組件,優點是實戰化、模塊化、文檔全面、模塊豐富、易用性高、通用性強、面向團隊。
最近發現了一款非常好用的基于go語言的web開發框架,非常適合PHP轉Go的同學使用,在很多設計思想和使用上和PHP的Laravel框架非常像。
今天就為大家簡單介紹一下GoFrame的特點:
官方介紹
GoFrame是一款模塊化、高性能、企業級的Go基礎開發框架。GoFrame不是一款WEB/RPC框架,而是一款通用性的基礎開發框架,是Golang標準庫的一個增強擴展級,包含通用核心的基礎開發組件,優點是實戰化、模塊化、文檔全面、模塊豐富、易用性高、通用性強、面向團隊。
我的使用體驗
官方文檔詳細介紹了框架特點,我就不贅述了。
下面我以一個使用者和學習者的角度分享一下我的學習體會。
設計思想
設計思想是GoFrame框架的靈魂,同時對于使用者來講,是不可或缺的內功心法。GoFrame有其獨特的設計思想,理解了GoFrame的設計思想,您就理解了GoFrame的全部。
和PHP的Laravel一樣,goframe的設計思想非常值得我們學習和借鑒。
學習建議
有基礎的同學
有基礎的同學,建議可以簡單熟悉一下框架設計、操作一下快速開始,然后就重點閱讀 核心組件[1]
尤其是數據庫ORM需要重點看一下,熟悉Laravel Eloquent的同學看起來應該比較輕松,很多使用和習慣是比較像的。
下面我舉個實例讓大家體會一下,從一些細節設計上我們能明顯感覺到設計者對PHP轉go開發者的友好。
對象管理相關:
Array也是切片的別名,猜測是為了迎合PHP轉go的使用習慣,PHP的array和golang的slice切片更像,因為Go的數組是固定長度的。
type(
Var = gvar.Var //是一個通用的變量,類似泛型
Ctx = context.Context //context.Context的別名
)
//Map是對原生map的key value約定好了類型,起了別名
type(
Map = map[string]interface{}
MapAnyAny = map[interface{}]interface{} // MapAnyAny is alias of frequently-used map type map[interface{}]interface{}.
MapAnyStr = map[interface{}]string // MapAnyStr is alias of frequently-used map type map[interface{}]string.
MapAnyInt = map[interface{}]int // MapAnyInt is alias of frequently-used map type map[interface{}]int.
MapStrAny = map[string]interface{} // MapStrAny is alias of frequently-used map type map[string]interface{}.
MapStrStr = map[string]string // MapStrStr is alias of frequently-used map type map[string]string.
MapStrInt = map[string]int // MapStrInt is alias of frequently-used map type map[string]int.
MapIntAny = map[int]interface{} // MapIntAny is alias of frequently-used map type map[int]interface{}.
.
.
.
)
//List是map類型的切片
type (
List = []Map
ListAnyAny = []MapAnyAny // ListAnyAny is alias of frequently-used slice type []MapAnyAny.
ListAnyStr = []MapAnyStr // ListAnyStr is alias of frequently-used slice type []MapAnyStr.
ListAnyInt = []MapAnyInt // ListAnyInt is alias of frequently-used slice type []MapAnyInt.
ListStrAny = []MapStrAny // ListStrAny is alias of frequently-used slice type []MapStrAny.
ListStrStr = []MapStrStr // ListStrStr is alias of frequently-used slice type []MapStrStr.
ListStrInt = []MapStrInt // ListStrInt is alias of frequently-used
.
.
.
)
//Slice就是切片的別名
type(
Slice = []interface{} // Slice is alias of frequently-used slice type []interface{}.
SliceAny = []interface{} // SliceAny is alias of frequently-used slice type []interface{}.
SliceStr = []string // SliceStr is alias of frequently-used slice type []string.
SliceInt = []int // SliceInt is alias of frequently-used slice type []int.
)
//Array也是切片的別名,猜測是為了迎合PHP轉go的使用習慣,PHP的array和golang的切片更像,因為go的數組的固定長度的。
type(
Array = []interface{} // Array is alias of frequently-used slice type []interface{}.
ArrayAny = []interface{} // ArrayAny is alias of frequently-used slice type []interface{}.
ArrayStr = []string // ArrayStr is alias of frequently-used slice type []string.
ArrayInt = []int // ArrayInt is alias of frequently-used slice type []int.
)
無基礎的同學
無Go語言基礎的同學,我建議先學Go的基礎語法,可以訂閱一下我的GO語言學習專欄,好好學習一下Go基礎,然后再看Goframe的框架。
因為只有搞清楚Go語言基礎后,才能更好理解GoFrame的優勢和使用技巧。
就像我們做PHP的時候,一定是先學習PHP的基礎語法,然后才學TP、Laravel這類框架的。
對于有PHP基礎,只是沒有Go語言基礎的同學來講,轉Go還是比較輕松的。
可能只是不能像PHP那么靈活,那么隨心所欲的寫代碼了,嘗試一下GO語言苛刻的規范化開發也未嘗不是一種享受。
官網地址
復制粘貼的重復工作我就不做了,更多內容建議大家查看下方的官網。
目前最新的2.0版本[2]
小坑
在看文檔過程中,我們不能很明顯的知道當前文檔的版本,這個問題我已經提交給社區了,目前的閱讀建議是這樣,我們把頁面拉到最上面,點擊左上角這里進行版本切換。

相關資料
[1]核心組件: https://goframe.org/pages/viewpage.action?pageId=1114409
[2]目前最新的2.0版本: https://goframe.org/pages/viewpage.action?pageId=1114119
本文轉載自微信公眾號「 程序員升級打怪之旅」,作者「王中陽Go」,可以通過以下二維碼關注。

轉載本文請聯系「 程序員升級打怪之旅」公眾號。