Skip to content
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

WebhookServiceの構造体定義+NewServerで読み込みを行うようにした #814

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added main
Binary file not shown.
11 changes: 9 additions & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
Logger *zap.Logger
SessionName string
}
type WebHookService struct {
webhookSecret string;
webhookChannelId string;
webhookId string;

}
Comment on lines +25 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

構造体の概形はあってます 👍

ただ、フィールドが小文字始まりになってしまっているのでserviceパッケージ側からアクセスできません...
加えて、このPRではservice/webhook.goにあるWebhookEventHandlerRequestWebhookを、ただの関数から作成した構造体のメソッドに置き換えることを目標としたいです。

// before
func WebhookEventHandler(...)
func RequestWebhook(...) error

// after
func (s WebHookService) WebhookEventHandler(...)
func (s WebHookService) RequestWebhook(...) error

ので、構造体の定義はrouter側ではなくservice側に置いて欲しいです。NewWebhookServiceのような関数をservice/webhook.goに生やして、router側ではこの関数を使ってWebhookServiceを作成すると丸そうだなと思ってます。 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(あと細かいですが、WebHookではなくWebhookに揃えて欲しいです)

func NewServer(h Handlers) *echo.Echo {
e := echo.New()
e.Debug = os.Getenv("IS_DEBUG_MODE") != ""
Expand All @@ -33,11 +38,13 @@
gob.Register(User{})
gob.Register(uuid.UUID{})
gob.Register([]*model.Owner{})

retrieveGroupOwner := h.RetrieveGroupOwner()
retrieveRequestCreator := h.RetrieveRequestCreator()
retrieveFileCreator := h.RetrieveFileCreator()

setupWebhook := WebHookService{}
setupWebhook.webhookSecret = os.Getenv("WEBHOOK_SECRET")
setupWebhook.webhookChannelId = os.Getenv("WEBHOOK_CHANNEL_ID")
setupWebhook.webhookId = os.Getenv("WEBHOOK_ID")

Check warning on line 47 in router/router.go

View check run for this annotation

Codecov / codecov/patch

router/router.go#L44-L47

Added lines #L44 - L47 were not covered by tests
api := e.Group("/api")
{
apiAuth := api.Group("/auth")
Expand Down
Loading