Skip to content

Commit

Permalink
不要な関数を削除
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattuki committed May 15, 2024
1 parent aa766f0 commit 351e8eb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 26 deletions.
7 changes: 1 addition & 6 deletions handler/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ func HandleGetMe(c echo.Context) error {
return c.String(http.StatusInternalServerError, "Failed to get the session.")
}

accessToken := sess.Values["access_token"]
var me user.Me
me.MyId = sess.Values["my_id"].(string)
me.MyName = sess.Values["my_name"].(string)
me.MyIconBase64 = sess.Values["my_icon_base64"].(string)
me.IsVisitor = sess.Values["is_visitor"].(bool)

if user.IsValidToken(accessToken.(string)) {
return c.JSON(http.StatusOK, &me)
} else {
return c.JSON(http.StatusOK, &me)
}
return c.JSON(http.StatusOK, &me)
}
1 change: 1 addition & 0 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func ValidateAccessToken(next echo.HandlerFunc) echo.HandlerFunc {
log.Println(err)
return c.String(http.StatusInternalServerError, "Failed to get the session.")
}
//accessTokenが空の場合エラー発生
accessToken := sess.Values["access_token"]
myInformation := user.GetUserInformation(accessToken.(string))

Expand Down
20 changes: 0 additions & 20 deletions user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,3 @@ func GetIcon(AccessToken string) string {
base64Data := base64.StdEncoding.EncodeToString(body)
return base64Data
}

func IsValidToken(AccessToken string) bool {
req, err := http.NewRequest(http.MethodGet, "https://q.trap.jp/api/v3/users/me", nil)
if err != nil {
log.Println(err)
}
req.Header.Add("Authorization", "Bearer "+AccessToken)

resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Println(err)
}
defer resp.Body.Close()

if resp.StatusCode == 200 {
return true
} else {
return false
}
}

0 comments on commit 351e8eb

Please sign in to comment.