gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/system/service/error.go (about) 1 package svc 2 3 type ErrorType int 4 5 const ( 6 // StartError is the type of error returned by the Start method of Lifecycle 7 StartError = ErrorType(iota) 8 9 // ExitError is the type of error returned by the Run method of Lifecycle 10 ExitError 11 12 // StopError is the type of error returned by the Close method of Lifecycle 13 StopError 14 15 // ServiceError is the type of system service error 16 ServiceError 17 ) 18 19 // Type method return the name of error type, If the error type is undefined, return 20 // UNKNOWN_ERROR 21 func (t ErrorType) Type() string { 22 switch t { 23 case StartError: 24 return "START_ERROR" 25 case ExitError: 26 return "EXIT_ERROR" 27 case StopError: 28 return "STOP_ERROR" 29 case ServiceError: 30 return "SERVICE_ERROR" 31 default: 32 return "UNKNOWN_ERROR" 33 } 34 } 35 36 type Error struct { 37 Type ErrorType 38 Err error 39 } 40 41 func (e Error) Error() string { 42 return e.Type.Type() + ": " + e.Err.Error() 43 }