支持日志打印
This commit is contained in:
+33
-1
@@ -1,15 +1,21 @@
|
||||
package curlx
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type clientOptions struct {
|
||||
TimeOut time.Duration
|
||||
InsecureSkipVerify bool
|
||||
Logger OptionLogger
|
||||
}
|
||||
|
||||
func defaultOptions() clientOptions {
|
||||
return clientOptions{
|
||||
TimeOut: time.Second * 120, // 默认超时120
|
||||
Logger: defaultLogger{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,3 +38,29 @@ func SetOptionTLSInsecureSkipVerify() Option {
|
||||
options.InsecureSkipVerify = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置日志输出
|
||||
*/
|
||||
func SetOptionLog(log OptionLogger) Option {
|
||||
return func(options *clientOptions) {
|
||||
options.Logger = log
|
||||
}
|
||||
}
|
||||
|
||||
type OptionLogger interface {
|
||||
Infof(ctx context.Context, format string, args ...interface{})
|
||||
Errorf(ctx context.Context, format string, args ...interface{})
|
||||
}
|
||||
|
||||
type defaultLogger struct{}
|
||||
|
||||
func (defaultLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
|
||||
// 输出日志
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
func (defaultLogger) Infof(ctx context.Context, format string, args ...interface{}) {
|
||||
// 输出日志
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user