From 87ea785119fcffd8ded637dec2e080084ad14a4d Mon Sep 17 00:00:00 2001 From: yanweidong Date: Tue, 20 Feb 2024 14:55:45 +0800 Subject: [PATCH] fix etcd prefix --- cmd/service.go | 6 ++++++ exception/auth.go | 18 +++++++++--------- exception/db.go | 10 +++++----- exception/errors.go | 44 ++++++++++++++++++++------------------------ exception/mq.go | 12 ++++++------ 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/cmd/service.go b/cmd/service.go index aedbd13..45d08ec 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -19,6 +19,8 @@ func parseArgs(cmd string) { switch cmd { case "-v", "--v", "-version", "--version": versionCmd() + case "--json": + versionCmdJson() } os.Exit(0) @@ -28,3 +30,7 @@ func versionCmd() { fmt.Printf("[Blocks Service: %s] Version: %s \n", vars.ServiceKey, vars.VERSION) fmt.Printf("[Blocks Service: %s] Compile: %s by %s build.\n", vars.ServiceKey, vars.GO_VERSION, vars.BUILD_TIME) } + +func versionCmdJson() { + fmt.Printf("{\"version\":\"%s\",\"build_time\":\"%s\"}\n", vars.VERSION, vars.BUILD_TIME) +} diff --git a/exception/auth.go b/exception/auth.go index c81a0bc..2e0cfe9 100644 --- a/exception/auth.go +++ b/exception/auth.go @@ -2,13 +2,13 @@ package exception // jwt custom error code ,begin:200 var ( - ErrAuthPasswd = ErrorJson(201, "Password Error") - ErrAuthNotFound = ErrorJson(202, "Auth Token Not Found") - ErrAuthParseFail = ErrorJson(203, "Auth Parse Fail") - ErrAuthId = ErrorJson(204, "Auth Id Not Passed") - ErrAuthIdentity = ErrorJson(205, "Auth Identity Not Passed") - ErrAuthTokenChanged = ErrorJson(206, "Auth Token Changed") - ErrAuthIdType = ErrorJson(207, "Auth Id Type Error") - ErrAuthExpire = ErrorJson(208, "Auth Token Expire") - ErrAuthClient = ErrorJson(208, "Auth Token Client Not Passed") + ErrAuthPasswd = Errorf(201, "Password Error") + ErrAuthNotFound = Errorf(202, "Auth Token Not Found") + ErrAuthParseFail = Errorf(203, "Auth Parse Fail") + ErrAuthId = Errorf(204, "Auth Id Not Passed") + ErrAuthIdentity = Errorf(205, "Auth Identity Not Passed") + ErrAuthTokenChanged = Errorf(206, "Auth Token Changed") + ErrAuthIdType = Errorf(207, "Auth Id Type Error") + ErrAuthExpire = Errorf(208, "Auth Token Expire") + ErrAuthClient = Errorf(208, "Auth Token Client Not Passed") ) diff --git a/exception/db.go b/exception/db.go index b949eb9..f8dcaf1 100644 --- a/exception/db.go +++ b/exception/db.go @@ -2,9 +2,9 @@ package exception // db custom error code ,begin:300 var ( - ErrDBFatal = ErrorJson(300, "DB Fatal error") - ErrCacheFatal = ErrorJson(301, "Cache Fatal error") - ErrEtcdFatal = ErrorJson(302, "Etcd Fatal error") - ErrElasticFatal = ErrorJson(303, "Elastic Fatal error") - ErrBlocksMQFatal = ErrorJson(304, "BlocksMQ Fatal error") + ErrDBFatal = Errorf(300, "DB Fatal error") + ErrCacheFatal = Errorf(301, "Cache Fatal error") + ErrEtcdFatal = Errorf(302, "Etcd Fatal error") + ErrElasticFatal = Errorf(303, "Elastic Fatal error") + ErrBlocksMQFatal = Errorf(304, "BlocksMQ Fatal error") ) diff --git a/exception/errors.go b/exception/errors.go index a73de9a..98ff4b0 100644 --- a/exception/errors.go +++ b/exception/errors.go @@ -9,27 +9,27 @@ import ( var ( // google grpc error status. - OK = ErrorJson(0, "OK") - ErrCanceled = ErrorJson(1, "Canceled") - ErrUnknown = ErrorJson(2, "Unknown") - ErrInvalidArgument = ErrorJson(3, "Invalid Argument") - ErrDeadlineExceeded = ErrorJson(4, "Deadline Exceeded") - ErrNotFound = ErrorJson(5, "Not Found") - ErrAlreadyExists = ErrorJson(6, "Already Exists") - ErrPermissionDenied = ErrorJson(7, "Permission Denied") - ErrResourceExhausted = ErrorJson(8, "Resource Exhausted") - ErrFailedPrecondition = ErrorJson(9, "Failed Precondition") - ErrAborted = ErrorJson(10, "Aborted") - ErrOutOfRange = ErrorJson(11, "Out Of Range") - ErrUnimplemented = ErrorJson(12, "Unimplemented") - ErrInternal = ErrorJson(13, "Internal") - ErrUnavailable = ErrorJson(14, "Unavailable") - ErrDataLoss = ErrorJson(15, "Data Loss") - ErrUnauthenticated = ErrorJson(16, "Unauthenticated") - ErrJSONMarshal = ErrorJson(17, "Marshal JSON") - ErrJSONUnmarshal = ErrorJson(18, "Unmarshal JSON") + OK = Errorf(0, "OK") + ErrCanceled = Errorf(1, "Canceled") + ErrUnknown = Errorf(2, "Unknown") + ErrInvalidArgument = Errorf(3, "Invalid Argument") + ErrDeadlineExceeded = Errorf(4, "Deadline Exceeded") + ErrNotFound = Errorf(5, "Not Found") + ErrAlreadyExists = Errorf(6, "Already Exists") + ErrPermissionDenied = Errorf(7, "Permission Denied") + ErrResourceExhausted = Errorf(8, "Resource Exhausted") + ErrFailedPrecondition = Errorf(9, "Failed Precondition") + ErrAborted = Errorf(10, "Aborted") + ErrOutOfRange = Errorf(11, "Out Of Range") + ErrUnimplemented = Errorf(12, "Unimplemented") + ErrInternal = Errorf(13, "Internal") + ErrUnavailable = Errorf(14, "Unavailable") + ErrDataLoss = Errorf(15, "Data Loss") + ErrUnauthenticated = Errorf(16, "Unauthenticated") + ErrJSONMarshal = Errorf(17, "Marshal JSON") + ErrJSONUnmarshal = Errorf(18, "Unmarshal JSON") - ErrSmsCode = ErrorJson(20, "SMS Code Invalid") + ErrSmsCode = Errorf(20, "SMS Code Invalid") // coustom error status ) @@ -41,7 +41,3 @@ func Error(c uint32, msg string) error { func Errorf(c uint32, format string, a ...interface{}) error { return status.New(codes.Code(c), fmt.Sprintf(format, a...)).Err() } - -func ErrorJson(c uint32, msg string) error { - return status.New(codes.Code(c), fmt.Sprintf(`{ "Code": %d, "Msg": "%s" }`, c, msg)).Err() -} diff --git a/exception/mq.go b/exception/mq.go index 76b87b3..981b2d6 100644 --- a/exception/mq.go +++ b/exception/mq.go @@ -2,10 +2,10 @@ package exception // mq custom error code ,begin:900 var ( - ErrMQClient = ErrorJson(900, "MQ Connect Error") - ErrMQDispatch = ErrorJson(901, "MQ Dispatch Error") - ErrMQProducer = ErrorJson(902, "MQ Producer Error") - ErrMQConsumer = ErrorJson(902, "MQ Consumer Error") - ErrMQInternal = ErrorJson(903, "MQ Internal Error") - ErrMQStorage = ErrorJson(904, "MQ Storage Error") + ErrMQClient = Errorf(900, "MQ Connect Error") + ErrMQDispatch = Errorf(901, "MQ Dispatch Error") + ErrMQProducer = Errorf(902, "MQ Producer Error") + ErrMQConsumer = Errorf(902, "MQ Consumer Error") + ErrMQInternal = Errorf(903, "MQ Internal Error") + ErrMQStorage = Errorf(904, "MQ Storage Error") )