github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/infrastructure/getTypeByString.go (about) 1 package infrastructure 2 3 import ( 4 "errors" 5 ) 6 7 var ( 8 // ErrServiceTypeNotFound occurs when unknown service type 9 // passed in GetTypeByString 10 ErrServiceTypeNotFound = errors.New("service type not found") 11 ) 12 13 // GetTypeByString returns a ServiceType associated with 14 // given typeName and nil, if type is known, otherwise 15 // instantiates a ServiceType with given typeName 16 // but returns ErrServiceTypeNotFound 17 func GetTypeByString(typeName string) (ServiceType, error) { 18 switch ServiceType(typeName) { 19 case HTTP: 20 return HTTP, nil 21 case HTTPS: 22 return HTTPS, nil 23 case TCP: 24 return TCP, nil 25 case UDP: 26 return UDP, nil 27 case Custom: 28 return Custom, nil 29 default: 30 return ServiceType(typeName), ErrServiceTypeNotFound 31 } 32 }