我正在尝试将结构字段“Category”转换为字符串,以便我可以在ConcatatenateNotification中进行串联。
有人知道如何做吗?
请参阅下面的代码片段。
//Category is enum of
//available notification types (semantic meaning of the notification)
type Category string
// Category allowed values
const (
FlowFailure Category = "flow_failure"
WriterResult Category = "writer_result"
)
//Notification is struct containing all information about notification
type Notification struct {
UserID int
Category Category
}
//ConcatenateNotification loads data from Notification struct and concatenates them into one string, "\n" delimited
func ConcatenateNotification(n Notification) (msg string) {
values := []string{}
values = append(values, "UserID: " + strconv.Itoa(n.UserID))
values = append(values, "Category: " + (n.Category)) // Anybody knows how to convert this value to string?
msg = strings.Join(values, "\n")
return msg
Qyouu
万千封印
相关分类