A self-taught frontend developer from Taiwan, Passionate about developing interesting web apps!
Go lacks enum and union keywords; utlizing existing features to achieve the same patterns. study TypeScript as example
Go 既没有 Enum(枚举)也没有 Union(联合)的关键字,因此会使用现有的语言特性来达到相同效果。参考 TypeScript,使用 Enum 组合 (const + iota) 与 Union 组合 (interface + struct)。
Go 既沒有 Enum(枚舉)也沒有 Union(聯合)的關鍵字,因此會使用現有的語言特性來達成相同的效果。藉由研究其他語言如 TypeScript 來了解如何重現相同的特性。Enum 組合 (const + iota)與Union 組合 (interface + struct)。
Go's uuid v7 uses Must: returns uuid if err is nil and panics otherwise — use when the error isn't recoverable.
最近用到 Go 官方 uuid 库产生 UUID v7 时候留意到一种使用方式是:Must,他的描述也很简单:Must returns uuid if err is nil and panics otherwise. 用途是「当错误不是一个可以恢复的选项时」,使用包装好的 `Must` 直接 panic 错误。
最近用到 Go 官方 uuid 庫產生 UUID v7 時候留意到一種使用方式是:Must,他的描述也很簡單:Must returns uuid if err is nil and panics otherwise. 用途是「當錯誤不是一個可以恢復的選項時」,使用包裝好的 `Must` 直接 panic 錯誤。



