# 第三方套件 ## Delay Queue https://pandaychen.github.io/2020/10/02/A-DELAY-QUEUE-ANALYSIS/ ## nat/http https://pandaychen.github.io/2021/10/01/GOLANG-NETHTTP-PRACTICE/ https://pandaychen.github.io/2020/10/01/GOLANG-NETHTTP-ANALYSIS/ ## nats https://github.com/nats-io/nats.go ## singleflight https://blog.wu-boy.com/2024/02/how-to-reslove-the-hotspot-invalid-using-singleflight/ ## go pool https://zhuanlan.zhihu.com/p/597231892 ## paseto https://www.youtube.com/watch?v=nBGx-q52KAY JWT進階 解決了JWT算法問題  purpose 可以選擇本地用還是(本地會越對稱加密) payload 要看purpose 本地會加密  ## fasthttp https://pandaychen.github.io/2020/10/09/GOLANG-FASTHTTP-POOL-ANALYSIS/ ## Lodash https://github.com/samber/lo  ## Singleflight https://pandaychen.github.io/2023/03/25/A-GOLANG-SINGLEFLIGHT-PRACTICE/ ## etcd  強一致性 redis會有機會丟失 ## 觀察者模式 go RxGo ## hash cost是跌帶次數 salt是隨機產生 所以假設你salt是2 cost 是10 就會跑2的十次方1024這樣 所以同一個password去hash出來會不同防止彩虹表攻擊 比較要先取出資料庫的hashpassword抓出他的cost跟salt拿去加密一開始的password 再比對   ## testify 測試用語法 必學 ## wirte  ## mockgen https://juejin.cn/post/7088905794607513608 https://www.youtube.com/watch?v=rL0aeMutoJ0 安裝教學 這邊注意要--build 給他Tag不然他不會用mod方式 還要_ import 他的package 看下面文章就明白了  https://dev.to/acetorscode/comment/1f1ma ### customer https://medium.com/modanisa-engineering/writing-a-custom-matcher-for-testing-with-gomock-d3ef5f13db82 ## snowflake https://github.com/sony/sonyflake https://github.com/bwmarrin/snowflake ## migrate https://www.youtube.com/watch?v=6_CH8Gx414A https://stackoverflow.com/questions/55779979/how-to-run-golang-migrate-with-docker-compose ## go redis https://www.liwenzhou.com/posts/Go/redis/#autoid-1-3-2 ## go-socket.io 處理socker.io https://github.com/googollee/go-socket.io ## Lumberjack ## gvm 用fish https://jdev.tw/blog/6093/wsl2-oh-my-zsh-install-and-setup (建議在wsl)(mac可以用 brew) https://github.com/moovweb/gvm 官網curl安裝 遇到ssl 問題用 -k 去信任直接無視 再用 安裝好的提示 source去啟動腳本(https://ithelp.ithome.com.tw/articles/10203477) ## hot reload https://github.com/codegangsta/gin https://www.youtube.com/watch?v=kyTnxBFYGYk 這筆gin好 air https://www.liwenzhou.com/posts/Go/live-reload-with-air/ https://github.com/cosmtrek/air ## corn linux 中的 cron 只能精确到分钟。而我们这里要讨论的 Go 实现的 cron 可以精确到秒 https://www.readfog.com/a/1637371620314157056 https://eddycjy.gitbook.io/golang/di-3-ke-gin/cron https://juejin.cn/post/7132715360293716004 ## validate https://juejin.cn/post/7136135907249225758 可以註冊   翻譯中文 http://www.findme.wang/blog/detail/id/733.html https://www.liwenzhou.com/posts/Go/validator-usages/#autoid-1-0-1 https://www.twblogs.net/a/5eeba5377301656afdda90cd   https://juejin.cn/post/7230777666127036472 驗證規則都在baked ## Goose 管理數據庫遷移 ## env ### viper(不只能讀.env) 這star比較多 https://github.com/spf13/viper  https://www.youtube.com/watch?v=r9Qvr40H4eE&list=PLujhHB_uAFJws6Vv5q1KDoaQ4YcpS9UOm&index=6 https://www.liwenzhou.com/posts/Go/zap/ 可以載入多種文件 可以支持嵌套 ### godotenv 把.env 的放到os.SetEnv Load() 會加載近來 在os.GetEnv去抓 Read() 會變成map格式 ## uuid ## aws-sdk-go https://github.com/aws/aws-sdk-go ### SES https://blog.canopas.com/sending-email-using-aws-simple-mail-service-ses-and-static-templates-with-golang-fa3b36da7230 https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/ses-example-send-email.html 注意region https://stackoverflow.com/questions/37528301/email-address-is-not-verified-aws-ses ## gorilla/websocket Upgrade的conn是指標  如果你要發送訊息怎的要用這個 所以要將他 = 到gloabl ## gorilla/mux ## twilo(短信) 電話那邊要加上+886 ## Fyne (GUI) https://www.youtube.com/watch?v=l9TGGU79Y04&list=PLujhHB_uAFJws6Vv5q1KDoaQ4YcpS9UOm&index=16 ## jwt https://www.liwenzhou.com/posts/Go/json-web-token/ https://github.com/dgrijalva/jwt-go https://www.youtube.com/watch?v=-Eei8eik1Io&list=PLujhHB_uAFJws6Vv5q1KDoaQ4YcpS9UOm&index=7 https://blog.kennycoder.io/2020/01/05/Golang-JSON-Web-Tokens-JWT-%E7%A4%BA%E7%AF%84/  ## errGroup https://kennychen-blog.herokuapp.com/2021/10/03/Golang-errGroup-%E7%94%A8%E6%B3%95%E5%8F%8A%E9%81%A9%E7%94%A8%E6%83%85%E5%A2%83/ https://blog.kennycoder.io/2021/10/03/Golang-errGroup-%E7%94%A8%E6%B3%95%E5%8F%8A%E9%81%A9%E7%94%A8%E6%83%85%E5%A2%83/ 當你要的執行的任務是要做同一件事情或者是同一個性質,比如說你同時會有多個 goroutine 都要存取同一個服務獲得不同的資訊之類的,但是訪問的都是同一個 service。而當其中一個 goroutine 如果失敗了,最有可能的原因是 network issue,那麼其他 goroutine 存取同一個 service 也是無法存取成功的。再來,如果你想要的是當有一個 goroutine 失敗了,其他 goroutine 即便成功做完也沒有幫助,就很適合用 errGroup。 https://juejin.cn/post/7126565797870174222 ## go-callvies https://github.com/ofabry/go-callvis  ## logrus  ## colly (爬蟲主流) ## go query(讀取html)(爬蟲用) 它與 jQuery 非常相似 ## go-jwt https://medium.com/%E4%BC%81%E9%B5%9D%E4%B9%9F%E6%87%82%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/golang-json-web-tokens-jwt-olang-json-web-tokens-jwt-%E7%A4%BA%E7%AF%84-225b377e0f79(JSON Web Tokens(JWT)示範) ## swagger   https://www.liwenzhou.com/posts/Go/gin-swagger/ ## rabbitMQ client https://github.com/streadway/amqp 最多star 但是不維護要小心 ### sqlc ### sqlX https://www.liwenzhou.com/posts/Go/sqlx/ https://www.liwenzhou.com/posts/Go/sqlx-bulk-insert/ 注意struct型態要跟database一樣 scan一定要對應全部欄位 但stuctScan mapScan之類的都不用要對應全部的欄位 #### IN 批量插入或查詢 ## cors https://github.com/gin-contrib/cors https://www.liwenzhou.com/posts/Go/deploy/ 使用情況  ## cobra   ``` // Command代表执行命令的结构 type Command struct { // 代表当前命令的,如何执行,root 最好和生成的命令工具名称一致 Use string // 代表这个工具的别名,在 subCommand 中有用,比如 root cmd1 和 root cmd_1 想要都执行一个 subCommand 就需要这样 Aliases []string // 由于不强制设置,用于输入错误的时候建议字段 SuggestFor []string // 这个就是在 help 的时候一句话描述这个命令的功能 Short string // 详细描述这个命令的功能 Long string // 例子,调用示例 Example string // 参数白名单(非 flag),只允许传这里定制的参数 // 此处的参数被被自动补全 ValidArgs []string // 参数验证器(可设置不接受参数,或者最多、最少参数) Args PositionalArgs // 参数别名 ArgAliases []string // 自动补全的命令设置,只能在 root 命令设置 BashCompletionFunction string // 如果这个命令已经废弃了,那么就这里写上废弃信息 Deprecated string // 如果这个命令要被隐藏,设置这个字段 Hidden bool // 设置命令分组注释 Annotations map[string]string // 设置命令的版本 Version string // The *Run 函数运行顺序: // * PersistentPreRun() // * PreRun() // * Run() // * PostRun() // * PersistentPostRun() // 会被子命令继承的前置 Run PersistentPreRun func(cmd *Command, args []string) // 会被子命令继承的前置 Run, 带 error PersistentPreRunE func(cmd *Command, args []string) error // 当前这个命令的前置 Run PreRun func(cmd *Command, args []string) // 当前这个命令的前置 Run,带 Error PreRunE func(cmd *Command, args []string) error // zh: 实际跑的时候运行的函数 Run func(cmd *Command, args []string) // zh: Run 执行错误了之后 RunE func(cmd *Command, args []string) error // 后置运行 PostRun func(cmd *Command, args []string) // 后置运行,带 error PostRunE func(cmd *Command, args []string) error // 会被子命令继承的后置运行 PersistentPostRun func(cmd *Command, args []string) // 会被子命令继承的后置运行,带 error PersistentPostRunE func(cmd *Command, args []string) error // 是否要打印错误信息 SilenceErrors bool // 是否关闭使用建议(当命令不存在,或参数有误时) SilenceUsage bool // 是否有 flag,如果这个命令没有 flag,设置为 true,那么所有的命令后面的参数都会是 arguments DisableFlagParsing bool // 生成文档时,是否打印自动生成字样: ("Auto generated by spf13/cobra...") DisableAutoGenTag bool // 是否显示[flags]字样 DisableFlagsInUseLine bool // 是否打印建议,当命令行出错时,匹配字数,然后给出建议的命令,提高用户体验 DisableSuggestions bool // 多少个字才会触发 suggest,必须大于 0 SuggestionsMinimumDistance int // 是否使用 Traverse 的方式来解析参数 TraverseChildren bool // 解析错误白名单, 比如像未知参数 FParseErrWhitelist FParseErrWhitelist } ``` ## machine(嵌入式代碼) https://www.youtube.com/watch?v=95Nz_1Qycl0&list=PLujhHB_uAFJws6Vv5q1KDoaQ4YcpS9UOm&index=14 ## structs struct to map https://github.com/fatih/structs ## go-redis ###### tags: `Go`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.