* 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 (#5032) 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>
		
			
				
	
	
		
			156 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			156 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2020 beego
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| // http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| package httplib
 | |
| 
 | |
| import (
 | |
| 	"crypto/tls"
 | |
| 	"net/http"
 | |
| 	"net/url"
 | |
| 	"time"
 | |
| )
 | |
| 
 | |
| type (
 | |
| 	ClientOption           func(client *Client)
 | |
| 	BeegoHTTPRequestOption func(request *BeegoHTTPRequest)
 | |
| )
 | |
| 
 | |
| // WithEnableCookie will enable cookie in all subsequent request
 | |
| func WithEnableCookie(enable bool) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.EnableCookie = enable
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithUserAgent will adds UA in all subsequent request
 | |
| func WithUserAgent(userAgent string) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.UserAgent = userAgent
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithTLSClientConfig will adds tls config in all subsequent request
 | |
| func WithTLSClientConfig(config *tls.Config) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.TLSClientConfig = config
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithTransport will set transport field in all subsequent request
 | |
| func WithTransport(transport http.RoundTripper) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.Transport = transport
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithProxy will set http proxy field in all subsequent request
 | |
| func WithProxy(proxy func(*http.Request) (*url.URL, error)) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.Proxy = proxy
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithCheckRedirect will specifies the policy for handling redirects in all subsequent request
 | |
| func WithCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.CheckRedirect = redirect
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithHTTPSetting can replace beegoHTTPSeting
 | |
| func WithHTTPSetting(setting BeegoHTTPSettings) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting = setting
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithEnableGzip will enable gzip in all subsequent request
 | |
| func WithEnableGzip(enable bool) ClientOption {
 | |
| 	return func(client *Client) {
 | |
| 		client.Setting.Gzip = enable
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // BeegoHttpRequestOption
 | |
| 
 | |
| // WithTimeout sets connect time out and read-write time out for BeegoRequest.
 | |
| func WithTimeout(connectTimeout, readWriteTimeout time.Duration) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.SetTimeout(connectTimeout, readWriteTimeout)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithHeader adds header item string in request.
 | |
| func WithHeader(key, value string) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.Header(key, value)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithCookie adds a cookie to the request.
 | |
| func WithCookie(cookie *http.Cookie) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.Header("Cookie", cookie.String())
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithTokenFactory adds a custom function to set Authorization
 | |
| func WithTokenFactory(tokenFactory func() string) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		t := tokenFactory()
 | |
| 
 | |
| 		request.Header("Authorization", t)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithBasicAuth adds a custom function to set basic auth
 | |
| func WithBasicAuth(basicAuth func() (string, string)) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		username, password := basicAuth()
 | |
| 		request.SetBasicAuth(username, password)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithFilters will use the filter as the invocation filters
 | |
| func WithFilters(fcs ...FilterChain) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.SetFilters(fcs...)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithContentType adds ContentType in header
 | |
| func WithContentType(contentType string) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.Header(contentTypeKey, contentType)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithParam adds query param in to request.
 | |
| func WithParam(key, value string) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.Param(key, value)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // WithRetry set retry times and delay for the request
 | |
| // default is 0 (never retry)
 | |
| // -1 retry indefinitely (forever)
 | |
| // Other numbers specify the exact retry amount
 | |
| func WithRetry(times int, delay time.Duration) BeegoHTTPRequestOption {
 | |
| 	return func(request *BeegoHTTPRequest) {
 | |
| 		request.Retries(times)
 | |
| 		request.RetryDelay(delay)
 | |
| 	}
 | |
| }
 |