新聞中心
最近發(fā)現(xiàn)了一款非常好用的基于go語(yǔ)言的web開發(fā)框架,非常適合PHP轉(zhuǎn)Go的同學(xué)使用,在很多設(shè)計(jì)思想和使用上和PHP的Laravel框架非常像。

成都創(chuàng)新互聯(lián)公司10多年企業(yè)網(wǎng)站設(shè)計(jì)服務(wù);為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì)及高端網(wǎng)站定制服務(wù),企業(yè)網(wǎng)站設(shè)計(jì)及推廣,對(duì)成都玻璃鋼坐凳等多個(gè)行業(yè)擁有多年的網(wǎng)站運(yùn)維經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。
今天就為大家簡(jiǎn)單介紹一下GoFrame的特點(diǎn):
官方介紹
GoFrame是一款模塊化、高性能、企業(yè)級(jí)的Go基礎(chǔ)開發(fā)框架。GoFrame不是一款WEB/RPC框架,而是一款通用性的基礎(chǔ)開發(fā)框架,是Golang標(biāo)準(zhǔn)庫(kù)的一個(gè)增強(qiáng)擴(kuò)展級(jí),包含通用核心的基礎(chǔ)開發(fā)組件,優(yōu)點(diǎn)是實(shí)戰(zhàn)化、模塊化、文檔全面、模塊豐富、易用性高、通用性強(qiáng)、面向團(tuán)隊(duì)。
我的使用體驗(yàn)
官方文檔詳細(xì)介紹了框架特點(diǎn),我就不贅述了。
下面我以一個(gè)使用者和學(xué)習(xí)者的角度分享一下我的學(xué)習(xí)體會(huì)。
設(shè)計(jì)思想
設(shè)計(jì)思想是GoFrame框架的靈魂,同時(shí)對(duì)于使用者來(lái)講,是不可或缺的內(nèi)功心法。GoFrame有其獨(dú)特的設(shè)計(jì)思想,理解了GoFrame的設(shè)計(jì)思想,您就理解了GoFrame的全部。
和PHP的Laravel一樣,goframe的設(shè)計(jì)思想非常值得我們學(xué)習(xí)和借鑒。
學(xué)習(xí)建議
有基礎(chǔ)的同學(xué)
有基礎(chǔ)的同學(xué),建議可以簡(jiǎn)單熟悉一下框架設(shè)計(jì)、操作一下快速開始,然后就重點(diǎn)閱讀 核心組件[1]
尤其是數(shù)據(jù)庫(kù)ORM需要重點(diǎn)看一下,熟悉Laravel Eloquent的同學(xué)看起來(lái)應(yīng)該比較輕松,很多使用和習(xí)慣是比較像的。
下面我舉個(gè)實(shí)例讓大家體會(huì)一下,從一些細(xì)節(jié)設(shè)計(jì)上我們能明顯感覺到設(shè)計(jì)者對(duì)PHP轉(zhuǎn)go開發(fā)者的友好。
對(duì)象管理相關(guān):
Array也是切片的別名,猜測(cè)是為了迎合PHP轉(zhuǎn)go的使用習(xí)慣,PHP的array和golang的slice切片更像,因?yàn)镚o的數(shù)組是固定長(zhǎng)度的。
type(
Var = gvar.Var //是一個(gè)通用的變量,類似泛型
Ctx = context.Context //context.Context的別名
)
//Map是對(duì)原生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也是切片的別名,猜測(cè)是為了迎合PHP轉(zhuǎn)go的使用習(xí)慣,PHP的array和golang的切片更像,因?yàn)間o的數(shù)組的固定長(zhǎng)度的。
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.
)
無(wú)基礎(chǔ)的同學(xué)
無(wú)Go語(yǔ)言基礎(chǔ)的同學(xué),我建議先學(xué)Go的基礎(chǔ)語(yǔ)法,可以訂閱一下我的GO語(yǔ)言學(xué)習(xí)專欄,好好學(xué)習(xí)一下Go基礎(chǔ),然后再看Goframe的框架。
因?yàn)橹挥懈闱宄礼o語(yǔ)言基礎(chǔ)后,才能更好理解GoFrame的優(yōu)勢(shì)和使用技巧。
就像我們做PHP的時(shí)候,一定是先學(xué)習(xí)PHP的基礎(chǔ)語(yǔ)法,然后才學(xué)TP、Laravel這類框架的。
對(duì)于有PHP基礎(chǔ),只是沒有Go語(yǔ)言基礎(chǔ)的同學(xué)來(lái)講,轉(zhuǎn)Go還是比較輕松的。
可能只是不能像PHP那么靈活,那么隨心所欲的寫代碼了,嘗試一下GO語(yǔ)言苛刻的規(guī)范化開發(fā)也未嘗不是一種享受。
官網(wǎng)地址
復(fù)制粘貼的重復(fù)工作我就不做了,更多內(nèi)容建議大家查看下方的官網(wǎng)。
目前最新的2.0版本[2]
小坑
在看文檔過(guò)程中,我們不能很明顯的知道當(dāng)前文檔的版本,這個(gè)問題我已經(jīng)提交給社區(qū)了,目前的閱讀建議是這樣,我們把頁(yè)面拉到最上面,點(diǎn)擊左上角這里進(jìn)行版本切換。
相關(guān)資料
[1]核心組件: https://goframe.org/pages/viewpage.action?pageId=1114409
[2]目前最新的2.0版本: https://goframe.org/pages/viewpage.action?pageId=1114119
本文轉(zhuǎn)載自微信公眾號(hào)「 程序員升級(jí)打怪之旅」,作者「王中陽(yáng)Go」,可以通過(guò)以下二維碼關(guān)注。
轉(zhuǎn)載本文請(qǐng)聯(lián)系「 程序員升級(jí)打怪之旅」公眾號(hào)。
標(biāo)題名稱:PHP轉(zhuǎn)Go優(yōu)選的框架:GoFrame
本文來(lái)源:http://fisionsoft.com.cn/article/dhccdhs.html


咨詢
建站咨詢
