Skip to content
This repository was archived by the owner on Aug 18, 2024. It is now read-only.

Commit 49332f4

Browse files
committed
Merge branch 'feature/monolith' into feature/staging
2 parents a47b0aa + 2d397a8 commit 49332f4

File tree

16 files changed

+294
-92
lines changed

16 files changed

+294
-92
lines changed

.env.example

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
# auth
2+
SESSION_LIFE_TIME_DAYS=90
3+
4+
# timetable
5+
COURSE_CACHE_HOURS=3
6+
7+
# donation
8+
STRIPE_KEY=***
9+
STRIPE_CHECKOUT_SUCCESS_URL=http://localhost:8080
10+
STRIPE_CHECKOUT_CANCEL_URL=http://localhost:8080
11+
112
# db
213
DB_URL=postgres://postgres:password@db:5432/twinte_db?sslmode=disable
314
TEST_DB_URL=postgres://postgres:password@db:5432/twinte_db_test?sslmode=disable
415

5-
# cookie
6-
COOKIE_SECURE=false
7-
COOKIE_SESSION_NAME=twinte_session
8-
COOKIE_OAUTH2_STATE_NAME=twinte_oauth2_state
9-
COOKIE_OAUTH2_STATE_MAX_AGE=180
10-
11-
# auth
16+
# handler
17+
ADDR=:8080
1218
AUTH_REDIRECT_URL=http://localhost:3000
13-
SESSION_LIFE_TIME_DAYS=90
1419

15-
# oauth2
1620
OAUTH2_GOOGLE_CLIENT_ID=***
1721
OAUTH2_GOOGLE_CLIENT_SECRET=***
1822
OAUTH2_GOOGLE_CALLBACK_URL=http://localhost:8080/google/callback
@@ -23,5 +27,7 @@ OAUTH2_APPLE_CLIENT_ID=***
2327
OAUTH2_APPLE_CLIENT_SECRET=***
2428
OAUTH2_APPLE_CALLBACK_URL=http://localhost:8080/apple/callback
2529

26-
# timetable
27-
COURSE_CACHE_HOURS=3
30+
COOKIE_SECURE=false
31+
COOKIE_SESSION_NAME=twinte_session
32+
COOKIE_OAUTH2_STATE_NAME=twinte_oauth2_state
33+
COOKIE_OAUTH2_STATE_MAX_AGE=180

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ migrate-create:
2828

2929
# e.g. make migrate-up db_url=${DB_URL}
3030
migrate-up:
31-
migrate -database ${db_url} -path ./db/migrations up;
31+
migrate -database ${db_url} -path ./db/migrations up
3232

3333
# e.g. make migrate-down db_url=${DB_URL}
3434
migrate-down:

appenv/appenv.go

-55
This file was deleted.

appenv/loader.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package appenv
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strconv"
7+
)
8+
9+
func loadBool(key string) bool {
10+
ret, err := strconv.ParseBool(os.Getenv(key))
11+
if err != nil {
12+
panic(fmt.Errorf("failed to load environment variable (%s) due to %w", key, err))
13+
}
14+
return ret
15+
}
16+
17+
func loadInt(key string) int {
18+
ret, err := strconv.Atoi(os.Getenv(key))
19+
if err != nil {
20+
panic(fmt.Errorf("failed to load environment variable (%s) due to %w", key, err))
21+
}
22+
return ret
23+
}
24+
25+
func loadString(key string) string {
26+
ret := os.Getenv(key)
27+
if ret == "" {
28+
panic(fmt.Errorf("failed to load environment variable (%s), please set it", key))
29+
}
30+
return ret
31+
}

