添加对应 php注册登录的token 验证逻辑
This commit is contained in:
		
							parent
							
								
									de7cd23deb
								
							
						
					
					
						commit
						62db070f61
					
				@ -34,6 +34,7 @@ func (m *KillaraCustomerTokenModel) InsertToken(data *KillaraCustomerToken) erro
 | 
				
			|||||||
	return m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
						return m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
				
			||||||
		// 查找是否存在相同客户ID、平台和Token的记录
 | 
							// 查找是否存在相同客户ID、平台和Token的记录
 | 
				
			||||||
		var existingToken KillaraCustomerToken
 | 
							var existingToken KillaraCustomerToken
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err := tx.Where("customer_id = ? AND platform = ? AND token = ?", data.CustomerId, data.Platform, *data.Token).First(&existingToken).Error
 | 
							err := tx.Where("customer_id = ? AND platform = ? AND token = ?", data.CustomerId, data.Platform, *data.Token).First(&existingToken).Error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
							if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
@ -44,7 +45,7 @@ func (m *KillaraCustomerTokenModel) InsertToken(data *KillaraCustomerToken) erro
 | 
				
			|||||||
		if !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
							if !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
			// 存在记录,先删除
 | 
								// 存在记录,先删除
 | 
				
			||||||
			err = tx.Delete(&existingToken).Error
 | 
								err = tx.Delete(&existingToken).Error
 | 
				
			||||||
			if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
 | 
								if err != nil {
 | 
				
			||||||
				tx.Rollback() // 删除错误,回滚事务
 | 
									tx.Rollback() // 删除错误,回滚事务
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -57,7 +58,7 @@ func (m *KillaraCustomerTokenModel) InsertToken(data *KillaraCustomerToken) erro
 | 
				
			|||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return tx.Commit().Error // 提交事务
 | 
							return err // 提交事务
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -113,12 +114,12 @@ func (m *KillaraCustomerTokenModel) GetToken(token string) (*KillaraCustomerToke
 | 
				
			|||||||
// 	return nil, nil
 | 
					// 	return nil, nil
 | 
				
			||||||
// }
 | 
					// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *KillaraCustomerTokenModel) CheckToken(token string) (*KillaraCustomerToken, error) {
 | 
					func (m *KillaraCustomerTokenModel) CheckToken(tokenstr string) (*KillaraCustomerToken, error) {
 | 
				
			||||||
	var resultToken *KillaraCustomerToken
 | 
						var resultToken *KillaraCustomerToken
 | 
				
			||||||
	err := m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
						err := m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
				
			||||||
		// 查找 Token 记录
 | 
							// 查找 Token 记录
 | 
				
			||||||
		var token KillaraCustomerToken
 | 
							var token KillaraCustomerToken
 | 
				
			||||||
		err := tx.Where("token = ?", token).First(&token).Error
 | 
							err := tx.Where("token = ?", tokenstr).First(&token).Error
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
								if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
				return nil
 | 
									return nil
 | 
				
			||||||
@ -138,7 +139,7 @@ func (m *KillaraCustomerTokenModel) CheckToken(token string) (*KillaraCustomerTo
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		resultToken = &token
 | 
							resultToken = &token
 | 
				
			||||||
		return tx.Commit().Error // 提交事务
 | 
							return err // 提交事务
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@ -150,7 +151,7 @@ func (m *KillaraCustomerTokenModel) CheckToken(token string) (*KillaraCustomerTo
 | 
				
			|||||||
func (m *KillaraCustomerTokenModel) ClearDuplicateToken(customerID uint64, currentToken string, platform int) error {
 | 
					func (m *KillaraCustomerTokenModel) ClearDuplicateToken(customerID uint64, currentToken string, platform int) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
						return m.db.Model(&KillaraCustomerToken{}).Transaction(func(tx *gorm.DB) error {
 | 
				
			||||||
		var tokens []KillaraCustomerToken
 | 
							var tokens []*KillaraCustomerToken
 | 
				
			||||||
		err := tx.Where("customer_id = ? AND platform = ?", customerID, platform).Find(&tokens).Error
 | 
							err := tx.Where("customer_id = ? AND platform = ?", customerID, platform).Find(&tokens).Error
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
								if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
@ -164,7 +165,7 @@ func (m *KillaraCustomerTokenModel) ClearDuplicateToken(customerID uint64, curre
 | 
				
			|||||||
		for _, token := range tokens {
 | 
							for _, token := range tokens {
 | 
				
			||||||
			if *token.Token != currentToken {
 | 
								if *token.Token != currentToken {
 | 
				
			||||||
				// err := tx.Delete(token).Error todo: 不太明白php为什么不删除token, 难道用来链路跟踪? 但是客户端id也被更新了, 没有存在的意义了
 | 
									// err := tx.Delete(token).Error todo: 不太明白php为什么不删除token, 难道用来链路跟踪? 但是客户端id也被更新了, 没有存在的意义了
 | 
				
			||||||
				err := tx.Where("token = ?", token).Update("customer_id", 0).Error
 | 
									err := tx.Where("token = ?", *token.Token).Update("customer_id", 0).Error
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
										if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
						return fmt.Errorf("tokens 查询出来, 自身都不存在, 疑似出了什么错误2")
 | 
											return fmt.Errorf("tokens 查询出来, 自身都不存在, 疑似出了什么错误2")
 | 
				
			||||||
 | 
				
			|||||||
@ -97,7 +97,7 @@ func BaseGetToken(ctx *ActionContext[BaseGetTokenParam]) (resp *basic.Response)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = modelToken.InsertToken(tokenItem)
 | 
							err = modelToken.InsertToken(tokenItem)
 | 
				
			||||||
		log.Println(err)
 | 
							log.Println(*tokenItem.Token)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return resp.ErrorErr(1, err)
 | 
								return resp.ErrorErr(1, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -342,7 +342,6 @@ func AccountLoginWithEmailPassword(ctx *ActionContext[AccountLoginWithEmailPassw
 | 
				
			|||||||
		return resp.ErrorErr(1, err)
 | 
							return resp.ErrorErr(1, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Println(ctx.Localize(translator.AccountNotRegistered))
 | 
					 | 
				
			||||||
	if customer == nil {
 | 
						if customer == nil {
 | 
				
			||||||
		return resp.ErrorTrCode(ctx, translator.AccountNotRegistered)
 | 
							return resp.ErrorTrCode(ctx, translator.AccountNotRegistered)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -5,6 +5,8 @@ import (
 | 
				
			|||||||
	"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
 | 
						"github.com/iapologizewhenimwrong/Vestmore_GO/utils/log"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var respLog = log.New(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 全局返回的结构体
 | 
					// 全局返回的结构体
 | 
				
			||||||
type Response struct {
 | 
					type Response struct {
 | 
				
			||||||
	Data      interface{} `json:"data"`
 | 
						Data      interface{} `json:"data"`
 | 
				
			||||||
@ -25,7 +27,7 @@ func (resp *Response) Error(errcode *ErrorCode, Data ...interface{}) *Response {
 | 
				
			|||||||
	resp.ErrorText = errcode.Message
 | 
						resp.ErrorText = errcode.Message
 | 
				
			||||||
	resp.IsSuccess = false
 | 
						resp.IsSuccess = false
 | 
				
			||||||
	resp.setData(Data)
 | 
						resp.setData(Data)
 | 
				
			||||||
	log.Error(resp.ErrorText)
 | 
						respLog.Error(resp.ErrorText)
 | 
				
			||||||
	return resp
 | 
						return resp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,7 +40,7 @@ func (resp *Response) ErrorErr(Code int, err error, Data ...interface{}) *Respon
 | 
				
			|||||||
	resp.IsSuccess = false
 | 
						resp.IsSuccess = false
 | 
				
			||||||
	resp.setData(Data)
 | 
						resp.setData(Data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	log.Error(resp.ErrorText)
 | 
						respLog.Error(resp.ErrorText)
 | 
				
			||||||
	return resp
 | 
						return resp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -50,7 +52,7 @@ func (resp *Response) ErrorMsg(Code int, Message string, Data ...interface{}) *R
 | 
				
			|||||||
	resp.ErrorText = Message
 | 
						resp.ErrorText = Message
 | 
				
			||||||
	resp.IsSuccess = false
 | 
						resp.IsSuccess = false
 | 
				
			||||||
	resp.setData(Data)
 | 
						resp.setData(Data)
 | 
				
			||||||
	log.Error(resp.ErrorText)
 | 
						respLog.Error(resp.ErrorText)
 | 
				
			||||||
	return resp
 | 
						return resp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@ import (
 | 
				
			|||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
@ -14,93 +13,50 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type levelSkip struct {
 | 
					type levelSkip struct {
 | 
				
			||||||
	SkipLogrus int
 | 
						Skip int
 | 
				
			||||||
	SkipBasic  int
 | 
						Once sync.Once
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// JSONFormatter formats logs into parsable json
 | 
					// JSONFormatter formats logs into parsable json
 | 
				
			||||||
type JSONFormatter struct {
 | 
					type JSONFormatter struct {
 | 
				
			||||||
	skip []*levelSkip
 | 
						diffSkip int
 | 
				
			||||||
	once sync.Once
 | 
						skip     []*levelSkip
 | 
				
			||||||
 | 
						once     sync.Once
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Format renders a single log entry
 | 
					// Format renders a single log entry
 | 
				
			||||||
func (h *JSONFormatter) Format(e *logrus.Entry) ([]byte, error) {
 | 
					func (h *JSONFormatter) Format(e *logrus.Entry) ([]byte, error) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	skipOnce := h.skip[int(e.Level)]
 | 
						skipOnce := h.skip[int(e.Level)]
 | 
				
			||||||
 | 
						skipOnce.Once.Do(func() {
 | 
				
			||||||
	if skipOnce.SkipLogrus == 0 {
 | 
							for i := 4; i < 100; i++ {
 | 
				
			||||||
		var skipLogrus OpenClose
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for i := 4; i < 50; i++ {
 | 
					 | 
				
			||||||
			// log.Println(i)
 | 
								// log.Println(i)
 | 
				
			||||||
			if pc, file, line, ok := runtime.Caller(i); ok {
 | 
								if pc, _, _, ok := runtime.Caller(i); ok {
 | 
				
			||||||
				funcStruct := runtime.FuncForPC(pc)
 | 
									funcStruct := runtime.FuncForPC(pc)
 | 
				
			||||||
				log.Println(funcStruct.Name(), file, line)
 | 
									// log.Println(funcStruct.Name(), file, line)
 | 
				
			||||||
 | 
									if !strings.Contains(funcStruct.Name(), "github.com/sirupsen/logrus.") {
 | 
				
			||||||
				skipLogrus.OpenFunc(func() bool {
 | 
										skipOnce.Skip++
 | 
				
			||||||
					return strings.Contains(funcStruct.Name(), "github.com/sirupsen/logrus.")
 | 
										if skipOnce.Skip >= 2 {
 | 
				
			||||||
				}, func() {
 | 
											skipOnce.Skip = i - 3
 | 
				
			||||||
 | 
											break
 | 
				
			||||||
					// skip = i
 | 
										}
 | 
				
			||||||
					skipOnce.SkipLogrus = i
 | 
									}
 | 
				
			||||||
					i = 10000
 | 
					 | 
				
			||||||
				})
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if skipOnce.SkipBasic == 0 {
 | 
					 | 
				
			||||||
		var skipBasic OpenClose
 | 
					 | 
				
			||||||
		for i := 4; i < 50; i++ {
 | 
					 | 
				
			||||||
			// log.Println(i)
 | 
					 | 
				
			||||||
			if pc, file, line, ok := runtime.Caller(i); ok {
 | 
					 | 
				
			||||||
				funcStruct := runtime.FuncForPC(pc)
 | 
					 | 
				
			||||||
				log.Println(funcStruct.Name(), file, line)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				skipBasic.OpenFunc(func() bool {
 | 
					 | 
				
			||||||
					return strings.Contains(funcStruct.Name(), "basic.(*Response).")
 | 
					 | 
				
			||||||
				}, func() {
 | 
					 | 
				
			||||||
					skipOnce.SkipBasic = i + 1
 | 
					 | 
				
			||||||
				})
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var fileinfo string
 | 
						var fileinfo string
 | 
				
			||||||
	if pc, _, _, ok := runtime.Caller(skipOnce.SkipBasic - 1); ok {
 | 
						if _, file, line, ok := runtime.Caller(skipOnce.Skip + h.diffSkip); ok {
 | 
				
			||||||
		funcStruct := runtime.FuncForPC(pc)
 | 
							if e.Level == logrus.InfoLevel {
 | 
				
			||||||
		log.Println(funcStruct.Name())
 | 
								fileinfo = fmt.Sprintf("%s:%d", file, line)
 | 
				
			||||||
		if strings.Contains(funcStruct.Name(), "basic.(*Response).") {
 | 
							} else {
 | 
				
			||||||
			if _, file, line, ok := runtime.Caller(skipOnce.SkipBasic); ok {
 | 
								ps := strings.Split(file, "/")
 | 
				
			||||||
				if e.Level == logrus.InfoLevel {
 | 
								fileinfo = fmt.Sprintf("%s:%d", strings.Join(ps, "/"), line)
 | 
				
			||||||
					fileinfo = fmt.Sprintf("%s:%d", file, line)
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					ps := strings.Split(file, "/")
 | 
					 | 
				
			||||||
					// ps = ps[len(ps)-4:]
 | 
					 | 
				
			||||||
					fileinfo = fmt.Sprintf("%s:%d", strings.Join(ps, "/"), line)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if fileinfo != "" {
 | 
					 | 
				
			||||||
		if _, file, line, ok := runtime.Caller(skipOnce.SkipLogrus); ok {
 | 
					 | 
				
			||||||
			if e.Level == logrus.InfoLevel {
 | 
					 | 
				
			||||||
				fileinfo = fmt.Sprintf("%s:%d", file, line)
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				ps := strings.Split(file, "/")
 | 
					 | 
				
			||||||
				// ps = ps[len(ps)-4:]
 | 
					 | 
				
			||||||
				fileinfo = fmt.Sprintf("%s:%d", strings.Join(ps, "/"), line)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var Data map[string]any = make(map[string]any, 4)
 | 
						var Data map[string]any = make(map[string]any, 4)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										166
									
								
								utils/log/log.go
									
									
									
									
									
								
							
							
						
						
									
										166
									
								
								utils/log/log.go
									
									
									
									
									
								
							@ -12,31 +12,38 @@ import (
 | 
				
			|||||||
	"github.com/sirupsen/logrus"
 | 
						"github.com/sirupsen/logrus"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var l *logrus.Logger
 | 
					var dlog *logrus.Logger
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
	l = logrus.New()
 | 
						dlog = New(0)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func New(skip int) *logrus.Logger {
 | 
				
			||||||
 | 
						myl := logrus.New()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 配置 Logstash 作为输出
 | 
						// 配置 Logstash 作为输出
 | 
				
			||||||
 | 
						myl.AddHook(NewUTCTimeHook())
 | 
				
			||||||
	l.AddHook(NewUTCTimeHook())
 | 
					 | 
				
			||||||
	jf := &JSONFormatter{
 | 
						jf := &JSONFormatter{
 | 
				
			||||||
		skip: make([]*levelSkip, len(logrus.AllLevels)),
 | 
							skip:     make([]*levelSkip, len(logrus.AllLevels)),
 | 
				
			||||||
 | 
							diffSkip: skip,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := range jf.skip {
 | 
						for i := range jf.skip {
 | 
				
			||||||
		jf.skip[i] = &levelSkip{}
 | 
							jf.skip[i] = &levelSkip{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	l.Formatter = jf
 | 
						myl.Formatter = jf
 | 
				
			||||||
 | 
						myl.SetReportCaller(true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// l.AddHook(&SkipHook{})
 | 
						if dlog != nil {
 | 
				
			||||||
 | 
							myl.SetOutput(dlog.Out)
 | 
				
			||||||
	l.SetReportCaller(true)
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return myl
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SkipHook struct {
 | 
					type SkipHook struct {
 | 
				
			||||||
 | 
						autoSkip  int
 | 
				
			||||||
	Formatter func(*logrus.Hook, *logrus.Entry) error
 | 
						Formatter func(*logrus.Hook, *logrus.Entry) error
 | 
				
			||||||
	once      sync.Once
 | 
						once      sync.Once
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -45,61 +52,28 @@ func (h *SkipHook) Levels() []logrus.Level {
 | 
				
			|||||||
	return logrus.AllLevels
 | 
						return logrus.AllLevels
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// OpenClose 开闭空间
 | 
					 | 
				
			||||||
type OpenClose struct {
 | 
					 | 
				
			||||||
	Open  bool
 | 
					 | 
				
			||||||
	Close bool
 | 
					 | 
				
			||||||
	Skip  int
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (oc *OpenClose) OpenFunc(opendo func() bool, closedo func()) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if oc.Open && oc.Close {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if opendo() {
 | 
					 | 
				
			||||||
		if !oc.Open {
 | 
					 | 
				
			||||||
			oc.Open = true
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		if oc.Open && !oc.Close {
 | 
					 | 
				
			||||||
			oc.Close = true
 | 
					 | 
				
			||||||
			closedo()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (h *SkipHook) Fire(e *logrus.Entry) error {
 | 
					func (h *SkipHook) Fire(e *logrus.Entry) error {
 | 
				
			||||||
 | 
						h.once.Do(func() {
 | 
				
			||||||
	var skipLogrus, skipBasic OpenClose
 | 
							for i := 4; i < 100; i++ {
 | 
				
			||||||
	var skip int
 | 
								log.Println(i)
 | 
				
			||||||
	for i := 4; i < 25; i++ {
 | 
								if pc, file, line, ok := runtime.Caller(i); ok {
 | 
				
			||||||
		log.Println(i)
 | 
									funcStruct := runtime.FuncForPC(pc)
 | 
				
			||||||
		if pc, file, line, ok := runtime.Caller(i); ok {
 | 
									log.Println(funcStruct.Name(), file, line)
 | 
				
			||||||
			funcStruct := runtime.FuncForPC(pc)
 | 
									if !strings.Contains(funcStruct.Name(), "github.com/sirupsen/logrus.") {
 | 
				
			||||||
			log.Println(funcStruct.Name(), file, line)
 | 
										h.autoSkip++
 | 
				
			||||||
 | 
										if h.autoSkip >= 2 {
 | 
				
			||||||
			skipLogrus.OpenFunc(func() bool {
 | 
											h.autoSkip = i - 3
 | 
				
			||||||
				return strings.Contains(funcStruct.Name(), "github.com/sirupsen/logrus.")
 | 
											break
 | 
				
			||||||
			}, func() {
 | 
										}
 | 
				
			||||||
				skip = i + 1
 | 
									}
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
			})
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			skipBasic.OpenFunc(func() bool {
 | 
					 | 
				
			||||||
				return strings.Contains(funcStruct.Name(), "basic.(*Response).")
 | 
					 | 
				
			||||||
			}, func() {
 | 
					 | 
				
			||||||
				skip = i
 | 
					 | 
				
			||||||
				i = 100
 | 
					 | 
				
			||||||
			})
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						if _, file, line, ok := runtime.Caller(h.autoSkip); ok {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if _, file, line, ok := runtime.Caller(skip); ok {
 | 
					 | 
				
			||||||
		// funcStruct := runtime.FuncForPC(pc)
 | 
							// funcStruct := runtime.FuncForPC(pc)
 | 
				
			||||||
		// log.Println(file, line, funcStruct.Name())
 | 
							// log.Println(file, line, funcStruct.Name())
 | 
				
			||||||
		// funcName := funcStruct.Name()
 | 
							// funcName := funcStruct.Name()
 | 
				
			||||||
@ -131,154 +105,154 @@ func (hook *UTCTimeHook) Fire(entry *logrus.Entry) error {
 | 
				
			|||||||
// this new returned entry.
 | 
					// this new returned entry.
 | 
				
			||||||
// If you want multiple fields, use `WithFields`.
 | 
					// If you want multiple fields, use `WithFields`.
 | 
				
			||||||
func WithField(key string, value interface{}) *logrus.Entry {
 | 
					func WithField(key string, value interface{}) *logrus.Entry {
 | 
				
			||||||
	return l.WithField(key, value)
 | 
						return dlog.WithField(key, value)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Adds a struct of fields to the log entry. All it does is call `WithField` for
 | 
					// Adds a struct of fields to the log entry. All it does is call `WithField` for
 | 
				
			||||||
// each `Field`.
 | 
					// each `Field`.
 | 
				
			||||||
func WithFields(fields logrus.Fields) *logrus.Entry {
 | 
					func WithFields(fields logrus.Fields) *logrus.Entry {
 | 
				
			||||||
	return l.WithFields(fields)
 | 
						return dlog.WithFields(fields)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Add an error as single field to the log entry.  All it does is call
 | 
					// Add an error as single field to the log entry.  All it does is call
 | 
				
			||||||
// `WithError` for the given `error`.
 | 
					// `WithError` for the given `error`.
 | 
				
			||||||
func WithError(err error) *logrus.Entry {
 | 
					func WithError(err error) *logrus.Entry {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return l.WithError(err)
 | 
						return dlog.WithError(err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Add a context to the log entry.
 | 
					// Add a context to the log entry.
 | 
				
			||||||
func WithContext(ctx context.Context) *logrus.Entry {
 | 
					func WithContext(ctx context.Context) *logrus.Entry {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return l.WithContext(ctx)
 | 
						return dlog.WithContext(ctx)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Overrides the time of the log entry.
 | 
					// Overrides the time of the log entry.
 | 
				
			||||||
func WithTime(t time.Time) *logrus.Entry {
 | 
					func WithTime(t time.Time) *logrus.Entry {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return l.WithTime(t)
 | 
						return dlog.WithTime(t)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Logf(level logrus.Level, format string, args ...interface{}) {
 | 
					func Logf(level logrus.Level, format string, args ...interface{}) {
 | 
				
			||||||
	l.Logf(level, format, args...)
 | 
						dlog.Logf(level, format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Tracef(format string, args ...interface{}) {
 | 
					func Tracef(format string, args ...interface{}) {
 | 
				
			||||||
	l.Tracef(format, args...)
 | 
						dlog.Tracef(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Debugf(format string, args ...interface{}) {
 | 
					func Debugf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Debugf(format, args...)
 | 
						dlog.Debugf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Infof(format string, args ...interface{}) {
 | 
					func Infof(format string, args ...interface{}) {
 | 
				
			||||||
	l.Infof(format, args...)
 | 
						dlog.Infof(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Printf(format string, args ...interface{}) {
 | 
					func Printf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Printf(format, args...)
 | 
						dlog.Printf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warnf(format string, args ...interface{}) {
 | 
					func Warnf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Warnf(format, args...)
 | 
						dlog.Warnf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warningf(format string, args ...interface{}) {
 | 
					func Warningf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Warningf(format, args...)
 | 
						dlog.Warningf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Errorf(format string, args ...interface{}) {
 | 
					func Errorf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Errorf(format, args...)
 | 
						dlog.Errorf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Fatalf(format string, args ...interface{}) {
 | 
					func Fatalf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Fatalf(format, args...)
 | 
						dlog.Fatalf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Panicf(format string, args ...interface{}) {
 | 
					func Panicf(format string, args ...interface{}) {
 | 
				
			||||||
	l.Panicf(format, args...)
 | 
						dlog.Panicf(format, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Log(level logrus.Level, args ...interface{}) {
 | 
					func Log(level logrus.Level, args ...interface{}) {
 | 
				
			||||||
	l.Log(level, args...)
 | 
						dlog.Log(level, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Trace(args ...interface{}) {
 | 
					func Trace(args ...interface{}) {
 | 
				
			||||||
	l.Trace(args...)
 | 
						dlog.Trace(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Debug(args ...interface{}) {
 | 
					func Debug(args ...interface{}) {
 | 
				
			||||||
	l.Debug(args...)
 | 
						dlog.Debug(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Info(args ...interface{}) {
 | 
					func Info(args ...interface{}) {
 | 
				
			||||||
	l.Info(args...)
 | 
						dlog.Info(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Print(args ...interface{}) {
 | 
					func Print(args ...interface{}) {
 | 
				
			||||||
	l.Print(args...)
 | 
						dlog.Print(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warn(args ...interface{}) {
 | 
					func Warn(args ...interface{}) {
 | 
				
			||||||
	l.Warn(args...)
 | 
						dlog.Warn(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warning(args ...interface{}) {
 | 
					func Warning(args ...interface{}) {
 | 
				
			||||||
	l.Warning(args...)
 | 
						dlog.Warning(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Error(args ...interface{}) {
 | 
					func Error(args ...interface{}) {
 | 
				
			||||||
	l.Error(args...)
 | 
						dlog.Error(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Fatal(args ...interface{}) {
 | 
					func Fatal(args ...interface{}) {
 | 
				
			||||||
	l.Fatal(args...)
 | 
						dlog.Fatal(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Panic(args ...interface{}) {
 | 
					func Panic(args ...interface{}) {
 | 
				
			||||||
	l.Panic(args...)
 | 
						dlog.Panic(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Logln(level logrus.Level, args ...interface{}) {
 | 
					func Logln(level logrus.Level, args ...interface{}) {
 | 
				
			||||||
	l.Logln(level, args...)
 | 
						dlog.Logln(level, args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Traceln(args ...interface{}) {
 | 
					func Traceln(args ...interface{}) {
 | 
				
			||||||
	l.Traceln(args...)
 | 
						dlog.Traceln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Debugln(args ...interface{}) {
 | 
					func Debugln(args ...interface{}) {
 | 
				
			||||||
	l.Debugln(args...)
 | 
						dlog.Debugln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Infoln(args ...interface{}) {
 | 
					func Infoln(args ...interface{}) {
 | 
				
			||||||
	l.Infoln(args...)
 | 
						dlog.Infoln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Println(args ...interface{}) {
 | 
					func Println(args ...interface{}) {
 | 
				
			||||||
	l.Println(args...)
 | 
						dlog.Println(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warnln(args ...interface{}) {
 | 
					func Warnln(args ...interface{}) {
 | 
				
			||||||
	l.Warnln(args...)
 | 
						dlog.Warnln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Warningln(args ...interface{}) {
 | 
					func Warningln(args ...interface{}) {
 | 
				
			||||||
	l.Warningln(args...)
 | 
						dlog.Warningln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Errorln(args ...interface{}) {
 | 
					func Errorln(args ...interface{}) {
 | 
				
			||||||
	l.Errorln(args...)
 | 
						dlog.Errorln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Fatalln(args ...interface{}) {
 | 
					func Fatalln(args ...interface{}) {
 | 
				
			||||||
	l.Fatalln(args...)
 | 
						dlog.Fatalln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Panicln(args ...interface{}) {
 | 
					func Panicln(args ...interface{}) {
 | 
				
			||||||
	l.Panicln(args...)
 | 
						dlog.Panicln(args...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Exit(code int) {
 | 
					func Exit(code int) {
 | 
				
			||||||
	l.Exit(code)
 | 
						dlog.Exit(code)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@ func DebuglnTrackTime(do func(), fargs ...interface{}) {
 | 
				
			|||||||
	var out []interface{}
 | 
						var out []interface{}
 | 
				
			||||||
	out = append(out, t)
 | 
						out = append(out, t)
 | 
				
			||||||
	out = append(out, fargs...)
 | 
						out = append(out, fargs...)
 | 
				
			||||||
	l.Debugln(out...)
 | 
						dlog.Debugln(out...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func InfolnTrackTime(do func(), fargs ...interface{}) {
 | 
					func InfolnTrackTime(do func(), fargs ...interface{}) {
 | 
				
			||||||
@ -24,5 +24,5 @@ func InfolnTrackTime(do func(), fargs ...interface{}) {
 | 
				
			|||||||
	var out []interface{}
 | 
						var out []interface{}
 | 
				
			||||||
	out = append(out, t)
 | 
						out = append(out, t)
 | 
				
			||||||
	out = append(out, fargs...)
 | 
						out = append(out, fargs...)
 | 
				
			||||||
	l.Infoln(out...)
 | 
						dlog.Infoln(out...)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user