GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

Overview

GoFrame

Go Doc Build Status Go Report Code Coverage Production Ready License

English | 简体中文

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

If you're a newbie to Go, you may consider GoFrame easy and great as Laravel in PHP, SpringBoot in Java or Django in Python.

Installation

go get -u -v github.com/gogf/gf

suggested using go.mod:

require github.com/gogf/gf latest

Limitation

golang version >= 1.11

Architecture

Packages

  1. Primary Package

    The gf repository maintains some basic and most commonly used packages, keeping it as lightweight and simple as possible.

  2. Community Package

    The community packages are contributed and maintained by community members, which are hosted in gogf organization. Some of the community packages are separated from the gf repository, which are not of common usage or are with heavy dependencies.

Performance

The Web component performance of GoFrame, please refer to third-party project: https://github.com/the-benchmarker/web-frameworks

Documentation

Discussion

It's recommended learning GoFrame through its awesome source codes and API reference.

License

GF is licensed under the MIT License, 100% free and open-source, forever.

Part Of Users

We list part of the users here, if your company or products are using GoFrame, please let us know here.

Contributors

This project exists thanks to all the people who contribute. [Contributors].

Donators

If you love GF, why not buy developer a cup of coffee?

Sponsors

We appreciate any kind of sponsorship for GF development. If you've got some interesting, please contact WeChat 389961817 / Email [email protected].

Thanks

JetBrains Atlassian

