Merge branch 'feature/220510_db_setting' into 'main'
Feature/220510 db setting # DB 세팅 및 초기화 - mysql:5.7 - docker-compose로 deploy See merge request !4
Showing
12 changed files
with
158 additions
and
0 deletions
... | @@ -276,4 +276,7 @@ dist | ... | @@ -276,4 +276,7 @@ dist |
276 | # Ignore code-workspaces | 276 | # Ignore code-workspaces |
277 | *.code-workspace | 277 | *.code-workspace |
278 | 278 | ||
279 | +# Ignore .env file | ||
280 | +.env | ||
281 | + | ||
279 | # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node,jetbrains | 282 | # End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,node,jetbrains | ... | ... |
database/Dockerfile
0 → 100644
database/deploy.sh
0 → 100755
database/docker-compose.yml
0 → 100644
database/mysql_init/.env_example
0 → 100644
database/mysql_init/create_db.sql
0 → 100644
1 | +CREATE DATABASE mamuri_db; | ||
2 | + | ||
3 | +USE mamuri_db; | ||
4 | + | ||
5 | +CREATE TABLE user | ||
6 | +( | ||
7 | + id INT AUTO_INCREMENT PRIMARY KEY, | ||
8 | + user_id INT NOT NULL | ||
9 | +); | ||
10 | + | ||
11 | +CREATE TABLE keyword | ||
12 | +( | ||
13 | + id INT AUTO_INCREMENT PRIMARY KEY, | ||
14 | + keyword VARCHAR(150) NULL | ||
15 | +); | ||
16 | + | ||
17 | +CREATE TABLE user_keyword | ||
18 | +( | ||
19 | + id INT AUTO_INCREMENT PRIMARY KEY, | ||
20 | + user_id INT NOT NULL, | ||
21 | + keyword_id INT NOT NULL, | ||
22 | + FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE, | ||
23 | + FOREIGN KEY (keyword_id) REFERENCES keyword (id) ON DELETE CASCADE | ||
24 | +); | ||
25 | + | ||
26 | +CREATE TABLE item | ||
27 | +( | ||
28 | + id INT AUTO_INCREMENT PRIMARY KEY, | ||
29 | + keyword_id INT NOT NULL, | ||
30 | + platform VARCHAR(50) NOT NULL, | ||
31 | + name VARCHAR(100) NOT NULL, | ||
32 | + price INT NOT NULL, | ||
33 | + thumbnail_url VARCHAR(255) NULL, | ||
34 | + item_url VARCHAR(255) NOT NULL, | ||
35 | + extra_info TEXT NULL, | ||
36 | + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
37 | +); | ||
38 | + | ||
39 | +CREATE TABLE item_check | ||
40 | +( | ||
41 | + id INT AUTO_INCREMENT PRIMARY KEY, | ||
42 | + item_id INT NULL, | ||
43 | + user_id INT NULL, | ||
44 | + FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE, | ||
45 | + FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE | ||
46 | +); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
database/undeploy.sh
0 → 100755
joongna/config/.env_example
0 → 100644
joongna/config/config.go
0 → 100644
1 | +package config | ||
2 | + | ||
3 | +import ( | ||
4 | + "log" | ||
5 | + | ||
6 | + "github.com/caarlos0/env/v6" | ||
7 | + "github.com/joho/godotenv" | ||
8 | +) | ||
9 | + | ||
10 | +type Config struct { | ||
11 | + Secret struct { | ||
12 | + CLIENTID string `env:"SECRET.CLIENTID"` | ||
13 | + CLIENTSECRET string `env:"SECRET.CLIENTSECRET"` | ||
14 | + } | ||
15 | +} | ||
16 | + | ||
17 | +var Cfg *Config | ||
18 | + | ||
19 | +func init() { | ||
20 | + err := godotenv.Load("./config/.env") | ||
21 | + if err != nil { | ||
22 | + log.Fatal("Load .env file failed.") | ||
23 | + } | ||
24 | + | ||
25 | + config := Config{} | ||
26 | + if err := env.Parse(&config); err != nil { | ||
27 | + log.Fatalf("%+v\n", err) | ||
28 | + } | ||
29 | + Cfg = &config | ||
30 | +} |
joongna/go.mod
0 → 100644
joongna/go.sum
0 → 100644
1 | +github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k= | ||
2 | +github.com/caarlos0/env/v6 v6.9.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= | ||
3 | +github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= | ||
4 | +github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= |
joongna/main.go
0 → 100644
1 | +package main | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "io/ioutil" | ||
6 | + "joongna/config" | ||
7 | + "log" | ||
8 | + "net/http" | ||
9 | + url2 "net/url" | ||
10 | +) | ||
11 | + | ||
12 | +func main() { | ||
13 | + keyword := "m1 pro 맥북 프로 16인치" | ||
14 | + encText := url2.QueryEscape("중고나라" + keyword) | ||
15 | + url := "https://openapi.naver.com/v1/search/cafearticle.json?query=" + encText + "&sort=sim" | ||
16 | + | ||
17 | + req, err := http.NewRequest("GET", url, nil) | ||
18 | + if err != nil { | ||
19 | + log.Fatal(err) | ||
20 | + } | ||
21 | + req.Header.Add("X-Naver-Client-Id", config.Cfg.Secret.CLIENTID) | ||
22 | + req.Header.Add("X-Naver-Client-Secret", config.Cfg.Secret.CLIENTSECRET) | ||
23 | + | ||
24 | + client := &http.Client{} | ||
25 | + resp, err := client.Do(req) | ||
26 | + if err != nil { | ||
27 | + log.Fatal(err) | ||
28 | + } | ||
29 | + defer resp.Body.Close() | ||
30 | + | ||
31 | + bytes, _ := ioutil.ReadAll(resp.Body) | ||
32 | + str := string(bytes) | ||
33 | + fmt.Println(str) | ||
34 | +} |
-
Please register or login to post a comment