From 2a98bd10ce0449db02e0dc3dd576764bcd93505c Mon Sep 17 00:00:00 2001 From: cranemont Date: Sun, 16 Jun 2024 15:09:55 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20logger=20libs=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- {src/service => lib}/logger/logger.go | 0 main.go | 4 ++-- src/connector/factory.go | 2 +- src/connector/rabbitmq/connector.go | 6 +++--- src/connector/rabbitmq/consumer.go | 2 +- src/connector/rabbitmq/producer.go | 2 +- src/handler/errors.go | 3 +-- src/handler/interface.go | 2 +- src/handler/judge-handler.go | 2 +- src/router/router.go | 2 +- src/service/sandbox/sandbox.go | 3 +-- 12 files changed, 16 insertions(+), 16 deletions(-) rename {src/service => lib}/logger/logger.go (100%) diff --git a/.gitignore b/.gitignore index 28c913a..09e6a60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ results judger.log log -logs \ No newline at end of file +logs +.idea* +/go.work.sum diff --git a/src/service/logger/logger.go b/lib/logger/logger.go similarity index 100% rename from src/service/logger/logger.go rename to lib/logger/logger.go diff --git a/main.go b/main.go index fc2b517..e5b5f17 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/cranemont/iris/lib/logger" "net/http" "os" "strconv" @@ -17,7 +18,6 @@ import ( "github.com/cranemont/iris/src/handler" "github.com/cranemont/iris/src/router" "github.com/cranemont/iris/src/service/file" - "github.com/cranemont/iris/src/service/logger" "github.com/cranemont/iris/src/service/sandbox" "github.com/cranemont/iris/src/service/testcase" "github.com/cranemont/iris/src/utils" @@ -60,7 +60,7 @@ func main() { utils.Getenv("TESTCASE_SERVER_URL_PLACEHOLDER", ":id"), utils.Getenv("TESTCASE_SERVER_AUTH_TOKEN", "iris"), utils.Getenv("TESTCASE_SERVER_AUTH_HEADER", "Authorization"), - time.Second * time.Duration(timeout), + time.Second*time.Duration(timeout), ) } testcaseManager := testcase.NewTestcaseManager(dataSource, cache) diff --git a/src/connector/factory.go b/src/connector/factory.go index c8c0dd9..55ea99b 100644 --- a/src/connector/factory.go +++ b/src/connector/factory.go @@ -2,10 +2,10 @@ package connector import ( "fmt" + "github.com/cranemont/iris/lib/logger" "github.com/cranemont/iris/src/connector/rabbitmq" "github.com/cranemont/iris/src/router" - "github.com/cranemont/iris/src/service/logger" ) type Providers struct { diff --git a/src/connector/rabbitmq/connector.go b/src/connector/rabbitmq/connector.go index 53ab71e..3135ee5 100644 --- a/src/connector/rabbitmq/connector.go +++ b/src/connector/rabbitmq/connector.go @@ -3,10 +3,10 @@ package rabbitmq import ( "context" "fmt" + "github.com/cranemont/iris/lib/logger" "time" "github.com/cranemont/iris/src/router" - "github.com/cranemont/iris/src/service/logger" amqp "github.com/rabbitmq/amqp091-go" ) @@ -74,10 +74,10 @@ func (c *connector) handle(message amqp.Delivery, ctx context.Context) { result = router.NewResponse("", nil, fmt.Errorf("type(message property) must not be empty")).Marshal() } else if message.MessageId == "" { result = router.NewResponse("", nil, fmt.Errorf("message_id(message property) must not be empty")).Marshal() - } else { + } else { result = c.router.Route(message.Type, message.MessageId, message.Body) } - + if err := c.producer.Publish(result, ctx); err != nil { c.logger.Log(logger.ERROR, fmt.Sprintf("failed to publish result: %s: %s", string(result), err)) // nack diff --git a/src/connector/rabbitmq/consumer.go b/src/connector/rabbitmq/consumer.go index 433bc2d..4cd52ca 100644 --- a/src/connector/rabbitmq/consumer.go +++ b/src/connector/rabbitmq/consumer.go @@ -2,8 +2,8 @@ package rabbitmq import ( "fmt" + "github.com/cranemont/iris/lib/logger" - "github.com/cranemont/iris/src/service/logger" amqp "github.com/rabbitmq/amqp091-go" ) diff --git a/src/connector/rabbitmq/producer.go b/src/connector/rabbitmq/producer.go index 749fe49..1ec24a8 100644 --- a/src/connector/rabbitmq/producer.go +++ b/src/connector/rabbitmq/producer.go @@ -3,9 +3,9 @@ package rabbitmq import ( "context" "fmt" + "github.com/cranemont/iris/lib/logger" "log" - "github.com/cranemont/iris/src/service/logger" amqp "github.com/rabbitmq/amqp091-go" ) diff --git a/src/handler/errors.go b/src/handler/errors.go index 5c2027c..94d6b56 100644 --- a/src/handler/errors.go +++ b/src/handler/errors.go @@ -3,8 +3,7 @@ package handler import ( "errors" "fmt" - - "github.com/cranemont/iris/src/service/logger" + "github.com/cranemont/iris/lib/logger" ) type HandlerError struct { diff --git a/src/handler/interface.go b/src/handler/interface.go index e53c7e8..0ca1d62 100644 --- a/src/handler/interface.go +++ b/src/handler/interface.go @@ -2,8 +2,8 @@ package handler import ( "encoding/json" + "github.com/cranemont/iris/lib/logger" - "github.com/cranemont/iris/src/service/logger" "github.com/cranemont/iris/src/service/sandbox" ) diff --git a/src/handler/judge-handler.go b/src/handler/judge-handler.go index ad49fc5..73b1c63 100644 --- a/src/handler/judge-handler.go +++ b/src/handler/judge-handler.go @@ -3,6 +3,7 @@ package handler import ( "encoding/json" "fmt" + "github.com/cranemont/iris/lib/logger" "strconv" "time" @@ -10,7 +11,6 @@ import ( "github.com/cranemont/iris/src/common/result" "github.com/cranemont/iris/src/service/file" "github.com/cranemont/iris/src/service/grader" - "github.com/cranemont/iris/src/service/logger" "github.com/cranemont/iris/src/service/sandbox" "github.com/cranemont/iris/src/service/testcase" "github.com/cranemont/iris/src/utils" diff --git a/src/router/router.go b/src/router/router.go index d2aed66..86494c1 100644 --- a/src/router/router.go +++ b/src/router/router.go @@ -3,9 +3,9 @@ package router import ( "encoding/json" "fmt" + "github.com/cranemont/iris/lib/logger" "github.com/cranemont/iris/src/handler" - "github.com/cranemont/iris/src/service/logger" ) const ( diff --git a/src/service/sandbox/sandbox.go b/src/service/sandbox/sandbox.go index edbba49..43af109 100644 --- a/src/service/sandbox/sandbox.go +++ b/src/service/sandbox/sandbox.go @@ -4,11 +4,10 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/cranemont/iris/lib/logger" "os" "os/exec" "strconv" - - "github.com/cranemont/iris/src/service/logger" ) type Sandbox interface {