-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/connect db #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/connect db #11
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e35f037
chore: ent 초기화 및 추가
pilyang a4aa541
feat: company schema file 작성
pilyang dc9bbec
chore: generate ent for company schema
pilyang e9d9bd4
feat: db 연결 코드 작성
pilyang 96c49f6
chore: company 추가 migration파일 생성
pilyang 1f58faf
chore: 마이그래이션 생성 스크립트 작성
pilyang 3787ffd
refactor: extract configuration setup
pilyang 46e1b22
refactor: db 설정 분리
pilyang d5454cc
chore: script파일 모으기~
pilyang 723a3c4
feat: soft delete mixin 추가, company에 적용
pilyang 08f309e
chore(ent): mixin추가 generate ./ent
pilyang 127460d
chore(atlas): mixin추가 후 migrations 재생성
pilyang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
|
|
||
| "github.com/joho/godotenv" | ||
| ) | ||
|
|
||
| type Config struct { | ||
| PostgresConfig | ||
| ServerConfig | ||
| } | ||
|
|
||
| type PostgresConfig struct { | ||
| Host string | ||
| Port string | ||
| User string | ||
| Password string | ||
| Db string | ||
| } | ||
|
|
||
| type ServerConfig struct { | ||
| Port string | ||
| Env string | ||
| } | ||
|
|
||
| func (cfg *PostgresConfig) ToMap() map[string]string { | ||
| return map[string]string{ | ||
| "HOST": cfg.Host, | ||
| "PORT": cfg.Port, | ||
| "USER": cfg.User, | ||
| "PASSWORD": cfg.Password, | ||
| "DB": cfg.Db, | ||
| } | ||
| } | ||
|
|
||
| func (cfg *ServerConfig) ToMap() map[string]string { | ||
| return map[string]string{ | ||
| "PORT": cfg.Port, | ||
| "ENV": cfg.Env, | ||
| } | ||
| } | ||
|
|
||
| func NewConfig() (*Config, error) { | ||
| errEnv := godotenv.Load(".env") | ||
| if errEnv != nil { | ||
| log.Print("failed to reading .env", errEnv) | ||
| } | ||
|
|
||
| postgresConf := PostgresConfig{ | ||
| Host: os.Getenv("POSTGRES_HOST"), | ||
| Port: os.Getenv("POSTGRES_PORT"), | ||
| User: os.Getenv("POSTGRES_USER"), | ||
| Password: os.Getenv("POSTGRES_PASSWORD"), | ||
| Db: os.Getenv("POSTGRES_DB"), | ||
| } | ||
|
|
||
| serverConf := ServerConfig{ | ||
| Port: os.Getenv("PORT"), | ||
| Env: os.Getenv("ENV"), | ||
| } | ||
|
|
||
| cfg := &Config{ | ||
| PostgresConfig: postgresConf, | ||
| ServerConfig: serverConf, | ||
| } | ||
|
|
||
| if err := validateEnvs(cfg); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return cfg, nil | ||
| } | ||
|
|
||
| func validateEnvs(cfg *Config) error { | ||
| missingEnvs := []string{} | ||
|
|
||
| missingEnvs = append(missingEnvs, findEmptyValueKeys(cfg.PostgresConfig.ToMap())...) | ||
| missingEnvs = append(missingEnvs, findEmptyValueKeys(cfg.ServerConfig.ToMap())...) | ||
|
|
||
| if len(missingEnvs) > 0 { | ||
| return fmt.Errorf("missing envs: %v", missingEnvs) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func findEmptyValueKeys(m map[string]string) []string { | ||
| keys := []string{} | ||
| for k, v := range m { | ||
| if v == "" { | ||
| keys = append(keys, k) | ||
| } | ||
| } | ||
| return keys | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 지금 config.go로도 괜찮은 것 같습니당
고랭 컨셉이 일단 짜고보는(?) 걸 지향하다보니
오히려 직관적이라는 생각이 드네용
config 개수가 늘어나거나(4~5개) 설정파일 뎁스가 늘어나면(config -> Aconfig -> BConfig 식으로 의존하게된다면) 그때 고민해봐도 좋을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋㅋㅋㅋ good good
.사실 만들면서 처음엔 자프링하듯이 디비랑 서버 config분리해서 만들다가 이게 맞나...? 하고 그냥 롤백하고 하나로 합쳐서 작업했슴다.
일단 그냥 만들기 말은 편한데 계속 이게 맞나 고미이 드면서 아직 어렵네용