appenv/variable.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package appenv
2+
3+
var (
4+
// auth
5+
SESSION_LIFE_TIME_DAYS int = loadInt("SESSION_LIFE_TIME_DAYS")
6+
7+
// timetable
8+
COURSE_CACHE_HOURS int = loadInt("COURSE_CACHE_HOURS")
9+
10+
// donation
11+
STRIPE_KEY string = loadString("STRIPE_KEY")
12+
STRIPE_CHECKOUT_SUCCESS_URL string = loadString("STRIPE_CHECKOUT_SUCCESS_URL")
13+
STRIPE_CHECKOUT_CANCEL_URL string = loadString("STRIPE_CHECKOUT_CANCEL_URL")
14+
15+
// db
16+
DB_URL string = loadString("DB_URL")
17+
TEST_DB_URL string = loadString("TEST_DB_URL")
18+
19+
// handler
20+
ADDR string = loadString("ADDR")
21+
AUTH_REDIRECT_URL string = loadString("AUTH_REDIRECT_URL")
22+
23+
OAUTH2_GOOGLE_CLIENT_ID string = loadString("OAUTH2_GOOGLE_CLIENT_ID")
24+
OAUTH2_GOOGLE_CLIENT_SECRET string = loadString("OAUTH2_GOOGLE_CLIENT_SECRET")
25+
OAUTH2_GOOGLE_CALLBACK_URL string = loadString("OAUTH2_GOOGLE_CALLBACK_URL")
26+
OAUTH2_TWITTER_CLIENT_ID string = loadString("OAUTH2_TWITTER_CLIENT_ID")
27+
OAUTH2_TWITTER_CLIENT_SECRET string = loadString("OAUTH2_TWITTER_CLIENT_SECRET")
28+
OAUTH2_TWITTER_CALLBACK_URL string = loadString("OAUTH2_TWITTER_CALLBACK_URL")
29+
OAUTH2_APPLE_CLIENT_ID string = loadString("OAUTH2_APPLE_CLIENT_ID")
30+
OAUTH2_APPLE_CLIENT_SECRET string = loadString("OAUTH2_APPLE_CLIENT_SECRET")
31+
OAUTH2_APPLE_CALLBACK_URL string = loadString("OAUTH2_APPLE_CALLBACK_URL")
32+
33+
COOKIE_SECURE bool = loadBool("COOKIE_SECURE")
34+
COOKIE_SESSION_NAME string = loadString("COOKIE_SESSION_NAME")
35+
COOKIE_OAUTH2_STATE_NAME string = loadString("COOKIE_OAUTH2_STATE_NAME")
36+
COOKIE_OAUTH2_STATE_MAX_AGE int = loadInt("COOKIE_OAUTH2_STATE_MAX_AGE")
37+
)

