I'm new to golang and not sure if the question title is accurate, but I will try to add a better description for the problem.
In daos/model.go
I have a package with the following code:
type ActionType int
const (
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
}
The purpose of ActionTypeFromString
is to convert a string passed as param to an int.
In actions/model.go
I have another package:
type ActionType string
const (
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
}
}
}
Compiling the code gives the following error and I'm not understanding why, since newAction.ActionType
is a string
cannot use newAction.ActionType (type *ActionType) as type *string in argument to models.ActionTypeFromString