我是 golang 新手,不確定問題標題是否準確,但我會嘗試為問題添加更好的描述。在daos/model.go我有一個包含以下代碼的包:type ActionType intconst ( ActionTypeExecute ActionType = 0 + iota ActionTypeSelect ActionTypeInput ActionTypeClick ActionTypeWait)func ActionTypeFromString(s *string) (ActionType, error) { switch *s { case "execute": return ActionTypeExecute, nil case "select": return ActionTypeSelect, nil case "input": return ActionTypeInput, nil case "click": return ActionTypeClick, nil case "wait": return ActionTypeWait, nil } return 0, ErrInvalidActionTypeText}的目的ActionTypeFromString是將作為參數傳遞的字符串轉換為 int。在actions/model.go我有另一個包:type ActionType stringconst ( ActionTypeExecute ActionType = "execute" ActionTypeSelect ActionType = "select" ActionTypeInput ActionType = "input" ActionTypeClick ActionType = "click" ActionTypeWait ActionType = "wait")type NewAction struct { ActionType *ActionType `json:"type"`}func insertActionsFromScan(newActions []*NewAction) { for _, newAction := range newActions { actionTypeInt, err := models.ActionTypeFromString(newAction.ActionType) if err != nil { return nil, err } }}編譯代碼會出現以下錯誤,我不明白為什么,因為newAction.ActionType它是一個字符串不能在 models.ActionTypeFromString 的參數中使用 newAction.ActionType(類型 *ActionType)作為類型 *string
- 1 回答
- 0 關注
- 163 瀏覽
添加回答
舉報
0/150
提交
取消