Skip to content

Commit

Permalink
website/public: make State methods use a pointer receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jan 3, 2025
1 parent 88a09f2 commit 98b126d
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion website/public/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewChatInput(r *http.Request) ChatInput {
}
}

func (s State) GetChat(w http.ResponseWriter, r *http.Request) {
func (s *State) GetChat(w http.ResponseWriter, r *http.Request) {
input := NewChatInput(r)

err := s.Templates.Execute(w, r, input)
Expand Down
4 changes: 2 additions & 2 deletions website/public/faves.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewFavesInput(ss radio.SongStorage, rs radio.RequestStorage, r *http.Reques
}, nil
}

func (s State) GetFaves(w http.ResponseWriter, r *http.Request) {
func (s *State) GetFaves(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

input, err := NewFavesInput(
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s State) GetFaves(w http.ResponseWriter, r *http.Request) {
}
}

func (s State) PostFaves(w http.ResponseWriter, r *http.Request) {
func (s *State) PostFaves(w http.ResponseWriter, r *http.Request) {
}

type FaveDownloadEntry struct {
Expand Down
2 changes: 1 addition & 1 deletion website/public/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewHelpInput(r *http.Request) HelpInput {
}
}

func (s State) GetHelp(w http.ResponseWriter, r *http.Request) {
func (s *State) GetHelp(w http.ResponseWriter, r *http.Request) {
input := NewHelpInput(r)

err := s.Templates.Execute(w, r, input)
Expand Down
2 changes: 1 addition & 1 deletion website/public/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (HomeInput) TemplateBundle() string {
return "home"
}

func (s State) GetHome(w http.ResponseWriter, r *http.Request) {
func (s *State) GetHome(w http.ResponseWriter, r *http.Request) {
err := s.getHome(w, r)
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("")
Expand Down
4 changes: 2 additions & 2 deletions website/public/lastplayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewLastPlayedInput(s radio.SongStorageService, r *http.Request) (*LastPlaye
}, nil
}

func (s State) getLastPlayed(w http.ResponseWriter, r *http.Request) error {
func (s *State) getLastPlayed(w http.ResponseWriter, r *http.Request) error {
input, err := NewLastPlayedInput(s.Storage, r)
if err != nil {
return err
Expand All @@ -62,7 +62,7 @@ func (s State) getLastPlayed(w http.ResponseWriter, r *http.Request) error {
return s.Templates.Execute(w, r, input)
}

func (s State) GetLastPlayed(w http.ResponseWriter, r *http.Request) {
func (s *State) GetLastPlayed(w http.ResponseWriter, r *http.Request) {
err := s.getLastPlayed(w, r)
if err != nil {
s.errorHandler(w, r, err)
Expand Down
6 changes: 3 additions & 3 deletions website/public/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewNewsInput(cache *shared.NewsCache, ns radio.NewsStorageService, r *http.
}, nil
}

func (s State) GetNews(w http.ResponseWriter, r *http.Request) {
func (s *State) GetNews(w http.ResponseWriter, r *http.Request) {
input, err := NewNewsInput(s.News, s.Storage, r)
if err != nil {
s.errorHandler(w, r, err)
Expand Down Expand Up @@ -210,7 +210,7 @@ func NewNewsEntryInput(cache *shared.NewsCache, ns radio.NewsStorage, r *http.Re
}, nil
}

func (s State) GetNewsEntry(w http.ResponseWriter, r *http.Request) {
func (s *State) GetNewsEntry(w http.ResponseWriter, r *http.Request) {
input, err := NewNewsEntryInput(s.News, s.Storage.News(r.Context()), r)
if err != nil {
s.errorHandler(w, r, err)
Expand All @@ -224,7 +224,7 @@ func (s State) GetNewsEntry(w http.ResponseWriter, r *http.Request) {
}
}

func (s State) PostNewsEntry(w http.ResponseWriter, r *http.Request) {
func (s *State) PostNewsEntry(w http.ResponseWriter, r *http.Request) {
const op errors.Op = "website/public.PostNewsEntry"

comment, err := ParsePostNewsEntryForm(r)
Expand Down
4 changes: 2 additions & 2 deletions website/public/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewQueueInput(qs radio.QueueService, r *http.Request) (*QueueInput, error)
}, nil
}

func (s State) getQueue(w http.ResponseWriter, r *http.Request) error {
func (s *State) getQueue(w http.ResponseWriter, r *http.Request) error {
input, err := NewQueueInput(s.Queue, r)
if err != nil {
return err
Expand All @@ -38,7 +38,7 @@ func (s State) getQueue(w http.ResponseWriter, r *http.Request) error {
return s.Templates.Execute(w, r, input)
}

func (s State) GetQueue(w http.ResponseWriter, r *http.Request) {
func (s *State) GetQueue(w http.ResponseWriter, r *http.Request) {
err := s.getQueue(w, r)
if err != nil {
s.errorHandler(w, r, err)
Expand Down
4 changes: 2 additions & 2 deletions website/public/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func (ScheduleInput) TemplateBundle() string {
return "schedule"
}

func (s State) GetSchedule(w http.ResponseWriter, r *http.Request) {
func (s *State) GetSchedule(w http.ResponseWriter, r *http.Request) {
err := s.getSchedule(w, r)
if err != nil {
s.errorHandler(w, r, err)
return
}
}

func (s State) getSchedule(w http.ResponseWriter, r *http.Request) error {
func (s *State) getSchedule(w http.ResponseWriter, r *http.Request) error {
input, err := NewScheduleInput(s.Storage, r)
if err != nil {
s.errorHandler(w, r, err)
Expand Down
2 changes: 1 addition & 1 deletion website/public/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewSearchSharedInput(s radio.SearchService, rs radio.RequestStorage, r *htt
}, nil
}

func (s State) GetSearch(w http.ResponseWriter, r *http.Request) {
func (s *State) GetSearch(w http.ResponseWriter, r *http.Request) {
input, err := NewSearchInput(
s.Search,
s.Storage.Request(r.Context()),
Expand Down
2 changes: 1 addition & 1 deletion website/public/staff.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (StaffInput) TemplateBundle() string {
return "staff"
}

func (s State) GetStaff(w http.ResponseWriter, r *http.Request) {
func (s *State) GetStaff(w http.ResponseWriter, r *http.Request) {
input, err := NewStaffInput(s.Storage, r)
if err != nil {
s.errorHandler(w, r, err)
Expand Down
10 changes: 5 additions & 5 deletions website/public/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getIdentifier(r *http.Request) (string, bool) {
return r.RemoteAddr, false
}

func (s State) canSubmitSong(r *http.Request) (time.Duration, error) {
func (s *State) canSubmitSong(r *http.Request) (time.Duration, error) {
const op errors.Op = "website.canSubmitSong"

identifier, isUser := getIdentifier(r)
Expand All @@ -98,15 +98,15 @@ func (s State) canSubmitSong(r *http.Request) (time.Duration, error) {
return since, errors.E(op, errors.UserCooldown)
}

func (s State) GetSubmit(w http.ResponseWriter, r *http.Request) {
func (s *State) GetSubmit(w http.ResponseWriter, r *http.Request) {
err := s.getSubmit(w, r, nil)
if err != nil {
hlog.FromRequest(r).Error().Err(err).Msg("")
return
}
}

func (s State) getSubmit(w http.ResponseWriter, r *http.Request, form *SubmissionForm) error {
func (s *State) getSubmit(w http.ResponseWriter, r *http.Request, form *SubmissionForm) error {
const op errors.Op = "website.getSubmit"

ctx := r.Context()
Expand All @@ -120,7 +120,7 @@ func (s State) getSubmit(w http.ResponseWriter, r *http.Request, form *Submissio
return s.Templates.Execute(w, r, input)
}

func (s State) PostSubmit(w http.ResponseWriter, r *http.Request) {
func (s *State) PostSubmit(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

// setup response function that differs between htmx/non-htmx request
Expand Down Expand Up @@ -172,7 +172,7 @@ func (s State) PostSubmit(w http.ResponseWriter, r *http.Request) {
responseFn(back)
}

func (s State) postSubmit(w http.ResponseWriter, r *http.Request) (SubmissionForm, error) {
func (s *State) postSubmit(w http.ResponseWriter, r *http.Request) (SubmissionForm, error) {
const op errors.Op = "website.PostSubmit"

// find out if the client is allowed to upload
Expand Down

0 comments on commit 98b126d

Please sign in to comment.