【程式語言 — Go】Retry Policy
由於Go語言本身沒有提供Enum的功能, 故我們可以使用package及type的技巧來達到類似的功能,假設今天要定義季節的enum型別, 包含了「春、夏、秋、冬」四種值的時候,可以怎麼做呢?
首先我們可以用package來框住season的範圍:
season |- season.go
然而在season.go可以定義一個字串的類型
package seasontype…
package seasontype
一般來說我們會這樣定義Struct來接收前端請求的POST Body
type UpdateReq struct { Name string `json:"name,omitempty" bson:"name,omitempty"` Enabled bool…
type UpdateReq struct { Name string `json:"name,omitempty" bson:"name,omitempty"` Enabled bool