A bit of code cleanup

This commit is contained in:
Jason Streifling 2024-09-10 19:59:56 +02:00
parent 4592bdf970
commit e4624b8705
4 changed files with 14 additions and 21 deletions

View File

@ -8,9 +8,7 @@ import (
"google.golang.org/api/option" "google.golang.org/api/option"
) )
type Client struct { type Client struct{ *auth.Client }
*auth.Client
}
func NewClient(c *Config) (*Client, error) { func NewClient(c *Config) (*Client, error) {
var err error var err error

View File

@ -10,9 +10,7 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
type CookieStore struct { type CookieStore struct{ sessions.CookieStore }
sessions.CookieStore
}
func NewKey() ([]byte, error) { func NewKey() ([]byte, error) {
key := make([]byte, 32) key := make([]byte, 32)

View File

@ -29,7 +29,7 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return return
} }
type editorHTMLData struct { type htmlData struct {
Title string Title string
Description string Description string
Content string Content string
@ -37,12 +37,12 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
Tags []*b.Tag Tags []*b.Tag
Mode int Mode int
} }
var data htmlData
var data editorHTMLData
if session.Values["article"] == nil { if session.Values["article"] == nil {
data = editorHTMLData{} data = htmlData{}
} else { } else {
data = session.Values["article"].(editorHTMLData) data = session.Values["article"].(htmlData)
} }
data.Mode = EditMode data.Mode = EditMode
@ -211,11 +211,10 @@ func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerF
return return
} }
type htmlData struct { data := new(struct {
MyIDs map[int64]bool MyIDs map[int64]bool
RejectedArticles []*b.Article RejectedArticles []*b.Article
} })
data := new(htmlData)
data.RejectedArticles, err = db.GetCertainArticles(false, true) data.RejectedArticles, err = db.GetCertainArticles(false, true)
if err != nil { if err != nil {
@ -530,16 +529,14 @@ func ReviewArticleForDeletion(c *b.Config, db *b.DB, s *b.CookieStore) http.Hand
return return
} }
type htmlData struct { var err error
data := new(struct {
Title string Title string
Description string Description string
Content template.HTML Content template.HTML
Tags []*b.Tag Tags []*b.Tag
ID int64 ID int64
} })
var err error
data := new(htmlData)
data.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64) data.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil { if err != nil {

View File

@ -277,12 +277,12 @@ func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.H
return return
} }
type htmlData struct { data := new(struct {
Users map[int64]*b.User Users map[int64]*b.User
Action string Action string
} })
data := &htmlData{Action: action} data.Action = action
data.Users, err = db.GetAllUsers() data.Users, err = db.GetAllUsers()
if err != nil { if err != nil {
log.Println(err) log.Println(err)