Created
December 24, 2020 11:58
-
-
Save rsgok/bc19df509ad9fd82f921851620cdced7 to your computer and use it in GitHub Desktop.
curry try
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package strategy | |
import "code.byted.org/gopkg/logs" | |
type Executable interface { | |
Exec() | |
} | |
type Curry struct { | |
ExecIndex int | |
ExecFuncArr []func() | |
Metadata map[string]string | |
Context map[string]interface{} | |
} | |
func NewCurry(context map[string]interface{}) *Curry { | |
return &Curry{ | |
ExecIndex: 0, | |
ExecFuncArr: make([]func(), 0), | |
Metadata: make(map[string]string), | |
Context: context, | |
} | |
} | |
func (curry *Curry) AddFunc(newFuncArr ...func()) { | |
curry.ExecFuncArr = append(curry.ExecFuncArr, newFuncArr...) | |
} | |
func (curry *Curry) Exec() { | |
defer func() { | |
err := recover() | |
if err != nil { | |
logs.Error("Exec Func Error: %+v\n", err) | |
} | |
}() | |
if curry.ExecIndex < len(curry.ExecFuncArr) { | |
// exec func | |
curry.ExecFuncArr[curry.ExecIndex]() | |
curry.ExecIndex++ | |
curry.Exec() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func QueryRecoveryStatus(c *gin.Context) { | |
defer utils.RecoverPanicGin(c) | |
partner := utils.GetRequestDefaultVal(c, "partner", "") | |
category := utils.GetRequestDefaultVal(c, "category", "") | |
partner = strings.ToLower(strings.ReplaceAll(partner, " ", "")) | |
category = strings.ToLower(strings.ReplaceAll(category, " ", "")) | |
cacheIgnore := utils.GetRequestDefaultBoolVal(c, "cache_ignore", false) | |
fuzzy := utils.GetRequestDefaultBoolVal(c, "fuzzy", false) | |
curryContext := map[string]interface{}{ | |
"partner": partner, | |
"category": category, | |
"cacheIgnore": cacheIgnore, | |
"fuzzy": fuzzy, | |
} | |
curry := strategy.NewCurry(curryContext) | |
curry.AddFunc(...) // 增加处理函数 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment