Compare commits

...

3 Commits

10 changed files with 100 additions and 35 deletions

View File

@ -2,10 +2,10 @@ package main
import (
"fmt"
"github.com/gogf/gf/text/gregex"
"github.com/gogf/gf/text/gstr"
)
func main() {
file := "xxx/github.com/hg-hh/ww/gf/.example/"
fmt.Println(gregex.IsMatchString(`/github.com/[^/]+/gf/\.example/`, file))
fmt.Println(gstr.CamelCase("userLoginLog.bak"))
}

View File

@ -1,30 +1,18 @@
# `v1.9.0`
该版本实际为`v2.0.0`的大版本发布,为避免`go module`机制严格要求`v2`版本以上需要修改`import`并加上`v2`后缀,因此使用了`v1.9.0`进行发布。
## 新特性
1. 增`gf`命令行开发辅助工具https://goframe.org/toolchain/cli
- 支持`GF`框架下载更新;
- 支持初始化新建项目命令;
- 支持跨平台交叉编译命令;
- 命令行工具支持自动更新命令;
- 支持二进制文件打包生成二进制文件或者Go程序文件
- 支持指定数据库生成数据表模型,支持本地配置文件读取数据库配置;
1. 新增`gi18n`国际化管理模块https://goframe.org/i18n/gi18n/index
1. 增`gf`命令行开发辅助工具https://goframe.org/toolchain/cli
1. 新增`gres`资源管理器模块https://goframe.org/os/gres/index
- 资源管理器支持虚拟的文件/目录操作方法;
- 默认整合支持到了WebServer、配置管理、模板引擎中
- 可将任意的文件打包为`Go`内容,支持开发者自定义加解密;
- 任意文件如网站静态文件、配置文件等可编译到二进制文件中,也可编译到发布的可执行文件中;
- 开发者可只需编译发布一个可执行文件,除了方便了软件分发,也为保护软件知识产权内容提供了可能;
1. 新增`gini`模块https://goframe.org/encoding/gini/index
- 支持`ini`文件的读取/生成;
- 同时配置管理模块也增加了对`ini`文件的支持;
- 配置管理模块目前自动识别支持`ini/xml/json/toml/yaml`五种数据格式;
1. `Session`功能重构,新增`gsession`模块,`WebServer`默认使用文件存储`Session`https://goframe.org/net/ghttp/session
1. 重构`Session`功能,新增`gsession`模块,`WebServer`默认使用文件存储`Session`https://goframe.org/net/ghttp/session
1. `WebServer`新增中间件特性并保留原有的HOOK设计两者都可实现请求拦截、预处理等等特性https://goframe.org/net/ghttp/router/middleware
1. 新增`gi18n`国际化管理模块https://goframe.org/i18n/gi18n/index
1. 新增`gini`模块https://goframe.org/encoding/gini/index
1. `WebServer`新增更便捷的层级路由注册方式https://goframe.org/net/ghttp/group/level
1. `gcmd`命令行参数解析模块重构,增加`Parser`解析对象
1. 新增`gdebug`模块,用于堆栈获取/打印
1. `gcmd`命令行参数解析模块重构,增加`Parser`解析对象https://goframe.org/os/gcmd/index
1. 新增`gdebug`模块,用于堆栈信息获取/打印https://goframe.org/debug/gdebug/index
## 重大调整
@ -53,7 +41,7 @@
- 增加`SetLogger`方法用于开发者自定义数据库的日志打印;
- 增加`Master/Slave`方法,开发者可自主选择数据库操作执行的主从节点;
- 增加对`mssql/pgsql/oracle`的单元测试;
- `debug`模式支持完整带参数整合的SQL语句调试打印
- `debug`模式支持完整带参数整合的SQL语句调试打印
- 增加了更多的功能方法;
1. `glog`
- 新增`Default`方法用于获取默认的`Logger`对象;

View File

