Prepare Release 2.0.6 (#5104)
* add: generic cache random time offset expired. * bugfix: Csrf token should be Secure and httpOnly, but not now * fix: expose the Offset property to allow external modifications * improving the concurrency performance of random value calculation * add WithOffsetFunc to define private RandomExpireCache.offset field * fix: add seconds definition * build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.8.0 Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.1 to 1.8.0. - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.7.1...v1.8.0) --- updated-dependencies: - dependency-name: github.com/stretchr/testify dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix 4907: force admin service http only * Feat: add get all tasks function (#4999) * feat: add get all tasks function * Refine Comments : admin/profile.go,bean/mock.go,config/global.go... (#5009) * Refine Comments * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * refine comments for for four files (#5011) * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * Update db.go * fix pass []any as any in variadic function by asasalint (#5012) * fix pass []any as any in variadic function * add change log * build(deps): bump go.opentelemetry.io/otel/trace from 1.7.0 to 1.8.0 (#5019) Bumps [go.opentelemetry.io/otel/trace](https://github.com/open-telemetry/opentelemetry-go) from 1.7.0 to 1.8.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.7.0...v1.8.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel/trace dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * refine comments for package core (#5014) * Refine Comments * refine comments for cache.go * refine comments for log.go * Update orm.go * refine comments for orm_log.go,types.go * Update utils.go * Update doc.go * refine comments * refine comments * Update db.go * refine comments for core * build(deps): bump go.opentelemetry.io/otel/exporters/stdout/stdouttrace (#5018) Bumps [go.opentelemetry.io/otel/exporters/stdout/stdouttrace](https://github.com/open-telemetry/opentelemetry-go) from 1.7.0 to 1.8.0. - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.7.0...v1.8.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel/exporters/stdout/stdouttrace dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix 5022: Miss assiging ln to graceful Server (#5028) * prepare for releasing v2.0.5 * prepare for releasing v2.0.5 (#5032) * feat: make commands and docker compose for ORM unit tests (#5031) * feat: make commands and docker compose for ORM unit tests Signed-off-by: mango <xu.weiKyrie@foxmail.com> * add changelog Signed-off-by: mango <xu.weiKyrie@foxmail.com> Signed-off-by: mango <xu.weiKyrie@foxmail.com> * Modify comment syntax error (#5094) * fix: revise the body wrapper to handle empty body case (#5102) Fix the router.go serverHttp method, wrap the body if the request body is empty, which can avoid panic when calling the CopyBody method. Signed-off-by: chlins <chenyuzh@vmware.com> Signed-off-by: chlins <chenyuzh@vmware.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: mango <xu.weiKyrie@foxmail.com> Signed-off-by: chlins <chenyuzh@vmware.com> Co-authored-by: auual <ding@ibyte.me> Co-authored-by: Leon Ding <deen.job@qq.com> Co-authored-by: dada0z <zhang.guangda@qq.com> Co-authored-by: kevinzeng <kevinzeng@zego.im> Co-authored-by: Kevin Tsang <39397413+ktalg@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: 日暮颂歌1991 <448081525@qq.com> Co-authored-by: Regan Yue <1131625869@qq.com> Co-authored-by: alingse <alingse@foxmail.com> Co-authored-by: mango <35127166+mangoGoForward@users.noreply.github.com> Co-authored-by: 王哈哈 <31426858+wanghaha-dev@users.noreply.github.com> Co-authored-by: Chlins Zhang <chlins.zhang@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ type siprng struct {
|
||||
k0, k1, ctr uint64
|
||||
}
|
||||
|
||||
// siphash implements SipHash-2-4, accepting a uint64 as a message.
|
||||
// siphash implements SipHash-2-4, accepting an uint64 as a message.
|
||||
func siphash(k0, k1, m uint64) uint64 {
|
||||
// Initialization.
|
||||
v0 := k0 ^ 0x736f6d6570736575
|
||||
|
||||
@@ -153,7 +153,7 @@ func (input *BeegoInput) IsHead() bool {
|
||||
return input.Is("HEAD")
|
||||
}
|
||||
|
||||
// IsOptions Is this a OPTIONS method request?
|
||||
// IsOptions Is this an OPTIONS method request?
|
||||
func (input *BeegoInput) IsOptions() bool {
|
||||
return input.Is("OPTIONS")
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"reflect"
|
||||
@@ -211,6 +213,7 @@ func (p *ControllerRegister) Init() {
|
||||
|
||||
// Add controller handler and pattern rules to ControllerRegister.
|
||||
// usage:
|
||||
//
|
||||
// default methods is the same name as method
|
||||
// Add("/user",&UserController{})
|
||||
// Add("/api/list",&RestController{},"*:ListFood")
|
||||
@@ -348,9 +351,10 @@ func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
||||
// GetContext returns a context from pool, so usually you should remember to call Reset function to clean the context
|
||||
// And don't forget to give back context to pool
|
||||
// example:
|
||||
// ctx := p.GetContext()
|
||||
// ctx.Reset(w, q)
|
||||
// defer p.GiveBackContext(ctx)
|
||||
//
|
||||
// ctx := p.GetContext()
|
||||
// ctx.Reset(w, q)
|
||||
// defer p.GiveBackContext(ctx)
|
||||
func (p *ControllerRegister) GetContext() *beecontext.Context {
|
||||
return p.pool.Get().(*beecontext.Context)
|
||||
}
|
||||
@@ -362,14 +366,16 @@ func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
||||
|
||||
// CtrlGet add get method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlGet("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlGet("/api/:id", MyController.Ping)
|
||||
//
|
||||
// If the receiver of function Ping is pointer, you should use CtrlGet("/api/:id", (*MyController).Ping)
|
||||
func (p *ControllerRegister) CtrlGet(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodGet, pattern, f)
|
||||
@@ -377,14 +383,16 @@ func (p *ControllerRegister) CtrlGet(pattern string, f interface{}) {
|
||||
|
||||
// CtrlPost add post method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlPost("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlPost("/api/:id", MyController.Ping)
|
||||
//
|
||||
// If the receiver of function Ping is pointer, you should use CtrlPost("/api/:id", (*MyController).Ping)
|
||||
func (p *ControllerRegister) CtrlPost(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodPost, pattern, f)
|
||||
@@ -392,14 +400,16 @@ func (p *ControllerRegister) CtrlPost(pattern string, f interface{}) {
|
||||
|
||||
// CtrlHead add head method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlHead("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlHead("/api/:id", MyController.Ping)
|
||||
//
|
||||
// If the receiver of function Ping is pointer, you should use CtrlHead("/api/:id", (*MyController).Ping)
|
||||
func (p *ControllerRegister) CtrlHead(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodHead, pattern, f)
|
||||
@@ -422,70 +432,75 @@ func (p *ControllerRegister) CtrlPut(pattern string, f interface{}) {
|
||||
|
||||
// CtrlPatch add patch method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlPatch("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlPatch("/api/:id", MyController.Ping)
|
||||
func (p *ControllerRegister) CtrlPatch(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodPatch, pattern, f)
|
||||
}
|
||||
|
||||
// CtrlDelete add delete method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlDelete("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlDelete("/api/:id", MyController.Ping)
|
||||
func (p *ControllerRegister) CtrlDelete(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodDelete, pattern, f)
|
||||
}
|
||||
|
||||
// CtrlOptions add options method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlOptions("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlOptions("/api/:id", MyController.Ping)
|
||||
func (p *ControllerRegister) CtrlOptions(pattern string, f interface{}) {
|
||||
p.AddRouterMethod(http.MethodOptions, pattern, f)
|
||||
}
|
||||
|
||||
// CtrlAny add all method
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlAny("/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// CtrlAny("/api/:id", MyController.Ping)
|
||||
func (p *ControllerRegister) CtrlAny(pattern string, f interface{}) {
|
||||
p.AddRouterMethod("*", pattern, f)
|
||||
}
|
||||
|
||||
// AddRouterMethod add http method router
|
||||
// usage:
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// AddRouterMethod("get","/api/:id", MyController.Ping)
|
||||
// type MyController struct {
|
||||
// web.Controller
|
||||
// }
|
||||
// func (m MyController) Ping() {
|
||||
// m.Ctx.Output.Body([]byte("hello world"))
|
||||
// }
|
||||
//
|
||||
// AddRouterMethod("get","/api/:id", MyController.Ping)
|
||||
func (p *ControllerRegister) AddRouterMethod(httpMethod, pattern string, f interface{}) {
|
||||
httpMethod = p.getUpperMethodString(httpMethod)
|
||||
ct, methodName := getReflectTypeAndMethod(f)
|
||||
@@ -624,81 +639,90 @@ type HandleFunc func(ctx *beecontext.Context)
|
||||
|
||||
// Get add get method
|
||||
// usage:
|
||||
// Get("/", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Get("/", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Get(pattern string, f HandleFunc) {
|
||||
p.AddMethod("get", pattern, f)
|
||||
}
|
||||
|
||||
// Post add post method
|
||||
// usage:
|
||||
// Post("/api", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Post("/api", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Post(pattern string, f HandleFunc) {
|
||||
p.AddMethod("post", pattern, f)
|
||||
}
|
||||
|
||||
// Put add put method
|
||||
// usage:
|
||||
// Put("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Put("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Put(pattern string, f HandleFunc) {
|
||||
p.AddMethod("put", pattern, f)
|
||||
}
|
||||
|
||||
// Delete add delete method
|
||||
// usage:
|
||||
// Delete("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Delete("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Delete(pattern string, f HandleFunc) {
|
||||
p.AddMethod("delete", pattern, f)
|
||||
}
|
||||
|
||||
// Head add head method
|
||||
// usage:
|
||||
// Head("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Head("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Head(pattern string, f HandleFunc) {
|
||||
p.AddMethod("head", pattern, f)
|
||||
}
|
||||
|
||||
// Patch add patch method
|
||||
// usage:
|
||||
// Patch("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Patch("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Patch(pattern string, f HandleFunc) {
|
||||
p.AddMethod("patch", pattern, f)
|
||||
}
|
||||
|
||||
// Options add options method
|
||||
// usage:
|
||||
// Options("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Options("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Options(pattern string, f HandleFunc) {
|
||||
p.AddMethod("options", pattern, f)
|
||||
}
|
||||
|
||||
// Any add all method
|
||||
// usage:
|
||||
// Any("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// Any("/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) Any(pattern string, f HandleFunc) {
|
||||
p.AddMethod("*", pattern, f)
|
||||
}
|
||||
|
||||
// AddMethod add http method router
|
||||
// usage:
|
||||
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
//
|
||||
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
||||
// ctx.Output.Body("hello world")
|
||||
// })
|
||||
func (p *ControllerRegister) AddMethod(method, pattern string, f HandleFunc) {
|
||||
method = p.getUpperMethodString(method)
|
||||
|
||||
@@ -772,8 +796,8 @@ func (p *ControllerRegister) addAutoPrefixMethod(prefix, controllerName, methodN
|
||||
|
||||
// InsertFilter Add a FilterFunc with pattern rule and action constant.
|
||||
// params is for:
|
||||
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
||||
// 2. determining whether or not params need to be reset.
|
||||
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
||||
// 2. determining whether or not params need to be reset.
|
||||
func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, opts ...FilterOpt) error {
|
||||
opts = append(opts, WithCaseSensitive(p.cfg.RouterCaseSensitive))
|
||||
mr := newFilterRouter(pattern, filter, opts...)
|
||||
@@ -784,13 +808,14 @@ func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter Filter
|
||||
// but it will using chainRoot.filterFunc as input to build a new filterFunc
|
||||
// for example, assume that chainRoot is funcA
|
||||
// and we add new FilterChain
|
||||
// fc := func(next) {
|
||||
// return func(ctx) {
|
||||
// // do something
|
||||
// next(ctx)
|
||||
// // do something
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fc := func(next) {
|
||||
// return func(ctx) {
|
||||
// // do something
|
||||
// next(ctx)
|
||||
// // do something
|
||||
// }
|
||||
// }
|
||||
func (p *ControllerRegister) InsertFilterChain(pattern string, chain FilterChain, opts ...FilterOpt) {
|
||||
opts = append([]FilterOpt{WithCaseSensitive(p.cfg.RouterCaseSensitive)}, opts...)
|
||||
p.filterChains = append(p.filterChains, filterChainConfig{
|
||||
@@ -1025,10 +1050,14 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
|
||||
}
|
||||
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
body := ctx.Input.Context.Request.Body
|
||||
if body == nil {
|
||||
body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
|
||||
if ctx.Input.IsUpload() {
|
||||
ctx.Input.Context.Request.Body = http.MaxBytesReader(ctx.Input.Context.ResponseWriter,
|
||||
ctx.Input.Context.Request.Body,
|
||||
body,
|
||||
p.cfg.MaxUploadSize)
|
||||
} else if p.cfg.CopyRequestBody {
|
||||
// connection will close if the incoming data are larger (RFC 7231, 6.5.11)
|
||||
@@ -1040,7 +1069,7 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
|
||||
ctx.Input.CopyBody(p.cfg.MaxMemory)
|
||||
} else {
|
||||
ctx.Input.Context.Request.Body = http.MaxBytesReader(ctx.Input.Context.ResponseWriter,
|
||||
ctx.Input.Context.Request.Body,
|
||||
body,
|
||||
p.cfg.MaxMemory)
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func encrypt(block cipher.Block, value []byte) ([]byte, error) {
|
||||
|
||||
// decrypt decrypts a value using the given block in counter mode.
|
||||
//
|
||||
// The value to be decrypted must be prepended by a initialization vector
|
||||
// The value to be decrypted must be prepended by an initialization vector
|
||||
// (http://goo.gl/zF67k) with the length of the block size.
|
||||
func decrypt(block cipher.Block, value []byte) ([]byte, error) {
|
||||
size := block.BlockSize()
|
||||
|
||||
@@ -103,7 +103,7 @@ func init() {
|
||||
beegoTplFuncMap["lt"] = lt // <
|
||||
beegoTplFuncMap["ne"] = ne // !=
|
||||
|
||||
beegoTplFuncMap["urlfor"] = URLFor // build a URL to match a Controller and it's method
|
||||
beegoTplFuncMap["urlfor"] = URLFor // build an URL to match a Controller and it's method
|
||||
}
|
||||
|
||||
// AddFuncMap let user to register a func in the template.
|
||||
|
||||
Reference in New Issue
Block a user