Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ikenox committed Oct 14, 2018
1 parent 3c33260 commit 44d5edb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
app-*.yaml

# Test binary, build with `go test -c`
*.test
Expand Down
21 changes: 21 additions & 0 deletions src/commenting/app/app.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
application:
runtime:
api_version: go1.8
version: 1
module: commenting

threadsafe: true

handlers:
- url: /_ah/push-handlers/.*
script: main.APPLICATION
login: admin
- url: /.*
script: _go_app
secure: always

env_variables:
APP_ID:
SERVICE_ACCOUNT_PATH:
IS_PRODUCTION:
GOOGLE_APPLICATION_CREDENTIALS:
2 changes: 2 additions & 0 deletions src/notification/app/app-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ env_variables:
SERVICE_ACCOUNT_PATH: ./secrets/comment-api-dev-9162d86d5ce8.json
IS_PRODUCTION: false
GOOGLE_APPLICATION_CREDENTIALS: ./secrets/comment-api-dev-9162d86d5ce8.json
ADMIN_EMAIL: ikenox@gmail.com
SENDER_EMAIL: ikenox@gmail.com
2 changes: 2 additions & 0 deletions src/notification/app/app-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ env_variables:
SERVICE_ACCOUNT_PATH: ./secrets/ikenox-info-comment-api-75b6f4b1fb2f.json
IS_PRODUCTION: true
GOOGLE_APPLICATION_CREDENTIALS: ./secrets/ikenox-info-comment-api-75b6f4b1fb2f.json
ADMIN_EMAIL: ikenox@gmail.com
SENDER_EMAIL: ikenox@gmail.com
23 changes: 23 additions & 0 deletions src/notification/app/app.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
application:
runtime: go
api_version: go1.8
version: 1
module: notification

threadsafe: true

handlers:
- url: /_ah/push-handlers/.*
script: main.APPLICATION
login: admin
- url: /.*
script: _go_app
secure: always

env_variables:
APP_ID:
SERVICE_ACCOUNT_PATH:
IS_PRODUCTION:
GOOGLE_APPLICATION_CREDENTIALS:
ADMIN_EMAIL:
SENDER_EMAIL:
17 changes: 4 additions & 13 deletions src/notification/env/env.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
package env

import (
"google.golang.org/api/option"
"os"
"path/filepath"
"time"
)

// application globals
// アプリにとって普遍とみなせる値や関数、環境変数など?
// どこからでも使われるような値や概念はRepositoryにするよりグローバル変数にしてしまったほうが楽そう
var Namespace string
var CurrentTime func() time.Time
var IsProduction bool
var GCPCredentialOption option.ClientOption
var ProjectID string
var AdminEmail string
var SenderEmail string

func init() {
ProjectID = os.Getenv("APP_ID")

IsProduction = os.Getenv("IS_PRODUCTION") == "True"

// time
CurrentTime = time.Now
AdminEmail = os.Getenv("ADMIN_EMAIL")
SenderEmail = os.Getenv("SENDER_EMAIL")

// namespace
if ns := os.Getenv("NAMESPACE"); ns != "" {
Namespace = ns
} else {
Namespace = ""
}

path, err := filepath.Abs(os.Getenv("SERVICE_ACCOUNT_PATH"))
if err != nil {
panic(err.Error())
}
GCPCredentialOption = option.WithCredentialsFile(path)
}
10 changes: 4 additions & 6 deletions src/notification/usecase/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
"notification/env"
)

var systemAdmin = fmt.Sprintf("ikenox+%s@gmail.com", env.ProjectID)

// TODO CleanArchitectureで書き直し
// 現状だとtoo muchだけど、メールとかの送信部分はラップして共通化しておくべき
func NotifyCommentPosted(ctx context.Context, commentId int64, pageId, name, text string) {
msg := &mail.Message{
Sender: systemAdmin,
To: []string{systemAdmin},
Sender: env.SenderEmail,
To: []string{env.AdminEmail},
Subject: "コメントが投稿されました",
Body: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text),
HTMLBody: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text),
Expand All @@ -28,8 +26,8 @@ func NotifyCommentPosted(ctx context.Context, commentId int64, pageId, name, tex

func NotifyCommentDeleted(ctx context.Context, commentId int64, pageId, name, text string) {
msg := &mail.Message{
Sender: systemAdmin,
To: []string{systemAdmin},
Sender: env.SenderEmail,
To: []string{env.AdminEmail},
Subject: "コメントが削除されました",
Body: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text),
HTMLBody: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text),
Expand Down

0 comments on commit 44d5edb

Please sign in to comment.