Issues
  • 性能问题

    性能问题

    被gf的路由注册、数据库record、自带很多常用的工具集等特点吸引过来,确实方便,花了几天时间打磨出一套快速开发平台,包括权限系统、代码生成的功能,目前也有几个系统在此平台运行。 由于系统涉及到高并发大流量的场景,我做了很多的压测,发现内存不断的增加,3种注册方式都测试过,函数注册、对象注册、控制器注册都试过,甚至函数注册逻辑只渲染一个简单的模板页面,最终结果都会导致内存不断增加,增加到2G之后我就没再做测试,等了数个小时之后,内存才降到200多M。 周末在家,我用gin实现了同样的功能,包括模板输出和json输出,在高并发的情况下,内存稳定在36M。 当然,gin用起来确实没有gf爽快,我希望作者给出内存不断增长的原因。

    bug enhancement 
    opened by piaohao 16
  • [P0]两点建议,大大有空看到请回复下

    [P0]两点建议,大大有空看到请回复下

    1.关于g.Db,当sql的debug开启时会输出一条条sql日志,目前是这样的

    [ 12 ms] [default] SHOW FULL COLUMNS FROM `users_source 
    

    希望能在链式操作上开放一个接口手动设置一个unique.让其输出变成

    [ 12 ms] [uniquestr] SHOW FULL COLUMNS FROM `users_source` 
    //伪代码:
    db.Table(table).SetUniqueStr(guid.S()).One()
    

    基本每次http请求都会对上下文设置一个workid,让sql日志也实现关联. 2.关于gvalidate.go语言的特性会对数值类型自动设置默认值0,直接导致了required的验证失效,对于数值类型的required验证希望能做成对入参的has+empty+类型验证.例如对如下的money字段验证

    例1:?money=1&uid=1//`p:"money" v:"required " 通过
    例2:?uid=1//`p:"money" v:"required " 不通过
    例3:?money=&uid=1//`p:"money" v:"required " 不通过
    
    done feature 
    opened by LonelySally 15
  • session强制缓存到内存的问题

    session强制缓存到内存的问题

    最近新上服务时发现服务内存使用过多,所以开启了pprof定位,最后定位到是使用了session的问题,从源码可以看到,每次请求结束关闭session时都会把当前session刷进内存且在内存存活的时间与session stroge一致,这样就会导致session的数据会存在两份,一份在远端存储,一份为本地内存。当请求用户基数较大时程序会占用非常大的内存且很久都无法释放 https://github.com/gogf/gf/blob/be77779affcc6b58d9841001c128956aeac750bc/os/gsession/gsession_session.go#L106

    我理解这样设计的原因是当远端session存储不可用时,可以有内存session进行兜底。 但我觉得至少也需要有方法可以限制session使用的内存,遗憾的是目前并没有发现有提供这样的方法 https://github.com/gogf/gf/blob/be77779affcc6b58d9841001c128956aeac750bc/os/gsession/gsession_manager.go#L33

    希望可以在实例化SessionManager的时候设置sessionDatalruCap大小;或者提供可选项,由开发者选择是否使用本地内存缓存session

    enhancement done 
    opened by zhoxife3ng 12
  • gconv 转换碰到问题

    gconv 转换碰到问题

    1. What version of Go and system type/arch are you using?

    go version go1.13.4 windows/amd64

    2. What version of GoFrame are you using?

    v1.13.2-0.20200701150539-76d93b3a6124

    3. Can this issue be reproduced with the latest release?

    yes

    4. What did you do?

    
    type Sub2 struct {
    	SubName string
    }
    
    type sub1 struct {
    	Sub2
    	Name string
    }
    type Test struct {
    	Sub sub1 `json:"sub"`
    }
    
    func Test_Conv(t *testing.T) {
    	data := `{
        "sub": {
            "Name": "name",
            "SubName": "subname"
        }}`
    	vdata := Test{
    		Sub: sub1{
    			Name: "name",
    			Sub2: Sub2{
    				SubName: "subname",
    			},
    		},
    	}
    	t.Run("gjson.Decode", func(t *testing.T) {
    		tx := Test{}
    		err := gjson.DecodeTo(data, &tx)
    		if err != nil {
    			t.Fatal(err)
    		}
    		gtest.AssertEQ(tx, vdata)
    	})
    	t.Run("gconv.StructDeep", func(t *testing.T) {
    		tx := Test{}
    		err := gconv.StructDeep(data, &tx)
    		if err != nil {
    			t.Fatal(err)
    		}
    		gtest.AssertEQ(tx, vdata)
    	})
    }
    

    如上测试代码

    使用gjson直接转换正常,改成使用gconv转换出来的结果不符合预期?不知是我的使用问题还是BUG?

    原始的使用场景是从配置文件直接转换成所需要的数据格式.发现异常

    g.Cfg().GetStructDeep(name,Point)
    

    目前我的解决方法

    gjson.DecodeTo(g.Cfg().GetString(name), Point)
    

    5. What did you expect to see?

    {"sub":{"SubName":"subname","Name":"name"}}
    

    6. What did you see instead?

    {"sub":{"SubName":"","Name":"name"}}
    
    bug enhancement done 
    opened by chenall 12
  • 中间件的执行逻辑问题

    中间件的执行逻辑问题

    使用的v1.9.10的GF,现有如下代码:

    package main
    
    import (
    	"fmt"
    	"net/http"
    
    	"github.com/gogf/gf/frame/g"
    	"github.com/gogf/gf/net/ghttp"
    )
    
    func MiddlewareAuth1(r *ghttp.Request) {
    	fmt.Println("middleware 1")
    	token := r.Get("token")
    	if token == "123456" {
    		r.Middleware.Next()
    	} else {
    		r.Response.WriteStatus(http.StatusForbidden)
    	}
    }
    func MiddlewareAuth2(r *ghttp.Request) {
    	fmt.Println("middleware 2")
    	token := r.Get("token")
    	if token == "123456" {
    		r.Middleware.Next()
    	} else {
    		r.Response.WriteStatus(http.StatusForbidden)
    	}
    }
    
    func MiddlewareFree(r *ghttp.Request) {
    	fmt.Println("middleware free")
    	r.Response.CORSDefault()
    	r.Middleware.Next()
    }
    func MiddlewareCORS(r *ghttp.Request) {
    	fmt.Println("middleware CORS")
    	r.Response.CORSDefault()
    	r.Middleware.Next()
    }
    
    func main() {
    	s := g.Server()
    	s.Group("/", func(g *ghttp.RouterGroup) {
    		g.MiddlewarePattern("/*", func(r *ghttp.Request) {
    			if r.URL.Path == "/login" {
    				r.Middleware.Next()
    				return
    			}
    			MiddlewareAuth1(r)
    			MiddlewareAuth2(r)
    		})
    	})
    	s.Group("/", func(g *ghttp.RouterGroup) {
    		g.ALL("/login", func(r *ghttp.Request) {
    			r.Response.Write("login")
    		})
    		g.ALL("/dashboard", func(r *ghttp.Request) {
    			r.Response.Write("dashboard")
    		})
    	})
    	s.Group("/api.v2", func(g *ghttp.RouterGroup) {
    		g.Middleware(MiddlewareFree, MiddlewareCORS)
    		g.ALL("/user/list", func(r *ghttp.Request) {
    			r.Response.Write("list")
    		})
    	})
    	s.SetPort(8199)
    	s.Run()
    }
    

    当我请求localhost:8199/api.v2/user/list的时候,的确应该返回403,但是问题是我收到了两个403,响应是这样的:ForbiddenForbidden。我的理解应该是:前一个中间件已经返回403了,不是200了,后面的中间件是不是不要再执行了?或者要其他什么手段控制它是否执行? 如果我把代码改成这样:

    package main
    
    import (
    	"fmt"
    	"net/http"
    
    	"github.com/gogf/gf/frame/g"
    	"github.com/gogf/gf/net/ghttp"
    )
    
    func MiddlewareAuth1(r *ghttp.Request) {
    	fmt.Println("middleware 1")
    	token := r.Get("token")
    	if token == "123456" {
    		r.Middleware.Next()
    	} else {
    		r.Response.WriteStatus(http.StatusForbidden)
    	}
    }
    func MiddlewareAuth2(r *ghttp.Request) {
    	fmt.Println("middleware 2")
    	token := r.Get("token")
    	if token == "123456" {
    		r.Middleware.Next()
    	} else {
    		r.Response.WriteStatus(http.StatusForbidden)
    	}
    }
    
    func MiddlewareFree(r *ghttp.Request) {
    	fmt.Println("middleware free")
    	r.Response.CORSDefault()
    	r.Middleware.Next()
    }
    func MiddlewareCORS(r *ghttp.Request) {
    	fmt.Println("middleware CORS")
    	r.Response.CORSDefault()
    	r.Middleware.Next()
    }
    
    func main() {
    	s := g.Server()
    	s.Group("/", func(g *ghttp.RouterGroup) {
    		g.Middleware(MiddlewareAuth1, MiddlewareAuth2)
    		g.MiddlewarePattern("/*", func(r *ghttp.Request) {
    			if r.URL.Path == "/login" {
    				r.Middleware.Next()
    				return
    			}
    		})
    	})
    	s.Group("/", func(g *ghttp.RouterGroup) {
    		g.ALL("/login", func(r *ghttp.Request) {
    			r.Response.Write("login")
    		})
    		g.ALL("/dashboard", func(r *ghttp.Request) {
    			r.Response.Write("dashboard")
    		})
    	})
    	s.Group("/api.v2", func(g *ghttp.RouterGroup) {
    		g.Middleware(MiddlewareFree, MiddlewareCORS)
    		g.ALL("/user/list", func(r *ghttp.Request) {
    			r.Response.Write("list")
    		})
    	})
    	s.SetPort(8199)
    	s.Run()
    }
    

    注意第44行,是我的改动,此时再请求localhost:8199/api.v2/user/list,只会返回1个403,一个Forbidden,然而,新的问题来了,不能正常访问login接口了。

    总结一下:

    1. 如果使用MiddlewarePattern绑定中间件,前一个403了之后,后一个还会执行,是否bug?
    2. 如果使用RouterGroup绑定中间件,官方文档中的例外控制action就失效了,是否bug?
    enhancement question 
    opened by ccpwcn 12
  • CPU 占用居高不下

    CPU 占用居高不下

    Build Detail: Go Version: go1.13.4 GF Version: v1.13.1 Git Commit: 1db1828b35c15b4a92cd144c33e636eb52d7ec07 Build Time: 2020-06-14 21:01:20

    今日进行代码漏洞扫描,指标如下:

    2个并发请求
    250ms请求延迟
    

    1、持续5分钟后,系统4核CPU全部占满, 2、7分钟后,应用服务响应变慢, 3、扫描结束30分钟后,CPU资源仍未释放

    20201119163428

    profile001

    enhancement done 
    opened by mir355 11
  • Cannot upload file on Linux

    Cannot upload file on Linux

    1. What version of Go and system type/arch are you using?

    go version go1.14.3 linux/amd64

    2. What version of GoFrame are you using?

    v1.12.3

    3. Can this issue be reproduced with the latest release?

    Yes

    4. What did you do?

    Use ghttp client to upload file ghttp.post, although it can be uploaded normally on Windows, it cannot be uploaded on Linux no matter using relative path or absolute path. The file is saved through files.save

    5. What did you expect to see?

    Normal uploads are also available on Linux

    6. What did you see instead?

    Normal uploads are also available on Linux

    question 
    opened by mingzaily 11
  • gqueue性能问题咨询

    gqueue性能问题咨询

    最近在使用gf的gqueue的时候,使用日志打点发现gqueue的性能似乎不太稳定,在我理解应该都是毫秒以下的处理,但是实际抖动延时很大,最大的时候达到了140ms,具体如下图描述,是否在使用上存在有什么不对的地方么。 golang 版本 go version go1.11.4 GOOS=linux AMD64 gf 版本 v1.6.17

    TIM截图20190616163435

    enhancement done 
    opened by foxhack 11
  • 连接MYSQL数据库 bad connection 和invalid connection

    连接MYSQL数据库 bad connection 和invalid connection

    2021-01-10 03:43:12.972 [ERRO] [252150 ms] [default] SELECT 语句 Error: bad connection

    数据库的连接配置

    Database. [database] link = "************************************************" maxLifetime = 5 #"(可选,单位秒)连接对象可重复使用的时间长度" maxIdle = 0 #"(可选)连接池最大闲置的连接数" maxOpen = 100 #"(可选)连接池最大打开的连接数" debug = true

    Database logger.

    [database.logger] Path = "/tmp/log/gf-lanbo/sql" Level = "ERRO" Stdout = true

    一天大概会出现两三次 这样的情况

    done feature 
    opened by code-cutter 10
  • 客户端提交过来的json格式的字符串如何转换到结构体啊?

    客户端提交过来的json格式的字符串如何转换到结构体啊?

    我如何将客户端提交map类型的参数内容绑定到我想要的request里面的内容里啊?这个问题干了四个小时了都没干出来,求大神指点一下,谢谢! 20201221-1 20201221-2 20201221-3 我的action代码是:

    func (action *Action) Save(r *ghttp.Request){
    request:=new(digital.Request)
    a:=gconv.Bytes(r.GetQueryMap()["data"])
    glog.Printf("%T",a)
    glog.Println(a)
    err:=gjson.DecodeTo(a,&request)
    if err!=nil{
    base.Fail(r,"error")
    }
    glog.Println(request)
    }
    

    我的service里的结构体为

    type Request struct{
    digital.Entity
    Id int `form:"id" json:"id"`
    ProjectId string `form:"projectId" json:"projectId"`
    CompleteScore float64 `form:"completeScore" json:"completeScore"`
    }
    
    question 
    opened by joyoes 10
  • orm 在没有连接池预热的情况瞬间事物并发卡死

    orm 在没有连接池预热的情况瞬间事物并发卡死

    [database]
        [[database.default]]
            host         = ""
            port         = "3306"
            user         = ""
            pass         = ""
            name         = "demo"
            type         = "mysql"
            debug        = "true"
            charset      = "utf8mb4"
            maxIdle      = "1"
            maxOpen      = "20"
            maxLifetime  = "30"
    
    func Hello(r *ghttp.Request) {
        _ = g.DB().Transaction(func(tx *gdb.TX) error {
            //延迟1s模拟耗时事物
            time.Sleep(time.Second)
            _, err := tx.Table(user.Table).Data("name","siyue").Insert()
            return err
        })
        r.Response.Writeln("Hello World!")
    }
    
    //建表语句 mysql 8.0
    //CREATE TABLE `user` (
    //`id` int(11) NOT NULL AUTO_INCREMENT,
    //`name` varchar(255) DEFAULT NULL,
    //PRIMARY KEY (`id`)
    //) ENGINE=InnoDB AUTO_INCREMENT=2489 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
    

    压测命令 wrk -t4 -c100 -d10s --latency http://127.0.0.1:8199/

    服务刚启动的时候直接用压测工具瞬间并发连接池瞬间满了然后卡死事物不执行, 如果提前手动请求一次预热在用压测工具就正常

    bug done 
    opened by siyue8899 10
  • 模板引擎-模板函数-内置函数-减法(minus) 计算结果错误

    模板引擎-模板函数-内置函数-减法(minus) 计算结果错误

    减法计算结果不正确

    {{.num1 | minus .num2}}

    .num1=4 .num2=2 当前给出结果(错误结果)=-2

    正确结果=2

    除法计算结果不正确

    {{.num1 | divide .num2}}

    .num1=4 .num2=2 当前给出结果(错误结果)=0.5

    正确结果=2

    猜测是变量顺序反了,但是使用文档里面是举例中的顺序

    opened by x-controller 0
  • Question:  I wanna change http response Code in `gcode` , What is the best way for me to do it ?

    Question: I wanna change http response Code in `gcode` , What is the best way for me to do it ?

    1. What version of Go and system type/arch are you using?

    go version go1.16.2 windows/amd64

    2. What version of GoFrame are you using?

    github.com/gogf/gf/v2 v2.0.0-rc3

    3. Can this issue be re-produced with the latest release?

    yes

    4. What did you do?

    I wanna change http response Code in my way . I found the http Code in goframe errors\gcode\gcode.go

    var (
    	CodeNil                      = localCode{-1, "", nil}                            // No error code specified.
    	CodeOK                       = localCode{0, "OK", nil}                           // It is OK.
    	CodeInternalError            = localCode{50, "Internal Error", nil}              // An error occurred internally.
    	CodeValidationFailed         = localCode{51, "Validation Failed", nil}           // Data validation failed.
             ........
    	CodeBusinessValidationFailed = localCode{300, "Business Validation Failed", nil} // Business validation failed.
    )
    

    I wanna change CodeValidationFailed = localCode{51, "Validation Failed", nil} into CodeValidationFailed = localCode{400, "Validation Failed and xxxxxxx", nil}.

    What is the best way for me to do it ?

    P.S. I also implment the MiddlewareHandlerResponse in group.Middleware() and Code Struct in my own way just like gcode. But Finally I found CodeValidationFailed used in gvalid which I really want the gvalid functions and abilities .

    
    
    opened by zhonghuaxunGM 0
  • 单元测试完善:contrib/drivers/oracle

    单元测试完善:contrib/drivers/oracle

    完善社区组件 contrib/drivers/oracle 的单元测试。

    组件地址:https://github.com/gogf/gf/tree/master/contrib/drivers/oracle

    要求:

    提供Model的CURD用例,至少包含这些方法的测试用例: 模型:Model/Raw 查询:All/One/Value/Array/Scan/Count 条件:多条件Where组合用例 写入:Insert/Replace/Save 更新:Update 删除:Delete 提供DB接口的CURD用例,至少包含这些方法的测试用例: 原生:Query/Exec 查询:GetAll/GetOne/GetValue/GetCount/GetArray/GetScan 写入:Insert/Replace/Save 更新:Update 删除:Delete 注意事项:不支持的方法断言返回的错误即可。

    feature help wanted wip 
    opened by wenzi1 0
  • [Feature Request] Suport protoc gen dao/dto/entity in gf

    [Feature Request] Suport protoc gen dao/dto/entity in gf

    It's useful to write some plugin for protoc. protobuff and grpc or other thrid part proto not support well in gf. The offical plugin list we can check blow: https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md

    希望gf能支持protoc gen 插件,通过编写protoc插件来支持protobuff,grpc,或者第三方私有协议,因为这部分在gf支持的并不好。 官方提供插件列表,可以供我们查看 https://github.com/protocolbuffers/protobuf/blob/main/docs/options.md

    opened by Cyberhan123 0
