mirror of
https://github.com/eolinker/apinto
synced 2025-10-24 17:20:22 +08:00
修复额外参数类型错误问题
This commit is contained in:
@@ -121,17 +121,19 @@ func (r *RedisCounter) lock(cache resources.ICache, count int64) error {
|
||||
log.Errorf("decr remain error: %s,key: %s", err, r.key)
|
||||
return err
|
||||
}
|
||||
if remain > 0 {
|
||||
if remain >= 0 {
|
||||
// 剩余次数充足,直接返回
|
||||
log.DebugF("lock now: %s,key: %s,remain: %d,count: %d", time.Now().Format("2006-01-02 15:04:05"), r.key, remain, count)
|
||||
return nil
|
||||
}
|
||||
// 回滚已经扣的次数
|
||||
cache.IncrBy(r.ctx, r.remainKey, count, -1).Result()
|
||||
|
||||
if time.Now().Sub(r.resetTime) < 15*time.Second {
|
||||
// 重置时间未到,直接将次数回滚
|
||||
cache.IncrBy(r.ctx, r.remainKey, count, -1).Result()
|
||||
return fmt.Errorf("no enough, key:%s, remain:%d, count:%d", r.key, remain+count, count)
|
||||
}
|
||||
|
||||
r.resetTime = time.Now()
|
||||
err = r.acquireLock(cache)
|
||||
if err != nil {
|
||||
@@ -139,6 +141,7 @@ func (r *RedisCounter) lock(cache resources.ICache, count int64) error {
|
||||
log.Errorf("acquire lock error: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 释放分布锁
|
||||
defer r.releaseLock(cache)
|
||||
// 重新尝试扣减
|
||||
@@ -147,8 +150,8 @@ func (r *RedisCounter) lock(cache resources.ICache, count int64) error {
|
||||
log.Errorf("lock decr remain error: %s,key: %s", err, r.key)
|
||||
return err
|
||||
}
|
||||
if remain > 0 {
|
||||
// 当次数大于0,此时已经有节点同步过剩余次数,直接返回
|
||||
if remain >= 0 {
|
||||
// 当次数大于等于0,此时已经有节点同步过剩余次数,直接返回
|
||||
log.DebugF("lock now: %s,key: %s,remain: %d,count: %d", time.Now().Format("2006-01-02 15:04:05"), r.key, remain, count)
|
||||
return nil
|
||||
}
|
||||
@@ -162,8 +165,17 @@ func (r *RedisCounter) lock(cache resources.ICache, count int64) error {
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return cache.Set(r.ctx, r.remainKey, []byte(strconv.FormatInt(remain, 10)), -1).Result()
|
||||
if err != nil {
|
||||
// 获取次数失败,回滚次数
|
||||
cache.IncrBy(r.ctx, r.remainKey, count, -1).Result()
|
||||
//return fmt.Errorf("no enough, key:%s, remain:%d, count:%d", r.key, remain+count, count)
|
||||
return err
|
||||
}
|
||||
err = cache.Set(r.ctx, r.remainKey, []byte(strconv.FormatInt(remain, 10)), -1).Result()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RedisCounter) rollback(cache resources.ICache, count int64) error {
|
||||
|
||||
@@ -99,7 +99,10 @@ func addParamToBody(ctx http_service.IHttpContext, contentType string, params []
|
||||
}
|
||||
}
|
||||
|
||||
b, _ := oj.Marshal(bodyParam)
|
||||
b, err := oj.Marshal(bodyParam)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctx.Proxy().Body().SetRaw(contentType, b)
|
||||
return bodyParam, nil
|
||||
} else if contentType == "application/x-www-form-urlencoded" || contentType == "multipart/form-data" {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -167,4 +167,4 @@ require (
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
//replace github.com/eolinker/eosc => ../eosc
|
||||
replace github.com/eolinker/eosc => ../eosc
|
||||
|
||||
@@ -106,7 +106,7 @@ func (r *Request) RealIP() string {
|
||||
}
|
||||
|
||||
func (r *Request) ForwardIP() string {
|
||||
return strings.Join(r.headers.Get("x-forwarded-for"), ";")
|
||||
return strings.Join(r.headers.Get("x-forwarded-for"), ", ")
|
||||
}
|
||||
|
||||
func (r *Request) Message(msgDesc *desc.MessageDescriptor) *dynamic.Message {
|
||||
|
||||
@@ -212,16 +212,19 @@ func (b *BodyRequestHandler) resetFile() error {
|
||||
body := new(bytes.Buffer)
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
for name, fs := range multipartForm.File {
|
||||
for _, fs := range multipartForm.File {
|
||||
for _, f := range fs {
|
||||
fio, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
part, err := writer.CreateFormFile(name, f.Filename)
|
||||
//part, err := writer.CreateFormFile(name, f.Filename)
|
||||
//if err != nil {
|
||||
// fio.Close()
|
||||
// return err
|
||||
//}
|
||||
part, err := writer.CreatePart(f.Header)
|
||||
if err != nil {
|
||||
fio.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (r *ProxyRequest) reset(request *fasthttp.Request, remoteAddr string) {
|
||||
|
||||
forwardedFor := r.req.Header.PeekBytes(xforwardedforKey)
|
||||
if len(forwardedFor) > 0 {
|
||||
r.req.Header.Set("x-forwarded-for", fmt.Sprint(string(forwardedFor), ",", r.remoteAddr))
|
||||
r.req.Header.Set("x-forwarded-for", fmt.Sprint(string(forwardedFor), ", ", r.remoteAddr))
|
||||
} else {
|
||||
r.req.Header.Set("x-forwarded-for", r.remoteAddr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user