From b92b69564bba4bc5dd46cf8532ecfe62c141201d Mon Sep 17 00:00:00 2001 From: John Date: Thu, 16 May 2019 23:41:09 +0800 Subject: [PATCH 1/5] improve gfile.MainPkgPath --- g/os/gfile/gfile.go | 21 +++++++++++++++------ geg/other/test.go | 6 ++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 1a97a51dc..224b40bd0 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -5,8 +5,6 @@ // You can obtain one at https://github.com/gogf/gf. // Package gfile provides easy-to-use operations for file system. -// -// 文件管理. package gfile import ( @@ -15,6 +13,7 @@ import ( "fmt" "github.com/gogf/gf/g/container/gtype" "github.com/gogf/gf/g/text/gregex" + "github.com/gogf/gf/g/text/gstr" "github.com/gogf/gf/g/util/gconv" "io" "os" @@ -452,11 +451,21 @@ func MainPkgPath() string { } for i := 1; i < 10000; i++ { if _, file, _, ok := runtime.Caller(i); ok { - if gregex.IsMatchString(`package\s+main`, GetContents(file)) { - path = Dir(file) - mainPkgPath.Set(path) - return path + if gstr.Contains(file, "/gf/g/") { + continue } + path = file + for path != "/" && gstr.Contains(path, "/") { + files, _ := ScanDir(path, "*.go") + for _, v := range files { + if gregex.IsMatchString(`package\s+main`, GetContents(v)) { + mainPkgPath.Set(path) + return path + } + } + path = Dir(path) + } + } else { break } diff --git a/geg/other/test.go b/geg/other/test.go index 03407626f..47632c222 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -3,10 +3,16 @@ package main import ( "fmt" "github.com/gogf/gf/g" + "github.com/gogf/gf/g/os/gfile" "github.com/gogf/gf/g/util/gconv" ) func main() { + fmt.Println(gfile.Dir("/")) + return + a := []int{1,2,3} + fmt.Println(a[:0]) + return type Person struct{ Name string } From dd2436925ba3577b21e645d6daafb8f463bb841d Mon Sep 17 00:00:00 2001 From: John Date: Fri, 17 May 2019 00:17:45 +0800 Subject: [PATCH 2/5] remove package feature for gudp, considering UDP protocal has its own border for message handling --- g/net/gudp/gudp_conn.go | 5 +- g/net/gudp/gudp_conn_pkg.go | 115 ------------------------------------ g/net/gudp/gudp_func_pkg.go | 49 --------------- 3 files changed, 3 insertions(+), 166 deletions(-) delete mode 100644 g/net/gudp/gudp_conn_pkg.go delete mode 100644 g/net/gudp/gudp_func_pkg.go diff --git a/g/net/gudp/gudp_conn.go b/g/net/gudp/gudp_conn.go index 975ef8c37..0d924734f 100644 --- a/g/net/gudp/gudp_conn.go +++ b/g/net/gudp/gudp_conn.go @@ -24,7 +24,7 @@ type Conn struct { const ( gDEFAULT_RETRY_INTERVAL = 100 // (毫秒)默认重试时间间隔 - gDEFAULT_READ_BUFFER_SIZE = 1024 // 默认数据读取缓冲区大小 + gDEFAULT_READ_BUFFER_SIZE = 64 // (KB)默认数据读取缓冲区大小 gRECV_ALL_WAIT_TIMEOUT = time.Millisecond // 读取全部缓冲数据时,没有缓冲数据时的等待间隔 ) @@ -88,7 +88,8 @@ func (c *Conn) Send(data []byte, retry...Retry) error { } } -// 接收数据 +// 接收数据. +// 注意:UDP协议存在消息边界,因此使用 length<=0 可以获取缓冲区所有消息包数据,即一个完整包。 func (c *Conn) Recv(length int, retry...Retry) ([]byte, error) { var err error // 读取错误 var size int // 读取长度 diff --git a/g/net/gudp/gudp_conn_pkg.go b/g/net/gudp/gudp_conn_pkg.go deleted file mode 100644 index 4b65be743..000000000 --- a/g/net/gudp/gudp_conn_pkg.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gudp - -import ( - "encoding/binary" - "errors" - "fmt" - "time" -) - -const ( - // 允许最大的简单协议包大小(byte), 15MB - PKG_MAX_SIZE = 0xFFFFFF - // 消息包头大小: "总长度"3字节+"校验码"4字节 - PKG_HEADER_SIZE = 7 -) - -// 根据简单协议发送数据包。 -// 简单协议数据格式:总长度(24bit)|校验码(32bit)|数据(变长)。 -// 注意: -// 1. "总长度"包含自身3字节及"校验码"4字节。 -// 2. 由于"总长度"为3字节,并且使用的BigEndian字节序,因此最后返回的buffer使用了buffer[1:]。 -func (c *Conn) SendPkg(data []byte, retry...Retry) error { - length := uint32(len(data)) - if length > PKG_MAX_SIZE - PKG_HEADER_SIZE { - return errors.New(fmt.Sprintf(`data size %d exceeds max pkg size %d`, length, PKG_MAX_SIZE - PKG_HEADER_SIZE)) - } - buffer := make([]byte, PKG_HEADER_SIZE + 1 + len(data)) - copy(buffer[PKG_HEADER_SIZE + 1 : ], data) - binary.BigEndian.PutUint32(buffer[0 : ], PKG_HEADER_SIZE + length) - binary.BigEndian.PutUint32(buffer[4 : ], Checksum(data)) - //fmt.Println("SendPkg:", buffer[1:]) - return c.Send(buffer[1:], retry...) -} - -// 简单协议: 带超时时间的数据发送 -func (c *Conn) SendPkgWithTimeout(data []byte, timeout time.Duration, retry...Retry) error { - c.SetSendDeadline(time.Now().Add(timeout)) - defer c.SetSendDeadline(time.Time{}) - return c.SendPkg(data, retry...) -} - -// 简单协议: 发送数据并等待接收返回数据 -func (c *Conn) SendRecvPkg(data []byte, retry...Retry) ([]byte, error) { - if err := c.SendPkg(data, retry...); err == nil { - return c.RecvPkg(retry...) - } else { - return nil, err - } -} - -// 简单协议: 发送数据并等待接收返回数据(带返回超时等待时间) -func (c *Conn) SendRecvPkgWithTimeout(data []byte, timeout time.Duration, retry...Retry) ([]byte, error) { - if err := c.SendPkg(data, retry...); err == nil { - return c.RecvPkgWithTimeout(timeout, retry...) - } else { - return nil, err - } -} - -// 简单协议: 获取一个数据包。 -func (c *Conn) RecvPkg(retry...Retry) (result []byte, err error) { - var temp []byte - var length uint32 - for { - // 先根据对象的缓冲区数据进行计算 - for { - if len(c.buffer) >= PKG_HEADER_SIZE { - // 注意"总长度"为3个字节,不满足4个字节的uint32类型,因此这里"低位"补0 - length = binary.BigEndian.Uint32([]byte{0, c.buffer[0], c.buffer[1], c.buffer[2]}) - // 解析的大小是否符合规范 - if length == 0 || length + PKG_HEADER_SIZE > PKG_MAX_SIZE { - c.buffer = c.buffer[1:] - continue - } - // 不满足包大小,需要继续读取 - if uint32(len(c.buffer)) < length { - break - } - // 数据校验 - if binary.BigEndian.Uint32(c.buffer[3 : PKG_HEADER_SIZE]) != Checksum(c.buffer[PKG_HEADER_SIZE : length]) { - c.buffer = c.buffer[1:] - continue - } - result = c.buffer[PKG_HEADER_SIZE : length] - c.buffer = c.buffer[length: ] - return - } else { - break - } - } - // 读取系统socket缓冲区的完整数据 - temp, err = c.Recv(-1, retry...) - if err != nil { - break - } - if len(temp) > 0 { - c.buffer = append(c.buffer, temp...) - } - //fmt.Println("RecvPkg:", c.buffer) - } - return -} - -// 简单协议: 带超时时间的消息包获取 -func (c *Conn) RecvPkgWithTimeout(timeout time.Duration, retry...Retry) ([]byte, error) { - c.SetRecvDeadline(time.Now().Add(timeout)) - defer c.SetRecvDeadline(time.Time{}) - return c.RecvPkg(retry...) -} \ No newline at end of file diff --git a/g/net/gudp/gudp_func_pkg.go b/g/net/gudp/gudp_func_pkg.go deleted file mode 100644 index f0796064a..000000000 --- a/g/net/gudp/gudp_func_pkg.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gudp - -import "time" - -// 简单协议: (面向短链接)发送消息包 -func SendPkg(addr string, data []byte, retry...Retry) error { - conn, err := NewConn(addr) - if err != nil { - return err - } - defer conn.Close() - return conn.SendPkg(data, retry...) -} - -// 简单协议: (面向短链接)发送数据并等待接收返回数据 -func SendRecvPkg(addr string, data []byte, retry...Retry) ([]byte, error) { - conn, err := NewConn(addr) - if err != nil { - return nil, err - } - defer conn.Close() - return conn.SendRecvPkg(data, retry...) -} - -// 简单协议: (面向短链接)带超时时间的数据发送 -func SendPkgWithTimeout(addr string, data []byte, timeout time.Duration, retry...Retry) error { - conn, err := NewConn(addr) - if err != nil { - return err - } - defer conn.Close() - return conn.SendPkgWithTimeout(data, timeout, retry...) -} - -// 简单协议: (面向短链接)发送数据并等待接收返回数据(带返回超时等待时间) -func SendRecvPkgWithTimeout(addr string, data []byte, timeout time.Duration, retry...Retry) ([]byte, error) { - conn, err := NewConn(addr) - if err != nil { - return nil, err - } - defer conn.Close() - return conn.SendRecvPkgWithTimeout(data, timeout, retry...) -} \ No newline at end of file From 1af482d950949bcd3bcf70b02dfd3721f4ecce98 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 17 May 2019 21:37:48 +0800 Subject: [PATCH 3/5] improve gfile.MainPkgPath --- g/os/gfile/gfile.go | 3 +++ g/os/gfile/gfile_test.go | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index 224b40bd0..47bbdb680 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -454,6 +454,9 @@ func MainPkgPath() string { if gstr.Contains(file, "/gf/g/") { continue } + if Ext(file) != ".go" { + continue + } path = file for path != "/" && gstr.Contains(path, "/") { files, _ := ScanDir(path, "*.go") diff --git a/g/os/gfile/gfile_test.go b/g/os/gfile/gfile_test.go index b7b9317b8..c0315f9f5 100644 --- a/g/os/gfile/gfile_test.go +++ b/g/os/gfile/gfile_test.go @@ -653,8 +653,8 @@ func TestMkdir(t *testing.T) { func TestStat(t *testing.T) { gtest.Case(t, func() { var ( - tpath1 string = "/testfile_t1.txt" - tpath2 string = "./testfile_t1_no.txt" + tpath1 = "/testfile_t1.txt" + tpath2 = "./testfile_t1_no.txt" err error fileiofo os.FileInfo ) @@ -675,12 +675,7 @@ func TestStat(t *testing.T) { func TestMainPkgPath(t *testing.T) { gtest.Case(t, func() { - var ( - reads string - ) - - reads = gfile.MainPkgPath() + reads := gfile.MainPkgPath() gtest.Assert(reads, "") - }) } From e31861af2e339db501256705a9c2dd48f9d4f6b8 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 18 May 2019 13:52:18 +0800 Subject: [PATCH 4/5] README updates --- README.MD | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.MD b/README.MD index 5933032b5..733a794f0 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,6 @@ # GoFrame - +
+ [![Go Doc](https://godoc.org/github.com/gogf/gf?status.svg)](https://godoc.org/github.com/gogf/gf) [![Build Status](https://travis-ci.org/gogf/gf.svg?branch=master)](https://travis-ci.org/gogf/gf) @@ -8,12 +9,15 @@ [![Production Ready](https://img.shields.io/badge/production-ready-blue.svg)](https://github.com/gogf/gf) [![License](https://img.shields.io/github/license/gogf/gf.svg?style=flat)](https://github.com/gogf/gf) +
+ `GF(GoFrame)` is a modular, loose-coupled, production-ready and most-powerful application development framework of golang. Providing a series of core components and dozens of practical modules, such as: memcache, configure, validator, logging, array/queue/set/map containers, timer/timing tasks, file/memory lock, object pool, database ORM, etc. Supporting web server integrated with router, cookie, session, logger, template, https, hooks, rewrites and many more features. + # Installation ``` go get -u github.com/gogf/gf From e9f7b8bc0c8fee289572f6e9d74b2aceaf8bbb95 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 18 May 2019 14:55:15 +0800 Subject: [PATCH 5/5] README updates --- README.MD | 16 +++++++++++++--- README_ZH.MD | 17 ++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.MD b/README.MD index 733a794f0..06202e302 100644 --- a/README.MD +++ b/README.MD @@ -1,6 +1,6 @@ # GoFrame
- + [![Go Doc](https://godoc.org/github.com/gogf/gf?status.svg)](https://godoc.org/github.com/gogf/gf) [![Build Status](https://travis-ci.org/gogf/gf.svg?branch=master)](https://travis-ci.org/gogf/gf) @@ -29,7 +29,7 @@ require github.com/gogf/gf latest # Limitation ``` -golang version >= 1.9.2 +golang version >= 1.10 ``` # Documentation @@ -68,7 +68,6 @@ func main() { `GF` is licensed under the [MIT License](LICENSE), 100% free and open-source, forever. - # Contributors - [aloncn](https://github.com/aloncn) @@ -91,6 +90,8 @@ func main() { # Donators +We currently accept donation by Alipay/WechatPay, please note your github/gitee account in your payment bill. If you like `GF`, why not [buy developer a cup of coffee](https://goframe.org/images/donate.png)? + - [flyke-xu](https://gitee.com/flyke-xu) - [hailaz](https://gitee.com/hailaz) - [ireadx](https://github.com/ireadx) @@ -106,3 +107,12 @@ func main() { + +# Sponsor + +We appreciate any kind of sponsorship for `GF` development. If you've got some interested, please contact john@goframe.org. + + + + + diff --git a/README_ZH.MD b/README_ZH.MD index fc43009cd..30b6ed12e 100644 --- a/README_ZH.MD +++ b/README_ZH.MD @@ -1,5 +1,6 @@ # GoFrame - +
+ [![Go Doc](https://godoc.org/github.com/gogf/gf?status.svg)](https://godoc.org/github.com/gogf/gf) [![Build Status](https://travis-ci.org/gogf/gf.svg?branch=master)](https://travis-ci.org/gogf/gf) @@ -8,6 +9,8 @@ [![Production Ready](https://img.shields.io/badge/production-ready-blue.svg)](https://github.com/gogf/gf) [![License](https://img.shields.io/github/license/gogf/gf.svg?style=flat)](https://github.com/gogf/gf) +
+ `GF(Go Frame)`是一款模块化、松耦合、生产级Go应用开发框架。提供了常用的核心开发组件,如:缓存、日志、文件、时间、队列、数组、集合、字符串、定时器、命令行、文件锁、内存锁、对象池、连接池、数据校验、数据编码、文件监控、定时任务、数据库ORM、TCP/UDP组件、进程管理/通信、 并发安全容器等等。并提供了Web服务开发的系列核心组件,如:Router、Cookie、Session、服务注册、配置管理、模板引擎等等,支持热重启、热更新、多域名、多端口、多服务、HTTPS、Rewrite等特性。 @@ -33,7 +36,7 @@ require github.com/gogf/gf latest # 限制 ```shell -golang版本 >= 1.9.2 +golang版本 >= 1.10 ``` # 架构 @@ -76,12 +79,12 @@ func main() { # 捐赠 -捐赠支持`GF`框架的研发, -请在捐赠时备注您的`github`/`gitee`账号名称。 +如果您喜欢`GF`,要不[给开发者来杯咖啡吧](https://goframe.org/images/donate.png)! +请在捐赠时备注您的`github`/`gitee`账号名称。 - - - +# 赞助 + +赞助支持`GF`框架的快速研发,如果您感兴趣,请联系 john@goframe.org 。 # 贡献者