適合PHP同學(xué)的GoFrame框架使用體驗及學(xué)習(xí)建議
前言
今天繼續(xù)為大家更新Go語言學(xué)習(xí)記錄的文章,介紹最近發(fā)現(xiàn)的一款非常優(yōu)秀的框架:GoFrame。
最近發(fā)現(xiàn)了一款非常好用的基于go語言的web開發(fā)框架,非常適合PHP轉(zhuǎn)Go的同學(xué)使用,在很多設(shè)計思想和使用上和PHP的Laravel框架非常像。
今天就為大家簡單介紹一下GoFrame的特點
官方介紹
GoFrame
是一款模塊化、高性能、企業(yè)級的Go
基礎(chǔ)開發(fā)框架。GoFrame
不是一款WEB/RPC
框架,而是一款通用性的基礎(chǔ)開發(fā)框架,是Golang
標(biāo)準(zhǔn)庫的一個增強擴展級,包含通用核心的基礎(chǔ)開發(fā)組件,優(yōu)點是實戰(zhàn)化、模塊化、文檔全面、模塊豐富、易用性高、通用性強、面向團(tuán)隊。
我的使用體驗
官方文檔詳細(xì)介紹了框架特點,我就不贅述了。
下面我以一個使用者和學(xué)習(xí)者的角度分享一下我的學(xué)習(xí)體會。
設(shè)計思想
設(shè)計思想是GoFrame框架的靈魂,同時對于使用者來講,是不可或缺的內(nèi)功心法。GoFrame有其獨特的設(shè)計思想,理解了GoFrame的設(shè)計思想,您就理解了GoFrame的全部。
和PHP的Laravel一樣,goframe的設(shè)計思想非常值得我們學(xué)習(xí)和借鑒。
學(xué)習(xí)建議
有基礎(chǔ)的同學(xué)
有基礎(chǔ)的同學(xué),建議可以簡單熟悉一下框架設(shè)計、操作一下快速開始,然后就重點閱讀 核心組件
尤其是數(shù)據(jù)庫ORM需要重點看一下,熟悉Laravel Eloquent的同學(xué)看起來應(yīng)該比較輕松,很多使用和習(xí)慣是比較像的。
下面我舉個實例讓大家體會一下,從一些細(xì)節(jié)設(shè)計上我們能明顯感覺到設(shè)計者對PHP轉(zhuǎn)go開發(fā)者的友好。
對象管理相關(guān):
Array也是切片的別名,猜測是為了迎合PHP轉(zhuǎn)go的使用習(xí)慣,PHP的array和golang的slice切片更像,因為go的數(shù)組的固定長度的。
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轉(zhuǎn)go的使用習(xí)慣,PHP的array和golang的切片更像,因為go的數(shù)組的固定長度的。 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. )
無基礎(chǔ)的同學(xué)
無go語言基礎(chǔ)的同學(xué),我建議先學(xué)go的基礎(chǔ)語法,安利一下GO語言學(xué)習(xí)專欄,然后再看goframe的框架。
因為只有搞清楚Go語言基礎(chǔ)后,才能更好的理解goframe的優(yōu)勢和使用技巧。
就像我們做PHP的時候,一定是先學(xué)習(xí)PHP的基礎(chǔ)語法,然后才學(xué)TP、Laravel這類框架的。
對于有PHP基礎(chǔ),只是沒有g(shù)o語言基礎(chǔ)的同學(xué)來講,轉(zhuǎn)go還是比較輕松的。
可能只是不能像PHP那么靈活,那么隨心所欲的寫代碼了,嘗試一下GO語言苛刻的規(guī)范化開發(fā)也未嘗不是一種享受。
官網(wǎng)地址
復(fù)制粘貼的重復(fù)工作我就不做了,更多內(nèi)容建議大家查看下方的官網(wǎng)。
小坑
在看文檔過程中,我們不能很明顯的知道當(dāng)前文檔的版本,這個問題我已經(jīng)提交給社區(qū)了,目前的閱讀建議是這樣,我們把頁面拉到最上面,點擊左上角這里進(jìn)行版本切換。
以上就是適合PHP同學(xué)的GoFrame框架的使用體驗及學(xué)習(xí)建議的詳細(xì)內(nèi)容,更多關(guān)于GoFrame框架學(xué)習(xí)建議的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Go調(diào)度器學(xué)習(xí)之系統(tǒng)調(diào)用詳解
這篇文章腫,將以一個簡單的文件打開的系統(tǒng)調(diào)用,來分析一下Go調(diào)度器在系統(tǒng)調(diào)用時做了什么。文中的示例代碼講解詳細(xì),需要的可以參考一下2023-04-04Go語言標(biāo)準(zhǔn)庫sync.Once使用場景及性能優(yōu)化詳解
這篇文章主要為大家介紹了Go語言標(biāo)準(zhǔn)庫sync.Once使用場景及性能優(yōu)化詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12Golang源碼分析之golang/sync之singleflight
golang/sync庫拓展了官方自帶的sync庫,提供了errgroup、semaphore、singleflight及syncmap四個包,本次先分析第一個包errgroup的源代碼,下面這篇文章主要給大家介紹了關(guān)于Golang源碼分析之golang/sync之singleflight的相關(guān)資料,需要的朋友可以參考下2022-11-11