cmd/serve.go

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"log"
56
"net/http"
67
"time"
@@ -46,6 +47,15 @@ var serveCmd = &cobra.Command{
4647
announcementRepository := announcementrepository.New(db)
4748
announcementUsecase := announcementusecase.New(accessController, announcementFactory, announcementRepository)
4849

50+
announcements, err := announcementrepository.LoadAnnouncements()
51+
if err != nil {
52+
log.Fatalln(err)
53+
}
54+
err = announcementRepository.CreateAnnouncements(context.Background(), announcements...)
55+
if err != nil {
56+
log.Fatalln(err)
57+
}
58+
4959
var dummyDonationUseCase donationmodule.UseCase
5060
// donationFactory := donationfactory.New()
5161
// donationGateway := donationgateway.New()
@@ -55,6 +65,24 @@ var serveCmd = &cobra.Command{
5565
schoolcalendarRepository := schoolcalendarrepository.New()
5666
schoolcalendarUseCase := schoolcalendarusecase.New(accessController, schoolcalendarRepository)
5767

68+
events, err := schoolcalendarrepository.LoadEvents()
69+
if err != nil {
70+
log.Fatalln(err)
71+
}
72+
err = schoolcalendarRepository.CreateEvents(context.Background(), events...)
73+
if err != nil {
74+
log.Fatalln(err)
75+
}
76+
77+
moduleDetails, err := schoolcalendarrepository.LoadModuleDetails()
78+
if err != nil {
79+
log.Fatalln(err)
80+
}
81+
err = schoolcalendarRepository.CreateModuleDetails(context.Background(), moduleDetails...)
82+
if err != nil {
83+
log.Fatalln(err)
84+
}
85+
5886
timetableFactory := timetablefactory.New(db)
5987
timetableGateWay := timetablegateway.New("")
6088
timetableRepository := timetablerepository.New(db)

docs/README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go run . serve
2323
## Migration Tool
2424
[golang-migrate](https://github.com/golang-migrate/migrate)というツールを使用しています。
2525

26-
Makefileで定義している主なコマンドは次の通りです。詳しくは`migrate --help`からご確認下さい。
26+
Makefileで定義している主なコマンドは次の通りです。詳しくは`Makefile``migrate --help`からご確認下さい。
2727
```sh
2828
# Apply all up migrations
2929
make migrate-up db_url=${DB_URL}
@@ -51,3 +51,12 @@ go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@lat
5151
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-arm64.tar.gz | tar xvz
5252
mv ./migrate /usr/local/bin/
5353
```
54+
55+
## Environment Variables
56+
下記のコマンドを実行することで`.env`ファイルに定義されている環境変数を設定することができます。
57+
58+
```sh
59+
export $(grep -v '^#' .env | xargs)
60+
```
61+
62+
c.f. [Stack Overflow](https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-value-pairs)

go.mod

+22-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/twin-te/twinte-back
33
go 1.21
44

55
require (
6-
cloud.google.com/go v0.112.0
6+
cloud.google.com/go v0.112.1
77
github.com/bufbuild/connect-go v1.10.0
88
github.com/getkin/kin-openapi v0.123.0
9+
github.com/golang-jwt/jwt/v5 v5.2.0
910
github.com/google/uuid v1.6.0
1011
github.com/labstack/echo/v4 v4.11.4
1112
github.com/oapi-codegen/runtime v1.1.1
@@ -16,20 +17,31 @@ require (
1617
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
1718
golang.org/x/oauth2 v0.17.0
1819
golang.org/x/sync v0.6.0
20+
google.golang.org/api v0.167.0
1921
google.golang.org/protobuf v1.32.0
2022
gorm.io/driver/postgres v1.5.6
2123
gorm.io/gen v0.3.25
2224
gorm.io/gorm v1.25.7
23-
gorm.io/plugin/dbresolver v1.5.0
25+
gorm.io/plugin/dbresolver v1.5.1
2426
)
2527

2628
require (
29+
cloud.google.com/go/compute v1.24.0 // indirect
30+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
2731
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
2832
github.com/davecgh/go-spew v1.1.1 // indirect
33+
github.com/felixge/httpsnoop v1.0.4 // indirect
34+
github.com/go-logr/logr v1.4.1 // indirect
35+
github.com/go-logr/stdr v1.2.2 // indirect
2936
github.com/go-openapi/jsonpointer v0.20.2 // indirect
3037
github.com/go-openapi/swag v0.22.8 // indirect
3138
github.com/go-sql-driver/mysql v1.7.0 // indirect
39+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
40+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3241
github.com/golang/protobuf v1.5.3 // indirect
42+
github.com/google/s2a-go v0.1.7 // indirect
43+
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
44+
github.com/googleapis/gax-go/v2 v2.12.1 // indirect
3345
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3446
github.com/invopop/yaml v0.2.0 // indirect
3547
github.com/jackc/pgpassfile v1.0.0 // indirect
@@ -48,13 +60,21 @@ require (
4860
github.com/spf13/pflag v1.0.5 // indirect
4961
github.com/valyala/bytebufferpool v1.0.0 // indirect
5062
github.com/valyala/fasttemplate v1.2.2 // indirect
63+
go.opencensus.io v0.24.0 // indirect
64+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0 // indirect
65+
go.opentelemetry.io/otel v1.23.0 // indirect
66+
go.opentelemetry.io/otel/metric v1.23.0 // indirect
67+
go.opentelemetry.io/otel/trace v1.23.0 // indirect
5168
golang.org/x/crypto v0.19.0 // indirect
5269
golang.org/x/mod v0.15.0 // indirect
5370
golang.org/x/net v0.21.0 // indirect
5471
golang.org/x/sys v0.17.0 // indirect
5572
golang.org/x/text v0.14.0 // indirect
73+
golang.org/x/time v0.5.0 // indirect
5674
golang.org/x/tools v0.18.0 // indirect
5775
google.golang.org/appengine v1.6.8 // indirect
76+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
77+
google.golang.org/grpc v1.61.1 // indirect
5878
gopkg.in/yaml.v3 v3.0.1 // indirect
5979
gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c // indirect
6080
gorm.io/driver/mysql v1.5.2 // indirect

0 commit comments

Comments
 (0)