github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/internal/grpc/error.go (about) 1 package grpc 2 3 import "fmt" 4 5 // GrpcServerStartError struct 6 type GrpcServerStartError struct { 7 Err error 8 } 9 10 // Error method - satisfying error interface 11 func (err *GrpcServerStartError) Error() string { 12 return fmt.Sprintf("gRPC Start Server Error | %v", err.Err) 13 } 14 15 // NewGrpcServerStartError - return a new instance of GrpcServerStartError 16 func NewGrpcServerStartError(err error) error { 17 return &GrpcServerStartError{Err: err} 18 } 19 20 // GrpcDialError struct 21 type GrpcDialError struct { 22 addr string 23 Err error 24 } 25 26 // Error method - satisfying error interface 27 func (err *GrpcDialError) Error() string { 28 return fmt.Sprintf("gRPC dial to %v Error | %v", err.addr, err.Err) 29 } 30 31 // NewGrpcDialError - return a new instance of GrpcDialError 32 func NewGrpcDialError(addr string, err error) error { 33 return &GrpcDialError{Err: err, addr: addr} 34 } 35 36 // CreateServerErr Error 37 type CreateServerErr struct { 38 Err error 39 } 40 41 // Error method - satisfying error interface 42 func (err *CreateServerErr) Error() string { 43 return fmt.Sprintf("Create a new server encounterred an error: %v", err.Err) 44 } 45 46 // NewCreateServerErr - return a new instance of CreateServerErr 47 func NewCreateServerErr(err error) error { 48 return &CreateServerErr{Err: err} 49 } 50 51 // GrpcServerNotExistError struct 52 type GrpcServerNotExistError struct { 53 name string 54 } 55 56 // Error method - satisfying error interface 57 func (err *GrpcServerNotExistError) Error() string { 58 return fmt.Sprintf("gRPC server with specified name `%v` not exist", err.name) 59 } 60 61 // NewGrpcServerNotExistError - return a new instance of GrpcServerNotExistError 62 func NewGrpcServerNotExistError(name string) error { 63 return &GrpcServerNotExistError{name: name} 64 } 65 66 // NilServiceRegistryError struct 67 type NilServiceRegistryError struct { 68 } 69 70 // Error method - satisfying error interface 71 func (err *NilServiceRegistryError) Error() string { 72 return fmt.Sprintf("Register a Nil service to gRPC server") 73 } 74 75 // NewNilServiceRegistryError - return a new instance of NilServiceRegistryError 76 func NewNilServiceRegistryError() error { 77 return &NilServiceRegistryError{} 78 }