脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Golang - 适合PHP同学的GoFrame框架使用体验及学习建议

适合PHP同学的GoFrame框架使用体验及学习建议

2022-10-18 11:31王中阳Go Golang

这篇文章主要为大家介绍了非常适合PHP同学使用的GoFrame框架设计思想使用体验及学习建议介绍,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

前言

今天继续为大家更新Go语言学习记录的文章,介绍最近发现的一款非常优秀的框架GoFrame

最近发现了一款非常好用的基于go语言的web开发框架,非常适合PHP转Go的同学使用,在很多设计思想和使用上和PHP的Laravel框架非常像。

今天就为大家简单介绍一下GoFrame的特点

官方介绍

GoFrame是一款模块化、高性能、企业级的Go基础开发框架。GoFrame不是一款WEB/RPC框架,而是一款通用性的基础开发框架,是Golang标准库的一个增强扩展级,包含通用核心的基础开发组件,优点是实战化、模块化、文档全面、模块丰富、易用性高、通用性强、面向团队。

我的使用体验

官方文档详细介绍了框架特点,我就不赘述了。

下面我以一个使用者和学习者的角度分享一下我的学习体会。

设计思想

设计思想是GoFrame框架的灵魂,同时对于使用者来讲,是不可或缺的内功心法。GoFrame有其独特的设计思想,理解了GoFrame的设计思想,您就理解了GoFrame的全部。

和PHP的Laravel一样,goframe的设计思想非常值得我们学习和借鉴。

学习建议

有基础的同学

有基础的同学,建议可以简单熟悉一下框架设计、操作一下快速开始,然后就重点阅读 核心组件

尤其是数据库ORM需要重点看一下,熟悉Laravel Eloquent的同学看起来应该比较轻松,很多使用和习惯是比较像的。

下面我举个实例让大家体会一下,从一些细节设计上我们能明显感觉到设计者对PHP转go开发者的友好。

对象管理相关:

Array也是切片的别名,猜测是为了迎合PHP转go的使用习惯,PHP的array和golang的slice切片更像,因为go的数组的固定长度的。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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语言学习专栏,然后再看goframe的框架。

因为只有搞清楚Go语言基础后,才能更好的理解goframe的优势和使用技巧。

就像我们做PHP的时候,一定是先学习PHP的基础语法,然后才学TP、Laravel这类框架的。

对于有PHP基础,只是没有go语言基础的同学来讲,转go还是比较轻松的。

可能只是不能像PHP那么灵活,那么随心所欲的写代码了,尝试一下GO语言苛刻的规范化开发也未尝不是一种享受。

官网地址

复制粘贴的重复工作我就不做了,更多内容建议大家查看下方的官网。

目前最新的2.0版本

小坑

在看文档过程中,我们不能很明显的知道当前文档的版本,这个问题我已经提交给社区了,目前的阅读建议是这样,我们把页面拉到最上面,点击左上角这里进行版本切换。

适合PHP同学的GoFrame框架使用体验及学习建议

以上就是适合PHP同学的GoFrame框架的使用体验及学习建议的详细内容,更多关于GoFrame框架学习建议的资料请关注服务器之家其它相关文章!

原文链接:https://juejin.cn/post/7075098594151235597

延伸 · 阅读

精彩推荐