mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
chore: fix warnings (#3989)
This commit is contained in:
parent
69bb746a1d
commit
159ecb7386
@ -130,7 +130,7 @@ func (r *redisBitSet) check(ctx context.Context, offsets []uint) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, err := r.store.ScriptRunCtx(ctx, testScript, []string{r.key}, args)
|
resp, err := r.store.ScriptRunCtx(ctx, testScript, []string{r.key}, args)
|
||||||
if err == redis.Nil {
|
if errors.Is(err, redis.Nil) {
|
||||||
return false, nil
|
return false, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -162,7 +162,7 @@ func (r *redisBitSet) set(ctx context.Context, offsets []uint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = r.store.ScriptRunCtx(ctx, setScript, []string{r.key}, args)
|
_, err = r.store.ScriptRunCtx(ctx, setScript, []string{r.key}, args)
|
||||||
if err == redis.Nil {
|
if errors.Is(err, redis.Nil) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ var (
|
|||||||
zero = big.NewInt(0)
|
zero = big.NewInt(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
// DhKey defines the Diffie Hellman key.
|
// DhKey defines the Diffie-Hellman key.
|
||||||
type DhKey struct {
|
type DhKey struct {
|
||||||
PriKey *big.Int
|
PriKey *big.Int
|
||||||
PubKey *big.Int
|
PubKey *big.Int
|
||||||
@ -46,7 +46,7 @@ func ComputeKey(pubKey, priKey *big.Int) (*big.Int, error) {
|
|||||||
return new(big.Int).Exp(pubKey, priKey, p), nil
|
return new(big.Int).Exp(pubKey, priKey, p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateKey returns a Diffie Hellman key.
|
// GenerateKey returns a Diffie-Hellman key.
|
||||||
func GenerateKey() (*DhKey, error) {
|
func GenerateKey() (*DhKey, error) {
|
||||||
var err error
|
var err error
|
||||||
var x *big.Int
|
var x *big.Int
|
||||||
|
@ -128,8 +128,8 @@ func (c *Cache) Take(key string, fetch func() (any, error)) (any, error) {
|
|||||||
|
|
||||||
var fresh bool
|
var fresh bool
|
||||||
val, err := c.barrier.Do(key, func() (any, error) {
|
val, err := c.barrier.Do(key, func() (any, error) {
|
||||||
// because O(1) on map search in memory, and fetch is an IO query
|
// because O(1) on map search in memory, and fetch is an IO query,
|
||||||
// so we do double check, cache might be taken by another call
|
// so we do double-check, cache might be taken by another call
|
||||||
if val, ok := c.doGet(key); ok {
|
if val, ok := c.doGet(key); ok {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ func addOrMergeFields(info *fieldInfo, key string, child *fieldInfo, fullName st
|
|||||||
return newConflictKeyError(fullName)
|
return newConflictKeyError(fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mergeFields(prev, key, child.children, fullName); err != nil {
|
if err := mergeFields(prev, child.children, fullName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -281,7 +281,7 @@ func getTagName(field reflect.StructField) string {
|
|||||||
return field.Name
|
return field.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeFields(prev *fieldInfo, key string, children map[string]*fieldInfo, fullName string) error {
|
func mergeFields(prev *fieldInfo, children map[string]*fieldInfo, fullName string) error {
|
||||||
if len(prev.children) == 0 || len(children) == 0 {
|
if len(prev.children) == 0 || len(children) == 0 {
|
||||||
return newConflictKeyError(fullName)
|
return newConflictKeyError(fullName)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import "gopkg.in/cheggaaa/pb.v1"
|
|||||||
type (
|
type (
|
||||||
// A Scanner is used to read lines.
|
// A Scanner is used to read lines.
|
||||||
Scanner interface {
|
Scanner interface {
|
||||||
// Scan checks if has remaining to read.
|
// Scan checks if it has remaining to read.
|
||||||
Scan() bool
|
Scan() bool
|
||||||
// Text returns next line.
|
// Text returns next line.
|
||||||
Text() string
|
Text() string
|
||||||
|
@ -352,7 +352,7 @@ func (s Stream) Parallel(fn ParallelFunc, opts ...Option) {
|
|||||||
}, opts...).Done()
|
}, opts...).Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce is an utility method to let the caller deal with the underlying channel.
|
// Reduce is a utility method to let the caller deal with the underlying channel.
|
||||||
func (s Stream) Reduce(fn ReduceFunc) (any, error) {
|
func (s Stream) Reduce(fn ReduceFunc) (any, error) {
|
||||||
return fn(s.source)
|
return fn(s.source)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package iox
|
|||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
// RedirectInOut redirects stdin to r, stdout to w, and callers need to call restore afterwards.
|
// RedirectInOut redirects stdin to r, stdout to w, and callers need to call restore afterward.
|
||||||
func RedirectInOut() (restore func(), err error) {
|
func RedirectInOut() (restore func(), err error) {
|
||||||
var r, w *os.File
|
var r, w *os.File
|
||||||
r, w, err = os.Pipe()
|
r, w, err = os.Pipe()
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
const bufSize = 32 * 1024
|
const bufSize = 32 * 1024
|
||||||
|
|
||||||
// CountLines returns the number of lines in file.
|
// CountLines returns the number of lines in the file.
|
||||||
func CountLines(file string) (int, error) {
|
func CountLines(file string) (int, error) {
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A TextLineScanner is a scanner that can scan lines from given reader.
|
// A TextLineScanner is a scanner that can scan lines from the given reader.
|
||||||
type TextLineScanner struct {
|
type TextLineScanner struct {
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
hasNext bool
|
hasNext bool
|
||||||
@ -14,7 +14,7 @@ type TextLineScanner struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextLineScanner returns a TextLineScanner with given reader.
|
// NewTextLineScanner returns a TextLineScanner with the given reader.
|
||||||
func NewTextLineScanner(reader io.Reader) *TextLineScanner {
|
func NewTextLineScanner(reader io.Reader) *TextLineScanner {
|
||||||
return &TextLineScanner{
|
return &TextLineScanner{
|
||||||
reader: bufio.NewReader(reader),
|
reader: bufio.NewReader(reader),
|
||||||
|
@ -125,7 +125,7 @@ func (lim *TokenLimiter) reserveN(ctx context.Context, now time.Time, n int) boo
|
|||||||
})
|
})
|
||||||
// redis allowed == false
|
// redis allowed == false
|
||||||
// Lua boolean false -> r Nil bulk reply
|
// Lua boolean false -> r Nil bulk reply
|
||||||
if err == redis.Nil {
|
if errors.Is(err, redis.Nil) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
|
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
|
||||||
|
@ -138,10 +138,10 @@ func (as *adaptiveShedder) Allow() (Promise, error) {
|
|||||||
func (as *adaptiveShedder) addFlying(delta int64) {
|
func (as *adaptiveShedder) addFlying(delta int64) {
|
||||||
flying := atomic.AddInt64(&as.flying, delta)
|
flying := atomic.AddInt64(&as.flying, delta)
|
||||||
// update avgFlying when the request is finished.
|
// update avgFlying when the request is finished.
|
||||||
// this strategy makes avgFlying have a little bit lag against flying, and smoother.
|
// this strategy makes avgFlying have a little bit of lag against flying, and smoother.
|
||||||
// when the flying requests increase rapidly, avgFlying increase slower, accept more requests.
|
// when the flying requests increase rapidly, avgFlying increase slower, accept more requests.
|
||||||
// when the flying requests drop rapidly, avgFlying drop slower, accept fewer requests.
|
// when the flying requests drop rapidly, avgFlying drop slower, accept fewer requests.
|
||||||
// it makes the service to serve as more requests as possible.
|
// it makes the service to serve as many requests as possible.
|
||||||
if delta < 0 {
|
if delta < 0 {
|
||||||
as.avgFlyingLock.Lock()
|
as.avgFlyingLock.Lock()
|
||||||
as.avgFlying = as.avgFlying*flyingBeta + float64(flying)*(1-flyingBeta)
|
as.avgFlying = as.avgFlying*flyingBeta + float64(flying)*(1-flyingBeta)
|
||||||
@ -200,7 +200,7 @@ func (as *adaptiveShedder) minRt() float64 {
|
|||||||
func (as *adaptiveShedder) overloadFactor() float64 {
|
func (as *adaptiveShedder) overloadFactor() float64 {
|
||||||
// as.cpuThreshold must be less than cpuMax
|
// as.cpuThreshold must be less than cpuMax
|
||||||
factor := (cpuMax - float64(stat.CpuUsage())) / (cpuMax - float64(as.cpuThreshold))
|
factor := (cpuMax - float64(stat.CpuUsage())) / (cpuMax - float64(as.cpuThreshold))
|
||||||
// at least accept 10% of acceptable requests even cpu is highly overloaded.
|
// at least accept 10% of acceptable requests, even cpu is highly overloaded.
|
||||||
return mathx.Between(factor, overloadFactorLowerBound, 1)
|
return mathx.Between(factor, overloadFactorLowerBound, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,14 +250,14 @@ func (as *adaptiveShedder) systemOverloaded() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBuckets customizes the Shedder with given number of buckets.
|
// WithBuckets customizes the Shedder with the given number of buckets.
|
||||||
func WithBuckets(buckets int) ShedderOption {
|
func WithBuckets(buckets int) ShedderOption {
|
||||||
return func(opts *shedderOptions) {
|
return func(opts *shedderOptions) {
|
||||||
opts.buckets = buckets
|
opts.buckets = buckets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCpuThreshold customizes the Shedder with given cpu threshold.
|
// WithCpuThreshold customizes the Shedder with the given cpu threshold.
|
||||||
func WithCpuThreshold(threshold int64) ShedderOption {
|
func WithCpuThreshold(threshold int64) ShedderOption {
|
||||||
return func(opts *shedderOptions) {
|
return func(opts *shedderOptions) {
|
||||||
opts.cpuThreshold = threshold
|
opts.cpuThreshold = threshold
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/syncx"
|
"github.com/zeromicro/go-zero/core/syncx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A ShedderGroup is a manager to manage key based shedders.
|
// A ShedderGroup is a manager to manage key-based shedders.
|
||||||
type ShedderGroup struct {
|
type ShedderGroup struct {
|
||||||
options []ShedderOption
|
options []ShedderOption
|
||||||
manager *syncx.ResourceManager
|
manager *syncx.ResourceManager
|
||||||
|
@ -42,7 +42,7 @@ func Debugv(ctx context.Context, v interface{}) {
|
|||||||
getLogger(ctx).Debugv(v)
|
getLogger(ctx).Debugv(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugw writes msg along with fields into access log.
|
// Debugw writes msg along with fields into the access log.
|
||||||
func Debugw(ctx context.Context, msg string, fields ...LogField) {
|
func Debugw(ctx context.Context, msg string, fields ...LogField) {
|
||||||
getLogger(ctx).Debugw(msg, fields...)
|
getLogger(ctx).Debugw(msg, fields...)
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func Errorv(ctx context.Context, v any) {
|
|||||||
getLogger(ctx).Errorv(v)
|
getLogger(ctx).Errorv(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorw writes msg along with fields into error log.
|
// Errorw writes msg along with fields into the error log.
|
||||||
func Errorw(ctx context.Context, msg string, fields ...LogField) {
|
func Errorw(ctx context.Context, msg string, fields ...LogField) {
|
||||||
getLogger(ctx).Errorw(msg, fields...)
|
getLogger(ctx).Errorw(msg, fields...)
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func Infov(ctx context.Context, v any) {
|
|||||||
getLogger(ctx).Infov(v)
|
getLogger(ctx).Infov(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infow writes msg along with fields into access log.
|
// Infow writes msg along with fields into the access log.
|
||||||
func Infow(ctx context.Context, msg string, fields ...LogField) {
|
func Infow(ctx context.Context, msg string, fields ...LogField) {
|
||||||
getLogger(ctx).Infow(msg, fields...)
|
getLogger(ctx).Infow(msg, fields...)
|
||||||
}
|
}
|
||||||
@ -108,10 +108,11 @@ func SetLevel(level uint32) {
|
|||||||
logx.SetLevel(level)
|
logx.SetLevel(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUp sets up the logx. If already set up, just return nil.
|
// SetUp sets up the logx.
|
||||||
// we allow SetUp to be called multiple times, because for example
|
// If already set up, return nil.
|
||||||
|
// We allow SetUp to be called multiple times, because, for example,
|
||||||
// we need to allow different service frameworks to initialize logx respectively.
|
// we need to allow different service frameworks to initialize logx respectively.
|
||||||
// the same logic for SetUp
|
// The same logic for SetUp
|
||||||
func SetUp(c LogConf) error {
|
func SetUp(c LogConf) error {
|
||||||
return logx.SetUp(c)
|
return logx.SetUp(c)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package logx
|
package logx
|
||||||
|
|
||||||
// A LessLogger is a logger that control to log once during the given duration.
|
// A LessLogger is a logger that controls to log once during the given duration.
|
||||||
type LessLogger struct {
|
type LessLogger struct {
|
||||||
*limitedExecutor
|
*limitedExecutor
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func Debugv(v any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugw writes msg along with fields into access log.
|
// Debugw writes msg along with fields into the access log.
|
||||||
func Debugw(msg string, fields ...LogField) {
|
func Debugw(msg string, fields ...LogField) {
|
||||||
if shallLog(DebugLevel) {
|
if shallLog(DebugLevel) {
|
||||||
writeDebug(msg, fields...)
|
writeDebug(msg, fields...)
|
||||||
@ -142,7 +142,7 @@ func Errorv(v any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorw writes msg along with fields into error log.
|
// Errorw writes msg along with fields into the error log.
|
||||||
func Errorw(msg string, fields ...LogField) {
|
func Errorw(msg string, fields ...LogField) {
|
||||||
if shallLog(ErrorLevel) {
|
if shallLog(ErrorLevel) {
|
||||||
writeError(msg, fields...)
|
writeError(msg, fields...)
|
||||||
@ -208,7 +208,7 @@ func Infov(v any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Infow writes msg along with fields into access log.
|
// Infow writes msg along with fields into the access log.
|
||||||
func Infow(msg string, fields ...LogField) {
|
func Infow(msg string, fields ...LogField) {
|
||||||
if shallLog(InfoLevel) {
|
if shallLog(InfoLevel) {
|
||||||
writeInfo(msg, fields...)
|
writeInfo(msg, fields...)
|
||||||
@ -254,11 +254,12 @@ func SetWriter(w Writer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUp sets up the logx. If already set up, just return nil.
|
// SetUp sets up the logx.
|
||||||
// we allow SetUp to be called multiple times, because for example
|
// If already set up, return nil.
|
||||||
|
// We allow SetUp to be called multiple times, because, for example,
|
||||||
// we need to allow different service frameworks to initialize logx respectively.
|
// we need to allow different service frameworks to initialize logx respectively.
|
||||||
func SetUp(c LogConf) (err error) {
|
func SetUp(c LogConf) (err error) {
|
||||||
// Just ignore the subsequent SetUp calls.
|
// Ignore the later SetUp calls.
|
||||||
// Because multiple services in one process might call SetUp respectively.
|
// Because multiple services in one process might call SetUp respectively.
|
||||||
// Need to wait for the first caller to complete the execution.
|
// Need to wait for the first caller to complete the execution.
|
||||||
setupOnce.Do(func() {
|
setupOnce.Do(func() {
|
||||||
@ -480,7 +481,7 @@ func writeDebug(val any, fields ...LogField) {
|
|||||||
getWriter().Debug(val, addCaller(fields...)...)
|
getWriter().Debug(val, addCaller(fields...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeError writes v into error log.
|
// writeError writes v into the error log.
|
||||||
// Not checking shallLog here is for performance consideration.
|
// Not checking shallLog here is for performance consideration.
|
||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
@ -520,7 +521,7 @@ func writeStack(msg string) {
|
|||||||
getWriter().Stack(fmt.Sprintf("%s\n%s", msg, string(debug.Stack())))
|
getWriter().Stack(fmt.Sprintf("%s\n%s", msg, string(debug.Stack())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeStat writes v into stat log.
|
// writeStat writes v into the stat log.
|
||||||
// Not checking shallLog here is for performance consideration.
|
// Not checking shallLog here is for performance consideration.
|
||||||
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
// If we check shallLog here, the fmt.Sprint might be called even if the log level is not enabled.
|
||||||
// The caller should check shallLog before calling this function.
|
// The caller should check shallLog before calling this function.
|
||||||
|
@ -570,7 +570,7 @@ func TestErrorfWithWrappedError(t *testing.T) {
|
|||||||
old := writer.Swap(w)
|
old := writer.Swap(w)
|
||||||
defer writer.Store(old)
|
defer writer.Store(old)
|
||||||
|
|
||||||
Errorf("hello %w", errors.New(message))
|
Errorf("hello %s", errors.New(message))
|
||||||
assert.True(t, strings.Contains(w.String(), "hello there"))
|
assert.True(t, strings.Contains(w.String(), "hello there"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,7 +319,7 @@ func (l *RotateLogger) maybeCompressFile(file string) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if _, err := os.Stat(file); err != nil {
|
if _, err := os.Stat(file); err != nil {
|
||||||
// file not exists or other error, ignore compression
|
// file doesn't exist or another error, ignore compression
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Marshal marshals the given val and returns the map that contains the fields.
|
// Marshal marshals the given val and returns the map that contains the fields.
|
||||||
// optional=another is not implemented, and it's hard to implement and not common used.
|
// optional=another is not implemented, and it's hard to implement and not commonly used.
|
||||||
func Marshal(val any) (map[string]map[string]any, error) {
|
func Marshal(val any) (map[string]map[string]any, error) {
|
||||||
ret := make(map[string]map[string]any)
|
ret := make(map[string]map[string]any)
|
||||||
tp := reflect.TypeOf(val)
|
tp := reflect.TypeOf(val)
|
||||||
|
@ -39,7 +39,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Unmarshaler is used to unmarshal with given tag key.
|
// Unmarshaler is used to unmarshal with the given tag key.
|
||||||
Unmarshaler struct {
|
Unmarshaler struct {
|
||||||
key string
|
key string
|
||||||
opts unmarshalOptions
|
opts unmarshalOptions
|
||||||
@ -69,7 +69,7 @@ func NewUnmarshaler(key string, opts ...UnmarshalOption) *Unmarshaler {
|
|||||||
return &unmarshaler
|
return &unmarshaler
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalKey unmarshals m into v with tag key.
|
// UnmarshalKey unmarshals m into v with the tag key.
|
||||||
func UnmarshalKey(m map[string]any, v any) error {
|
func UnmarshalKey(m map[string]any, v any) error {
|
||||||
return keyUnmarshaler.Unmarshal(m, v)
|
return keyUnmarshaler.Unmarshal(m, v)
|
||||||
}
|
}
|
||||||
@ -629,7 +629,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if value is a pointer, we need to check overflow with the pointer's value.
|
// if the value is a pointer, we need to check overflow with the pointer's value.
|
||||||
derefedValue := value
|
derefedValue := value
|
||||||
for derefedValue.Type().Kind() == reflect.Ptr {
|
for derefedValue.Type().Kind() == reflect.Ptr {
|
||||||
derefedValue = derefedValue.Elem()
|
derefedValue = derefedValue.Elem()
|
||||||
|
@ -5866,7 +5866,7 @@ type mockValuerWithParent struct {
|
|||||||
ok bool
|
ok bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockValuerWithParent) Value(key string) (any, bool) {
|
func (m mockValuerWithParent) Value(_ string) (any, bool) {
|
||||||
return m.value, m.ok
|
return m.value, m.ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ func parseOption(fieldOpts *fieldOptions, fieldName, option string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseOptions parses the given options in tag.
|
// parseOptions parses the given options in tag.
|
||||||
// for example: `json:"name,options=foo|bar"` or `json:"name,options=[foo,bar]"`
|
// for example, `json:"name,options=foo|bar"` or `json:"name,options=[foo,bar]"`
|
||||||
func parseOptions(val string) []string {
|
func parseOptions(val string) []string {
|
||||||
if len(val) == 0 {
|
if len(val) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -26,9 +26,9 @@ type (
|
|||||||
parent valuerWithParent
|
parent valuerWithParent
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapValuer is a type for map to meet the Valuer interface.
|
// mapValuer is a type for the map to meet the Valuer interface.
|
||||||
mapValuer map[string]any
|
mapValuer map[string]any
|
||||||
// simpleValuer is a type to get value from current node.
|
// simpleValuer is a type to get value from the current node.
|
||||||
simpleValuer node
|
simpleValuer node
|
||||||
// recursiveValuer is a type to get the value recursively from current and parent nodes.
|
// recursiveValuer is a type to get the value recursively from current and parent nodes.
|
||||||
recursiveValuer node
|
recursiveValuer node
|
||||||
|
@ -36,6 +36,6 @@ type fakeCreator struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fc fakeCreator) Create(name string) (file *os.File, err error) {
|
func (fc fakeCreator) Create(_ string) (file *os.File, err error) {
|
||||||
return fc.file, fc.err
|
return fc.file, fc.err
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (q *Queue) AddListener(listener Listener) {
|
|||||||
q.listeners = append(q.listeners, listener)
|
q.listeners = append(q.listeners, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast broadcasts message to all event channels.
|
// Broadcast broadcasts the message to all event channels.
|
||||||
func (q *Queue) Broadcast(message any) {
|
func (q *Queue) Broadcast(message any) {
|
||||||
go func() {
|
go func() {
|
||||||
q.eventLock.Lock()
|
q.eventLock.Lock()
|
||||||
@ -202,7 +202,7 @@ func (q *Queue) produce() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queue) produceOne(producer Producer) (string, bool) {
|
func (q *Queue) produceOne(producer Producer) (string, bool) {
|
||||||
// avoid panic quit the producer, just log it and continue
|
// avoid panic quit the producer, log it and continue
|
||||||
defer rescue.Recover()
|
defer rescue.Recover()
|
||||||
|
|
||||||
return producer.Produce()
|
return producer.Produce()
|
||||||
|
@ -67,7 +67,7 @@ func (p *mockedPusher) Name() string {
|
|||||||
return p.name
|
return p.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mockedPusher) Push(s string) error {
|
func (p *mockedPusher) Push(_ string) error {
|
||||||
if proba.TrueOnProba(failProba) {
|
if proba.TrueOnProba(failProba) {
|
||||||
return errors.New("dummy")
|
return errors.New("dummy")
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,6 @@ func (m *mockedWriter) Write(report *StatReport) error {
|
|||||||
|
|
||||||
type badWriter struct{}
|
type badWriter struct{}
|
||||||
|
|
||||||
func (b *badWriter) Write(report *StatReport) error {
|
func (b *badWriter) Write(_ *StatReport) error {
|
||||||
return errors.New("bad")
|
return errors.New("bad")
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package stat
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// A Task is a task that is reported to Metrics.
|
// A Task is a task reported to Metrics.
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Drop bool
|
Drop bool
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
|
2
core/stores/cache/cacheopt.go
vendored
2
core/stores/cache/cacheopt.go
vendored
@ -8,7 +8,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// An Options is used to store the cache options.
|
// Options is used to store the cache options.
|
||||||
Options struct {
|
Options struct {
|
||||||
Expiry time.Duration
|
Expiry time.Duration
|
||||||
NotFoundExpiry time.Duration
|
NotFoundExpiry time.Duration
|
||||||
|
@ -47,7 +47,7 @@ func (rc RedisConf) NewRedis() *Redis {
|
|||||||
opts = append(opts, WithTLS())
|
opts = append(opts, WithTLS())
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(rc.Host, opts...)
|
return newRedis(rc.Host, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the RedisConf.
|
// Validate validates the RedisConf.
|
||||||
|
@ -2,6 +2,7 @@ package redis
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -64,7 +65,7 @@ func (rl *RedisLock) AcquireCtx(ctx context.Context) (bool, error) {
|
|||||||
resp, err := rl.store.ScriptRunCtx(ctx, lockScript, []string{rl.key}, []string{
|
resp, err := rl.store.ScriptRunCtx(ctx, lockScript, []string{rl.key}, []string{
|
||||||
rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance),
|
rl.id, strconv.Itoa(int(seconds)*millisPerSecond + tolerance),
|
||||||
})
|
})
|
||||||
if err == red.Nil {
|
if errors.Is(err, red.Nil) {
|
||||||
return false, nil
|
return false, nil
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
logx.Errorf("Error on acquiring lock for %s, %s", rl.key, err.Error())
|
logx.Errorf("Error on acquiring lock for %s, %s", rl.key, err.Error())
|
||||||
|
@ -34,7 +34,7 @@ type mockSpan struct {
|
|||||||
options []trace.EventOption
|
options []trace.EventOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) End(options ...trace.SpanEndOption) {
|
func (m *mockSpan) End(_ ...trace.SpanEndOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) AddEvent(name string, options ...trace.EventOption) {
|
func (m *mockSpan) AddEvent(name string, options ...trace.EventOption) {
|
||||||
@ -46,20 +46,20 @@ func (m *mockSpan) IsRecording() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) RecordError(err error, options ...trace.EventOption) {
|
func (m *mockSpan) RecordError(_ error, _ ...trace.EventOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) SpanContext() trace.SpanContext {
|
func (m *mockSpan) SpanContext() trace.SpanContext {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) SetStatus(code codes.Code, description string) {
|
func (m *mockSpan) SetStatus(_ codes.Code, _ string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) SetName(name string) {
|
func (m *mockSpan) SetName(_ string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) SetAttributes(kv ...attribute.KeyValue) {
|
func (m *mockSpan) SetAttributes(_ ...attribute.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockSpan) TracerProvider() trace.TracerProvider {
|
func (m *mockSpan) TracerProvider() trace.TracerProvider {
|
||||||
|
@ -4,5 +4,5 @@ import "net/http"
|
|||||||
|
|
||||||
// TraceIdKey is the trace id header.
|
// TraceIdKey is the trace id header.
|
||||||
// https://www.w3.org/TR/trace-context/#trace-id
|
// https://www.w3.org/TR/trace-context/#trace-id
|
||||||
// May change it to trace-id afterwards.
|
// May change it to trace-id afterward.
|
||||||
var TraceIdKey = http.CanonicalHeaderKey("x-trace-id")
|
var TraceIdKey = http.CanonicalHeaderKey("x-trace-id")
|
||||||
|
Loading…
Reference in New Issue
Block a user