我是 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 关注
- 189 浏览
添加回答
举报
0/150
提交
取消