@ -31,7 +31,7 @@ const (
)
var (
wordReg = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`)
wordReg = regexp.MustCompile(`^[a-zA-Z0-9\-_\.]+$`)
lastOperatorReg = regexp.MustCompile(`[<>=]+\s*$`)
)

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// 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,
@ -17,8 +17,9 @@ import (
)
var (
defaultParsedArgs = make([]string, 0)
defaultParsedOptions = make(map[string]string)
defaultParsedArgs = make([]string, 0)
defaultParsedOptions = make(map[string]string)
defaultCommandFuncMap = make(map[string]func())
)
// Custom initialization.
@ -29,7 +30,7 @@ func doInit() {
// Parsing os.Args with default algorithm.
// The option should use '=' to separate its name and value in default.
for _, arg := range os.Args {
array, _ := gregex.MatchString(`^\-{1,2}([\w\?]+)={0,1}(.*)$`, arg)
array, _ := gregex.MatchString(`^\-{1,2}([\w\?\.\-]+)={0,1}(.*)$`, arg)
if len(array) == 3 {
defaultParsedOptions[array[1]] = array[2]
} else {

58
os/gcmd/gcmd_handler.go Normal file
View File

@ -0,0 +1,58 @@
// 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 gcmd
import (
"errors"
)
// BindHandle registers callback function <f> with <cmd>.
func BindHandle(cmd string, f func()) error {
if _, ok := defaultCommandFuncMap[cmd]; ok {
return errors.New("duplicated handle for command:" + cmd)
} else {
defaultCommandFuncMap[cmd] = f
}
return nil
}
// BindHandle registers callback function with map <m>.
func BindHandleMap(m map[string]func()) error {
var err error
for k, v := range m {
if err = BindHandle(k, v); err != nil {
return err
}
}
return err
}
// RunHandle executes the callback function registered by <cmd>.
func RunHandle(cmd string) error {
if handle, ok := defaultCommandFuncMap[cmd]; ok {
handle()
} else {
return errors.New("no handle found for command:" + cmd)
}
return nil
}
// AutoRun automatically recognizes and executes the callback function
// by value of index 0 (the first console parameter).
func AutoRun() error {
if cmd := GetArg(1); cmd != "" {
if handle, ok := defaultCommandFuncMap[cmd]; ok {
handle()
} else {
return errors.New("no handle found for command:" + cmd)
}
} else {
return errors.New("no command found")
}
return nil
}

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// 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,
@ -21,6 +21,17 @@ func (p *Parser) BindHandle(cmd string, f func()) error {
return nil
}
// BindHandle registers callback function with map <m>.
func (p *Parser) BindHandleMap(m map[string]func()) error {
var err error
for k, v := range m {
if err = p.BindHandle(k, v); err != nil {
return err
}
}
return err
}
// RunHandle executes the callback function registered by <cmd>.
func (p *Parser) RunHandle(cmd string) error {
if handle, ok := p.commandFuncMap[cmd]; ok {

View File

@ -447,7 +447,10 @@ func Split(str, delimiter string) []string {
func SplitAndTrim(str, delimiter, cut string) []string {
array := strings.Split(str, delimiter)
for k, v := range array {
array[k] = strings.Trim(v, cut)
v = strings.Trim(v, cut)
if v != "" {
array[k] = strings.Trim(v, cut)
}
}
return array
}
@ -457,7 +460,10 @@ func SplitAndTrim(str, delimiter, cut string) []string {
func SplitAndTrimSpace(str, delimiter string) []string {
array := strings.Split(str, delimiter)
for k, v := range array {
array[k] = strings.TrimSpace(v)
v = strings.TrimSpace(v)
if v != "" {
array[k] = v
}
}
return array
}

View File

@ -90,7 +90,7 @@ func DelimitedScreamingCase(s string, del uint8, screaming bool) string {
} else if v >= 'a' && v <= 'z' {
n += string(v) + string(del)
}
} else if v == ' ' || v == '_' || v == '-' {
} else if v == ' ' || v == '_' || v == '-' || v == '.' {
// replace spaces/underscores with delimiters
n += string(del)
} else {
@ -132,7 +132,7 @@ func toCamelInitCase(s string, initCase bool) string {
n += string(v)
}
}
if v == '_' || v == ' ' || v == '-' {
if v == '_' || v == ' ' || v == '-' || v == '.' {
capNext = true
} else {
capNext = false

View File

@ -20,6 +20,7 @@ func Test_CamelCase(t *testing.T) {
{"test", "Test"},
{"TestCase", "TestCase"},
{" test case ", "TestCase"},
{"userLogin_log.bak", "UserLoginLogBak"},
{"", ""},
{"many_many_words", "ManyManyWords"},
{"AnyKind of_string", "AnyKindOfString"},

View File

@ -1,4 +1,4 @@
package gf
const VERSION = "v2.0.0"
const VERSION = "v1.9.1"
const AUTHORS = "john<john@goframe.org>"