Releases(v2.1.0-rc)
Owner
GoFrame
The GoFrame Organization.
GoFrame
Package macaron is a high productive and modular web framework in Go.

Macaron Package macaron is a high productive and modular web framework in Go. Getting Started The minimum requirement of Go is 1.6. To install Macaron

Macaron 3.3k May 15, 2022
Mango is a modular web-application framework for Go, inspired by Rack, and PEP333.

Mango Mango is a modular web-application framework for Go, inspired by Rack and PEP333. Note: Not actively maintained. Overview Mango is most of all a

Paul Bellamy 364 Apr 24, 2022
hiboot is a high performance web and cli application framework with dependency injection support

Hiboot - web/cli application framework About Hiboot is a cloud native web and cli application framework written in Go. Hiboot is not trying to reinven

hidevops.io 169 May 10, 2022
A powerful go web framework for highly scalable and resource efficient web application

webfr A powerful go web framework for highly scalable and resource efficient web application Installation: go get -u github.com/krishpranav/webfr Exa

Krisna Pranav 13 Nov 28, 2021
A powerful go web framework for highly scalable and resource efficient web application

A powerful go web framework for highly scalable and resource efficient web application

null 20 Feb 2, 2022
A fantastic modular Go web framework boiled with black magic.

A fantastic modular Go web framework boiled with black magic. Getting started The minimum requirement of Go is 1.16. To install Flamego: go get github

