Skip to content

Commit

Permalink
[Backend] Implement Uber Fx for dependency management and codebase mo…
Browse files Browse the repository at this point in the history
…dularity

- DI like Spring Boot
  • Loading branch information
Alfex4936 committed May 9, 2024
1 parent dc3190d commit 9464f58
Show file tree
Hide file tree
Showing 87 changed files with 3,701 additions and 3,701 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dragonfly/
zincsearch/markers.json
zincsearch/Dockerfile.json
zincsearch/fly.toml
zincsearch/.dockerignore
zincsearch/.dockerignore
badwords_test.txt
3 changes: 2 additions & 1 deletion backend/benchmark/map_korea_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package benchmark

import (
"chulbong-kr/util"
"testing"

"github.com/Alfex4936/chulbong-kr/util"

"github.com/Alfex4936/tzf"
)

Expand Down
132 changes: 128 additions & 4 deletions backend/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,131 @@
package config

import "os"

var (
IS_PRODUCTION = os.Getenv("DEPLOYMENT")
import (
"encoding/base64"
"os"
"strconv"
"time"
)

type AppConfig struct {
AwsRegion string
S3BucketName string
LoginTokenCookie string
TokenExpirationTime time.Duration
IsProduction string
IsWaterURL string
IsWaterKEY string
CkURL string // to fetch new ones from external
NaverEmailVerifyURL string
ClientURL string
}

func NewAppConfig() *AppConfig {
expiration, _ := strconv.Atoi(os.Getenv("TOKEN_EXPIRATION_INTERVAL"))
return &AppConfig{
AwsRegion: os.Getenv("AWS_REGION"),
S3BucketName: os.Getenv("AWS_BUCKET_NAME"),
LoginTokenCookie: os.Getenv("TOKEN_COOKIE"),
TokenExpirationTime: time.Duration(expiration) * time.Hour,
IsProduction: os.Getenv("DEPLOYMENT"),
IsWaterURL: os.Getenv("IS_WATER_API"),
IsWaterKEY: os.Getenv("IS_WATER_API_KEY"),
CkURL: os.Getenv("CK_URL"),
NaverEmailVerifyURL: os.Getenv("NAVER_EMAIL_VERIFY_URL"),
ClientURL: os.Getenv("CLIENT_ADDR"),
}
}

type KakaoConfig struct {
KakaoAK string
KakaoStaticMap string
KakaoGeoCode string
KakaoCoord2Addr string
KakaoCoord2Region string
KakaoWeather string
KakaoAddressInfo string
}

func NewKakaoConfig() *KakaoConfig {
return &KakaoConfig{
KakaoAK: os.Getenv("KAKAO_AK"),
KakaoStaticMap: os.Getenv("KAKAO_STATIC_MAP"),
KakaoGeoCode: "https://dapi.kakao.com/v2/local/geo/address.json",
KakaoCoord2Addr: "https://dapi.kakao.com/v2/local/geo/coord2address.json",
KakaoCoord2Region: "https://dapi.kakao.com/v2/local/geo/coord2regioncode.json",
KakaoWeather: "https://map.kakao.com/api/dapi/point/weather?inputCoordSystem=WCONGNAMUL&outputCoordSystem=WCONGNAMUL&version=2&service=map.daum.net",
KakaoAddressInfo: "https://map.kakao.com/etc/areaAddressInfo.json?output=JSON&inputCoordSystem=WCONGNAMUL&outputCoordSystem=WCONGNAMUL",
}
}

type RedisConfig struct {
AllMarkersKey string
UserProfileKey string
UserFavKey string
}

func NewRedisConfig() *RedisConfig {
return &RedisConfig{
AllMarkersKey: "all_markers",
UserProfileKey: "user_profile",
UserFavKey: "user_fav",
}
}

type ZincSearchConfig struct {
ZincAPI string
ZincUser string
ZincPassword string
}

func NewZincSearchConfig() *ZincSearchConfig {
return &ZincSearchConfig{
ZincAPI: os.Getenv("ZINCSEARCH_URL"),
ZincUser: os.Getenv("ZINCSEARCH_USER"),
ZincPassword: os.Getenv("ZINCSEARCH_PASSWORD"),
}
}

type S3Config struct {
AwsRegion string
S3BucketName string
}

func NewS3Config() *S3Config {
return &S3Config{
AwsRegion: os.Getenv("AWS_REGION"),
S3BucketName: os.Getenv("AWS_BUCKET_NAME"),
}
}

type SmtpConfig struct {
SmtpServer string
SmtpPort string
SmtpUsername string
SmtpPassword string
FrontendResetRouter string
}

func NewSmtpConfig() *SmtpConfig {
return &SmtpConfig{
SmtpServer: os.Getenv("SMTP_SERVER"),
SmtpPort: os.Getenv("SMTP_PORT"),
SmtpUsername: os.Getenv("SMTP_USERNAME"),
SmtpPassword: os.Getenv("SMTP_PASSWORD"),
FrontendResetRouter: os.Getenv("FRONTEND_RESET_ROUTER"),
}
}

type TossPayConfig struct {
SecretKey string
ConfirmAPI string
PaymentAPI string
}

func NewTossPayConfig() *TossPayConfig {
return &TossPayConfig{
SecretKey: "Basic " + base64.StdEncoding.EncodeToString([]byte(os.Getenv("TOSS_SECRET_KEY_TEST")+":")),
ConfirmAPI: "https://api.tosspayments.com/v1/payments/confirm",
PaymentAPI: "https://api.tosspayments.com/v1/payments/",
}
}
20 changes: 20 additions & 0 deletions backend/configfx/fx_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package configfx

import (
"github.com/Alfex4936/chulbong-kr/config"
"go.uber.org/fx"
)

var (
FxConfigModule = fx.Module("config",
fx.Provide(
config.NewAppConfig,
config.NewKakaoConfig,
config.NewRedisConfig,
config.NewZincSearchConfig,
config.NewS3Config,
config.NewSmtpConfig,
config.NewTossPayConfig,
),
)
)
39 changes: 0 additions & 39 deletions backend/database/mysql_connector.go

This file was deleted.

80 changes: 80 additions & 0 deletions backend/di/fx_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package servicefx

import (
"github.com/Alfex4936/chulbong-kr/facade"
"github.com/Alfex4936/chulbong-kr/handler"
"github.com/Alfex4936/chulbong-kr/service"
"github.com/Alfex4936/chulbong-kr/util"
"go.uber.org/fx"
)

var (
FxAPIModule = fx.Module("api",
fx.Provide(
handler.NewMarkerHandler,
handler.NewUserHandler,
handler.NewSearchHandler,
handler.NewNotificationHandler,
handler.NewCommentHandler,
handler.NewChatHandler,
handler.NewAuthHandler,
handler.NewAdminHandler,
),
)

FxFacadeModule = fx.Module("facade",
fx.Provide(
facade.NewMarkerFacadeService,
facade.NewUserFacadeService,
facade.NewAdminFacadeService,
),
)

FxUserModule = fx.Module("user",
fx.Provide(
service.NewAuthService,
service.NewUserService,
),
)
FxMarkerModule = fx.Module("marker",
fx.Provide(
service.NewMarkerManageService,
service.NewMarkerInteractService,
service.NewMarkerRankService,
service.NewMarkerLocationService,
service.NewMarkerFacilityService,
service.NewMarkerCommentService,
service.NewNotificationService,
service.NewReportService,
),
)

FxExternalModle = fx.Module("external",
fx.Provide(
service.NewRedisService,
service.NewS3Service,
service.NewZincSearchService,
service.NewSmtpService,
),
)

FxChatModule = fx.Module("chat",
fx.Provide(
service.NewChatService,
service.NewRoomConnectionManager,
// service.NewMqService,
// service.NewGeminiService,
),
)

FxUtilModule = fx.Module("util",
fx.Provide(
service.NewTokenService,
service.NewSchedulerService,
util.NewTokenUtil,
util.NewChatUtil,
util.NewBadWordUtil,
util.NewMapUtil,
),
)
)
Loading

0 comments on commit 9464f58

Please sign in to comment.