This question already has an answer here:
- Converting a custom type to string in Go 4 answers
I have underlying type of string: type Capability string
.
I wanted to use it as a string inside map of strings but I am getting an error:
cannot use cap (type Capability) as type string in map index
This is my code:
package main
import (
"fmt"
)
type Capability string
var caps_list = map[string]int {
"HOME" : 1,
}
func main() {
var cap Capability // string
cap = "HOME"
fmt.Print(string(caps_list[cap]))
}
Why it doesn't accept it ? it is a string after all.
You can try my code here:
https://play.golang.org/p/r-h9Hu8_eoM
</div>