-
Notifications
You must be signed in to change notification settings - Fork 2
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
make shorten api #5
base: master
Are you sure you want to change the base?
Conversation
src/adapters/web/middleware.go
Outdated
@@ -12,6 +12,8 @@ func (web *Web) authenticate(h http.HandlerFunc) http.HandlerFunc { | |||
return func(w http.ResponseWriter, r *http.Request) { | |||
session, _ := web.store.Get(r, "scvl") | |||
userID, ok := session.Values["user_id"].(uint) | |||
userID = 1 | |||
ok = true |
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.
delete
src/engine/page.go
Outdated
_, err = e.sqlClient.FindUserByAPIKey(req.APIKey) | ||
if err != nil { | ||
return | ||
} |
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.
if _, err = e.sqlClient.FindUserByAPIKey(req.APIKey); err != nil {
return
}
src/engine/page.go
Outdated
err = e.sqlClient.CreatePage(page) | ||
if err != nil { | ||
return | ||
} |
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.
if err = e.sqlClient.CreatePage(page); err != nil {
return
}
src/engine/page.go
Outdated
} | ||
|
||
page = &domain.Page{ | ||
Slug: domain.GenerateSlug(5), |
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.
2箇所以上で使うんだったら定数を定義するのもあり。
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.
どの部分のことですか?
src/adapters/web/web.go
Outdated
@@ -36,6 +36,8 @@ func (web *Web) Start(port string) error { | |||
r.Handle("/", web.authenticate(web.rootHandler)).Methods(http.MethodGet) | |||
r.Handle("/logout", web.authenticate(web.logoutHandler)).Methods(http.MethodPost) | |||
r.Handle("/shorten", web.authenticate(web.shortenHandler)).Methods(http.MethodPost) | |||
r.HandleFunc("/api/shorten", web.shortenByAPIHandler).Methods(http.MethodPost) | |||
r.Handle("/api/publish", web.authenticate(web.publishAPIKeyHandler)).Methods(http.MethodPost) |
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.
path名がこれだと(keyではなく)apiをpublishすることになりそう。
あと、RestでURLを考える場合は基本的に何をするかはAction(get post put delete)で定義されているから、Path中に動詞を入れると冗長になると言われている。
例えば /api/key
とかの方がいいかも
No description provided.