dev mode integrated with rest

This commit is contained in:
Eugene
2017-12-22 14:16:01 -06:00
parent 7b5733e248
commit d6c4d06bd8
2 changed files with 16 additions and 12 deletions
+12 -8
View File
@@ -93,8 +93,19 @@ func (s *Server) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
return
}
user, err := GetUserInfo(r)
if err != nil {
httpError(w, r, http.StatusUnauthorized, err, "can't get user info")
return
}
comment.User.IP = strings.Split(r.RemoteAddr, ":")[0]
comment.User.Name = template.HTMLEscapeString(comment.User.Name)
comment.User.ID = template.HTMLEscapeString(user.ID)
comment.User.Name = template.HTMLEscapeString(user.Name)
comment.User.Picture = template.HTMLEscapeString(user.Picture)
comment.User.Profile = template.HTMLEscapeString(user.Profile)
comment.User.Admin = user.Admin
comment.Text = template.HTMLEscapeString(comment.Text)
log.Printf("[INFO] create comment %+v", comment)
@@ -156,13 +167,6 @@ func (s *Server) getLastComments(w http.ResponseWriter, r *http.Request) {
max = 0
}
uinfoData, err := GetUserInfo(r)
if err != nil {
http.Error(w, "login required", http.StatusUnauthorized)
return
}
log.Printf("[DEBUG] user: %+v", uinfoData)
comments, err := s.Store.Last(store.Locator{}, max)
if err != nil {
log.Printf("[WARN] can't get last comments, %s", err)
+4 -4
View File
@@ -10,13 +10,13 @@ type Comment struct {
User User `json:"user"`
Locator Locator `json:"locator"`
Score int `json:"score"`
Votes map[string]bool `json:"votes"`
Timestamp time.Time `json:"time"`
Votes map[string]bool `json:"votes,omitempty"`
Timestamp time.Time `json:"time,omitempty"`
}
// Locator keeps site and url of the post
type Locator struct {
SiteID string `json:"site"`
SiteID string `json:"site,omitempty"`
URL string `json:"url"`
}
@@ -26,7 +26,7 @@ type User struct {
ID string `json:"id"`
Picture string `json:"picture"`
Profile string `json:"profile"`
Admin bool `json:"admin"`
Admin bool `json:"admin,omitempty"`
IP string `json:"-"`
}