Files
moxa/_test/interface11.go
2019-09-25 15:24:04 +02:00

28 lines
368 B
Go

package main
import "fmt"
type Error interface {
error
Code() string
}
type MyError Error
type T struct {
Name string
}
func (t *T) Error() string { return "err: " + t.Name }
func (t *T) Code() string { return "code: " + t.Name }
func newT(s string) MyError { return &T{s} }
func main() {
t := newT("foo")
fmt.Println(t.Code())
}
// Output:
// code: foo