-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from save95/develop
- Loading branch information
Showing
76 changed files
with
3,191 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
# 变更日志 | ||
|
||
## v1.2.0 | ||
|
||
1. 增加 http 中间件: | ||
- xss 过滤器: `middleware.XSSFilter()` | ||
- cors 处理器:`middleware.CORS()` | ||
- 有状态的 jwt 处理器:`middleware.JWTStatefulWith()`,`middleware.JWTStatefulWithout()` | ||
- session 管理器:`middleware.SessionWithStore()` 方便分布式部署,指定 session 存储器 | ||
- http 缓存器:`middleware.HttpCache()` | ||
- 角色控制器:`middleware.WithRole()` | ||
2. 增加 json logger 格式,为适应云日志采集(阿里云/腾讯云) | ||
3. 增加 db 内部特地错误检查工具: | ||
- 唯一键冲突:`dberror.IsDuplicateEntry()` | ||
4. 增加 动态表格结构的 restful 响应:`restful.TableWithPagination()` | ||
5. 增加 [HTTPSQS](http://zyan.cc/httpsqs/) 客户端及相关队列: | ||
- 客户端:`httpsqs.NewClient()` | ||
- 消费者:`listener.NewHttpSQSConsumer()` | ||
- 其他情形: | ||
```golang | ||
err := listener.NewHttpSQSConsumer(handler). | ||
WithContext(ctx). | ||
WithLog(global.Log). | ||
Consume() | ||
``` | ||
- 消费者包装器:`listener.HTTPSQS(handler)` | ||
6. 其他组件升级: | ||
- DB 分页查询参数 `pager.Option{}` 支持 `Preload` | ||
|
||
⚠️注意:本次升级存在不向下兼容部分: | ||
- http 中间件: | ||
- `middleware.HttpLogger(restful.LogOption{})` => `middleware.HttpLogger(middleware.HttpLoggerOption{})` | ||
|
||
|
||
## v1.1.0 | ||
|
||
1. 升级 `gorm v2`,并增加 `dbutil.ConnectWith` 方法以适应非 mysql、sqlite 的数据库连接 | ||
1. 升级 `gorm v2`,并增加 `dbutil.ConnectWith()` 方法以适应非 mysql、sqlite 的数据库连接 | ||
|
||
## v1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dberror | ||
|
||
const ( | ||
errorCodeMySQLDuplicateEntry = 1062 | ||
errorCodeMySQLDuplicateEntryWithKeyName = 1586 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dberror | ||
|
||
import ( | ||
"github.com/go-sql-driver/mysql" | ||
) | ||
|
||
func IsDuplicateEntry(err error) bool { | ||
//if sqliteErr, ok := err.(sqlite3.Error); ok { | ||
// return sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique || | ||
// sqliteErr.ExtendedCode == sqlite3.ErrConstraintPrimaryKey | ||
//} else | ||
if mysqlErr, ok := err.(*mysql.MySQLError); ok { | ||
return mysqlErr.Number == errorCodeMySQLDuplicateEntry || | ||
mysqlErr.Number == errorCodeMySQLDuplicateEntryWithKeyName | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package logger | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type formatJson struct { | ||
} | ||
|
||
func (lf *formatJson) Format(entry *logrus.Entry) ([]byte, error) { | ||
logs := map[string]interface{}{ | ||
"time": entry.Time.Format("2006-01-02 15:04:05.000"), | ||
"level": strings.ToUpper(entry.Level.String()), | ||
"message": entry.Message, | ||
} | ||
|
||
if len(entry.Data) > 0 { | ||
logs["data"] = entry.Data | ||
} | ||
|
||
return json.Marshal(logs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package logger | ||
|
||
type LogFormat int8 | ||
|
||
const ( | ||
LogFormatText LogFormat = iota | ||
LogFormatJson | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package logger | ||
|
||
import "github.com/sirupsen/logrus" | ||
|
||
func WithFormat(format LogFormat) func(*logger) { | ||
return func(l *logger) { | ||
switch format { | ||
case LogFormatJson: | ||
l.formatter = &formatJson{} | ||
default: | ||
l.formatter = &formatText{} | ||
} | ||
} | ||
} | ||
|
||
func WithFormatter(formatter logrus.Formatter) func(*logger) { | ||
return func(l *logger) { | ||
l.formatter = formatter | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.