Flamego 317 May 20, 2022
Modular C2 framework aiming to ease post exploitation for red teamers.

test.mp4 testvideo.mp4 Usage: Inside the command server you can reference beacons using either their list id or their unique id. For example if the ou

meet 144 May 15, 2022
Goal is a toolkit for high productivity web development in Go language in the spirit of Revel Framework that is built around the concept of code generation.

Goal Goal is a set of tools for high productivity web development in Go language. Goal, being mostly inspired by Revel Framework and its discussions,

null 88 Sep 27, 2021
henrylee2cn 1.6k May 17, 2022
Dragon 🐲 🐲 🐲 is a lightweight high performance web framework with Go for the feature and comfortable develop.

Dragon project new link start dragon ab performance Dragon ?? ?? ?? is a lightweight high performance web framework with Go for the feature and comfor

azerothyang 13 Apr 6, 2022
GoFarm is an Application Development Framework for especially Backend Developer with Golang

What is GoFarm GoFarm is an Application Development Framework for especially Backend Developer with Golang. Our goal is to develop easier, standardize

Alvin Leonardo 2 Dec 9, 2021
beego is an open-source, high-performance web framework for the Go programming language.

Beego Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services. It is inspired by To

astaxie 465 May 20, 2022
High performance, minimalist Go web framework

