最近发现了一款非常好用的基于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」,可以通过以下二维码关注。

转载本文请联系「 程序员升级打怪之旅」公众号。

推荐内容