1package name 2 3import ( 4 "fmt" 5 "reflect" 6) 7 8func Interface(x interface{}) (Ident, error) { 9 switch t := x.(type) { 10 case string: 11 return New(t), nil 12 default: 13 rv := reflect.Indirect(reflect.ValueOf(x)) 14 to := rv.Type() 15 if len(to.Name()) > 0 { 16 return New(to.Name()), nil 17 } 18 k := to.Kind() 19 switch k { 20 case reflect.Slice, reflect.Array: 21 e := to.Elem() 22 n := New(e.Name()) 23 return New(n.Pluralize().String()), nil 24 } 25 } 26 return New(""), fmt.Errorf("could not convert %T to Ident", x) 27} 28