github.com/lyft/flytestdlib@v0.3.12-0.20210213045714-8cdd111ecda1/cli/pflags/api/utils.go (about) 1 package api 2 3 import ( 4 "bytes" 5 "fmt" 6 "go/types" 7 "unicode" 8 ) 9 10 func camelCase(str string) string { 11 if len(str) == 0 { 12 return str 13 } 14 15 firstRune := bytes.Runes([]byte(str))[0] 16 if unicode.IsLower(firstRune) { 17 return fmt.Sprintf("%v%v", string(unicode.ToUpper(firstRune)), str[1:]) 18 } 19 20 return str 21 } 22 23 func isJSONUnmarshaler(t types.Type) bool { 24 return implementsAnyOfMethods(t, "UnmarshalJSON") 25 } 26 27 func isStringer(t types.Type) bool { 28 return implementsAnyOfMethods(t, "String") 29 } 30 31 func implementsAnyOfMethods(t types.Type, methodNames ...string) (found bool) { 32 mset := types.NewMethodSet(t) 33 for _, name := range methodNames { 34 if mset.Lookup(nil, name) != nil { 35 return true 36 } 37 } 38 39 mset = types.NewMethodSet(types.NewPointer(t)) 40 for _, name := range methodNames { 41 if mset.Lookup(nil, name) != nil { 42 return true 43 } 44 } 45 46 return false 47 }