diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c554b0b..db05536 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,7 +22,7 @@ jobs: go-version: '1.20' - name: Build - run: go build -v $PWD/cmd/api-server/api-server $PWD/cmd/api-server/main.go + run: go build -v $PWD/cmd/apiserver/apiserver $PWD/cmd/apiserver/main.go # - name: Test # run: go test -v ./... diff --git a/cmd/api-server/internal/server.go b/cmd/api-server/internal/server.go deleted file mode 100644 index c30e7d6..0000000 --- a/cmd/api-server/internal/server.go +++ /dev/null @@ -1,20 +0,0 @@ -package internal - -import "golang-with-k8s/cmd/api-server/internal/controller" - -type Server struct { - controller.AuthController - controller.CategoryController - controller.HomeController - controller.MenteeFeedbackController - controller.MentorFeedbackController - controller.MentorProfileController - controller.HashtagController - controller.ReservationController - controller.UserController - controller.SearchController -} - -func NewServer() *Server { - return &Server{} -} diff --git a/cmd/api-server/internal/controller/AuthController.go b/cmd/apiserver/controller/AuthController.go similarity index 100% rename from cmd/api-server/internal/controller/AuthController.go rename to cmd/apiserver/controller/AuthController.go diff --git a/cmd/api-server/internal/controller/CategoryController.go b/cmd/apiserver/controller/CategoryController.go similarity index 100% rename from cmd/api-server/internal/controller/CategoryController.go rename to cmd/apiserver/controller/CategoryController.go diff --git a/cmd/api-server/internal/controller/HashtagController.go b/cmd/apiserver/controller/HashtagController.go similarity index 100% rename from cmd/api-server/internal/controller/HashtagController.go rename to cmd/apiserver/controller/HashtagController.go diff --git a/cmd/api-server/internal/controller/HomeController.go b/cmd/apiserver/controller/HomeController.go similarity index 100% rename from cmd/api-server/internal/controller/HomeController.go rename to cmd/apiserver/controller/HomeController.go diff --git a/cmd/api-server/internal/controller/MenteeFeedbackController.go b/cmd/apiserver/controller/MenteeFeedbackController.go similarity index 100% rename from cmd/api-server/internal/controller/MenteeFeedbackController.go rename to cmd/apiserver/controller/MenteeFeedbackController.go diff --git a/cmd/api-server/internal/controller/MentorFeedbackController.go b/cmd/apiserver/controller/MentorFeedbackController.go similarity index 100% rename from cmd/api-server/internal/controller/MentorFeedbackController.go rename to cmd/apiserver/controller/MentorFeedbackController.go diff --git a/cmd/api-server/internal/controller/MentorProfileController.go b/cmd/apiserver/controller/MentorProfileController.go similarity index 100% rename from cmd/api-server/internal/controller/MentorProfileController.go rename to cmd/apiserver/controller/MentorProfileController.go diff --git a/cmd/api-server/internal/controller/ReservationController.go b/cmd/apiserver/controller/ReservationController.go similarity index 100% rename from cmd/api-server/internal/controller/ReservationController.go rename to cmd/apiserver/controller/ReservationController.go diff --git a/cmd/api-server/internal/controller/SearchController.go b/cmd/apiserver/controller/SearchController.go similarity index 90% rename from cmd/api-server/internal/controller/SearchController.go rename to cmd/apiserver/controller/SearchController.go index 75bc99f..a00f17a 100644 --- a/cmd/api-server/internal/controller/SearchController.go +++ b/cmd/apiserver/controller/SearchController.go @@ -1,7 +1,7 @@ package controller import ( - "golang-with-k8s/cmd/api-server/internal/service" + "golang-with-k8s/cmd/apiserver/service" "golang-with-k8s/generated/api_server" "github.com/labstack/echo/v4" diff --git a/cmd/api-server/internal/controller/UserController.go b/cmd/apiserver/controller/UserController.go similarity index 97% rename from cmd/api-server/internal/controller/UserController.go rename to cmd/apiserver/controller/UserController.go index 293f407..78f8421 100644 --- a/cmd/api-server/internal/controller/UserController.go +++ b/cmd/apiserver/controller/UserController.go @@ -1,7 +1,7 @@ package controller import ( - "golang-with-k8s/cmd/api-server/internal/service" + "golang-with-k8s/cmd/apiserver/service" "golang-with-k8s/generated/api_server" _ "golang-with-k8s/pkg/database" "net/http" diff --git a/cmd/api-server/internal/repository/MentorProfileRepository.go b/cmd/apiserver/repository/MentorProfileRepository.go similarity index 90% rename from cmd/api-server/internal/repository/MentorProfileRepository.go rename to cmd/apiserver/repository/MentorProfileRepository.go index a3335f1..63cc501 100644 --- a/cmd/api-server/internal/repository/MentorProfileRepository.go +++ b/cmd/apiserver/repository/MentorProfileRepository.go @@ -2,7 +2,7 @@ package repository import ( "fmt" - query "golang-with-k8s/cmd/api-server/internal/repository/internal" + "golang-with-k8s/cmd/apiserver/repository/internal" "golang-with-k8s/generated/api_server" "golang-with-k8s/pkg/database" "golang-with-k8s/pkg/models" diff --git a/cmd/api-server/internal/repository/UserRepository.go b/cmd/apiserver/repository/UserRepository.go similarity index 83% rename from cmd/api-server/internal/repository/UserRepository.go rename to cmd/apiserver/repository/UserRepository.go index c63b3d7..765b90a 100644 --- a/cmd/api-server/internal/repository/UserRepository.go +++ b/cmd/apiserver/repository/UserRepository.go @@ -2,7 +2,7 @@ package repository import ( "fmt" - query "golang-with-k8s/cmd/api-server/internal/repository/internal" + query2 "golang-with-k8s/cmd/apiserver/repository/internal" "golang-with-k8s/generated/api_server" "golang-with-k8s/pkg/database" "golang-with-k8s/pkg/models" @@ -15,7 +15,7 @@ func GetUsers(params *api_server.GetUsersParams) (*[]models.UserGet, error) { users := []models.UserGet{} - sql := query.GetUsers + sql := query2.GetUsers db := database.SqlX err := db.Select(&users, sql, strconv.Itoa(int(params.Take)), strconv.Itoa(int(params.Take)*int(params.Page))) @@ -30,7 +30,7 @@ func GetUsers(params *api_server.GetUsersParams) (*[]models.UserGet, error) { func GetUserById(id *api_server.IdPath) (*models.UserGet, error) { var user models.UserGet - sql := query.GetUserById + sql := query2.GetUserById db := database.SqlX err := db.Get(&user, sql, id) @@ -48,8 +48,8 @@ func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersId var page *api_server.Page db := database.SqlX - sql := query.GetUsersIdReservations - sql += query.GetUsersIdReservationsQuery(params.Status, params.Role) + sql := query2.GetUsersIdReservations + sql += query2.GetUsersIdReservationsQuery(params.Status, params.Role) sql += " GROUP BY r.id, mf.id, mtf.id, cr.content, cr.reservation_id, cr.created_at, cr.requested_user_id, c.id ORDER BY r.updated_at DESC LIMIT $3 OFFSET $4;" err := db.Select(&reservations, sql, pq.Array(params.Status), strconv.Itoa(int(*id)), strconv.Itoa(int(params.Take)), strconv.Itoa(int(params.Take)*int(params.Page))) @@ -61,11 +61,11 @@ func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersId var count int32 cntsql := "SELECT count(*) FROM reservations r " - cntsql += query.GetUsersIdReservationsQuery(params.Status, params.Role) + cntsql += query2.GetUsersIdReservationsQuery(params.Status, params.Role) cntsql += ";" row := db.QueryRow(cntsql, pq.Array(params.Status), strconv.Itoa(int(*id))) row.Scan(&count) - page = query.GetPageStruct(&count, ¶ms.Page, ¶ms.Take) + page = query2.GetPageStruct(&count, ¶ms.Page, ¶ms.Take) result.Content = &reservations result.Page = page return &result, nil @@ -74,7 +74,7 @@ func GetUsersIdReservations(id *api_server.IdPath, params *api_server.GetUsersId func PatchUser(id *api_server.IdPath, body *api_server.PatchUsersIdJSONRequestBody) (*models.UserGet, error) { var user models.UserGet - sql := query.PatchUser + sql := query2.PatchUser db := database.SqlX diff --git a/cmd/api-server/internal/repository/internal/mentorProfileQuery.go b/cmd/apiserver/repository/internal/mentorProfileQuery.go similarity index 100% rename from cmd/api-server/internal/repository/internal/mentorProfileQuery.go rename to cmd/apiserver/repository/internal/mentorProfileQuery.go diff --git a/cmd/api-server/internal/repository/internal/page.go b/cmd/apiserver/repository/internal/page.go similarity index 100% rename from cmd/api-server/internal/repository/internal/page.go rename to cmd/apiserver/repository/internal/page.go diff --git a/cmd/api-server/internal/repository/internal/userQuery.go b/cmd/apiserver/repository/internal/userQuery.go similarity index 100% rename from cmd/api-server/internal/repository/internal/userQuery.go rename to cmd/apiserver/repository/internal/userQuery.go diff --git a/cmd/api-server/main.go b/cmd/apiserver/server.go similarity index 66% rename from cmd/api-server/main.go rename to cmd/apiserver/server.go index 473a9d9..fe1d865 100644 --- a/cmd/api-server/main.go +++ b/cmd/apiserver/server.go @@ -1,29 +1,35 @@ -package main +package apiServer import ( - "golang-with-k8s/cmd/api-server/internal" - "golang-with-k8s/generated/api_server" - - //database 초기화 - "golang-with-k8s/pkg/config" - _ "golang-with-k8s/pkg/database" - "github.com/gorilla/sessions" "github.com/labstack/echo-contrib/echoprometheus" "github.com/labstack/echo-contrib/session" - "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + controller2 "golang-with-k8s/cmd/apiserver/controller" + "golang-with-k8s/generated/api_server" + "golang-with-k8s/pkg/config" ) -func main() { +type Server struct { + controller2.AuthController + controller2.CategoryController + controller2.HomeController + controller2.MenteeFeedbackController + controller2.MentorFeedbackController + controller2.MentorProfileController + controller2.HashtagController + controller2.ReservationController + controller2.UserController + controller2.SearchController +} + +func Start() { + server := &Server{} + api_server.ApiServerRegisterHandlers(e, server) - e := echo.New() //logger // e.Use(echomiddleware.Logger()) - server := internal.NewServer() - api_server.ApiServerRegisterHandlers(e, server) - //cors e.Use(middleware.CORSWithConfig(middleware.DefaultCORSConfig)) diff --git a/cmd/api-server/internal/service/AuthService.go b/cmd/apiserver/service/AuthService.go similarity index 100% rename from cmd/api-server/internal/service/AuthService.go rename to cmd/apiserver/service/AuthService.go diff --git a/cmd/api-server/internal/service/SearchService.go b/cmd/apiserver/service/SearchService.go similarity index 85% rename from cmd/api-server/internal/service/SearchService.go rename to cmd/apiserver/service/SearchService.go index 91199e9..b97f99b 100644 --- a/cmd/api-server/internal/service/SearchService.go +++ b/cmd/apiserver/service/SearchService.go @@ -1,7 +1,7 @@ package service import ( - "golang-with-k8s/cmd/api-server/internal/repository" + "golang-with-k8s/cmd/apiserver/repository" "golang-with-k8s/generated/api_server" "golang-with-k8s/pkg/models" ) diff --git a/cmd/api-server/internal/service/UserService.go b/cmd/apiserver/service/UserService.go similarity index 92% rename from cmd/api-server/internal/service/UserService.go rename to cmd/apiserver/service/UserService.go index 3ea6ed2..bfca5bd 100644 --- a/cmd/api-server/internal/service/UserService.go +++ b/cmd/apiserver/service/UserService.go @@ -1,7 +1,7 @@ package service import ( - "golang-with-k8s/cmd/api-server/internal/repository" + "golang-with-k8s/cmd/apiserver/repository" "golang-with-k8s/generated/api_server" "golang-with-k8s/pkg/models" ) diff --git a/cmd/mailserver/server.go b/cmd/mailserver/server.go new file mode 100644 index 0000000..b0ed773 --- /dev/null +++ b/cmd/mailserver/server.go @@ -0,0 +1,7 @@ +package mailserver + +//rabitmq + +func Start() { + +} diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..1ef9434 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,10 @@ +package main + +import ( + apiServer "golang-with-k8s/cmd/apiserver" + _ "golang-with-k8s/pkg/database" +) + +func main() { + apiServer.Start() +} diff --git a/pkg/config/config.go b/pkg/config/config.go index 90bd629..5f52d41 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -21,7 +21,7 @@ var ConfigInstance IConfig func (c *config) loadEnvfile(envfilePath *string, keys []string) { err := godotenv.Load(*envfilePath) if err != nil { - panic("Error loading .env file") + panic("Error loading .env.dev file") } for _, key := range keys { c.Env[key] = os.Getenv(key) @@ -43,13 +43,14 @@ func init() { deploy_mode := os.Getenv("ENVIROMENT") if deploy_mode == "production" { - envFilePath = ".env.prod" + envFilePath = ".env.dev.prod" } else { - envFilePath = ".env.dev" + envFilePath = ".env.dev.dev" } ConfigInstance.loadEnvfile(&envFilePath, []string{"GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET", "GOOGLE_LOGIN_CALLBACK"}) ConfigInstance.loadEnvfile(&envFilePath, []string{"FT_CLIENT_ID", "FT_CLIENT_SECRET", "FT_LOGIN_CALLBACK"}) ConfigInstance.loadEnvfile(&envFilePath, []string{"URL"}) ConfigInstance.loadEnvfile(&envFilePath, []string{"SESSION_SECRET"}) + ConfigInstance.loadEnvfile(&envFilePath, []string{"QUEUE_URI", "QUEUE_PORT", "QUEUE_USER", "QUEUE_PASSWORD", "QUEUE_NAME"}) } diff --git a/pkg/mq/rabbitmq.go b/pkg/mq/rabbitmq.go new file mode 100644 index 0000000..71893fd --- /dev/null +++ b/pkg/mq/rabbitmq.go @@ -0,0 +1 @@ +package mq diff --git a/tools/api-server/make-server.sh b/tools/api-server/make-server.sh index 4a85f34..149d568 100755 --- a/tools/api-server/make-server.sh +++ b/tools/api-server/make-server.sh @@ -2,11 +2,11 @@ # This script will create a server with the given port and run -# build go server in cmd/api-server file +# build go server in cmd/apiserver file go1.20.11 build -o $PWD/cmd/api-server/api-server $PWD/cmd/api-server/main.go -# check if api-server process is on, if on, kill process before running server +# check if apiserver process is on, if on, kill process before running server if lsof -Pi :10001 -sTCP:LISTEN -t >/dev/null ; then kill -9 $(lsof -t -i:10001)