Supported Go versions As of version 4.0.0, Echo is available as a Go module. Therefore a Go version capable of understanding /vN suffixed imports is r

LabStack LLC 22.4k May 12, 2022
Gearbox :gear: is a web framework written in Go with a focus on high performance

gearbox ⚙️ is a web framework for building micro services written in Go with a focus on high performance. It's built on fasthttp which is up to 10x fa

Gearbox 634 May 13, 2022
Gearbox :gear: is a web framework written in Go with a focus on high performance

gearbox ⚙️ is a web framework for building micro services written in Go with a focus on high performance. It's built on fasthttp which is up to 10x fa

Gearbox 635 May 18, 2022
High performance, simple Go web framework

Elton Elton的实现参考了koa以及echo,中间件的调整均为洋葱模型:请求由外至内,响应由内至外。主要特性如下: 处理函数(中间件)均以返回error的形式响应出错,方便使用统一的出错处理中间件将出错统一转换为对应的输出(JSON),并根据出错的类型等生成各类统计分析 成功响应数据直接赋值

Tree Xie 59 May 15, 2022
beego is an open-source, high-performance web framework for the Go programming language.

Beego Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services. It is inspired by To

beego Framework 28.2k May 16, 2022
letgo is an open-source, high-performance web framework for the Go programming language.

high-performance Lightweight web framework for the Go programming language. golang web framework,高可用golang web框架,go语言 web框架 ,go web

wjp 354 May 12, 2022
Hexya business application development framework

Hexya Hexya is an open source ERP and a business application development framework written in Go. This repository houses the business application deve

Hexya 347 May 10, 2022