package main
import "fmt"
type Animal string
const (
Cat Animal = "cat"
Dog Animal = "dog"
)
func (a *Animal) Scan(src interface{}) error {
str := fmt.Sprintf("%s", src)
*a = Animal(str)
return nil
}
func main() {
var animal Animal
animal.Scan("cat")
fmt.Println(animal)
fmt.Println(animal.Scan("monkey"))
}
run:
cat
<nil>
よく忘れるので・・・