跳转至

提高效率的工具库

  • https://github.com/huandu/xstrings
    • 强大的字符串操作扩展
  • 文档
    • https://github.com/gomutex/godocx
    • github.com/xuri/excelize
  • https://github.com/deckarep/golang-set
    • set(sorted、threadsafe)
  • https://github.com/bobg/go-generics
    • slices负索引操作
  • https://github.com/lrita/cmap
    • 线程安全map(对key加锁!!!)
  • https://github.com/samber/lo
    • go loadsh
  • https://github.com/samber/do
    • go di
  • https://github.com/samber/mo
    • FP(Function Programming) monad,参考Rust等语言,有如Option、Result等monad结构体

retry

  • github.com/avast/retry-go/v4
    uid := util.UUIDPretty()  
    err := retry.Do(  
        func() error {  
           return os.RemoveAll(userDataDir)  
        },  
        retry.Attempts(7),  
        retry.MaxJitter(10*time.Second), // 最大RandomDelay  
        retry.Delay(2*time.Second),      // 基础间隔  
        retry.MaxDelay(15*time.Second),  // 延迟上限  
        retry.DelayType(retry.CombineDelay(retry.BackOffDelay, retry.RandomDelay)),  
        retry.OnRetry(func(attempt uint, err error) {  
           config.Log.Warnf("%s: remove fetch article browser userDataDir: attempt=%d/7, path=%s: %s", uid, attempt+1, userDataDir, err.Error())  
        }),  
        retry.LastErrorOnly(true), // 只返回最后一次错误 否则是 "All attempts fail:\n\#1: err\n\#n...")  
    if err != nil {  
        config.Log.Warnf("%s: remove fetch article browser userDataDir failed after try 7 times: path=%s", uid, userDataDir)  
    }