Skip to content

Commit

Permalink
Issue umputun#31: Replace separate UI with the embedded HTMX based
Browse files Browse the repository at this point in the history
   - fixed linter errors
  • Loading branch information
oneils committed Oct 1, 2023
1 parent 691c776 commit 63738bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
18 changes: 9 additions & 9 deletions backend/app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s Server) Run(ctx context.Context) error {
err := httpServer.ListenAndServe()
log.Printf("[WARN] http server terminated, %s", err)

if err != http.ErrServerClosed {
if !errors.Is(err, http.ErrServerClosed) {
return errors.Wrap(err, "server failed")
}
return nil
Expand Down Expand Up @@ -195,14 +195,6 @@ func (s Server) fileServer(r chi.Router, path string, root http.FileSystem) {

path += "*"

//r.Get(path, func(w http.ResponseWriter, r *http.Request) {
// if strings.HasSuffix(r.URL.Path, "/") {
// http.NotFound(w, r)
// return
// }
// fs.ServeHTTP(w, r)
//})

r.Handle(path, http.StripPrefix("/static", fs))
}

Expand All @@ -219,6 +211,14 @@ func (nfs truncatedFileSystem) Open(path string) (http.File, error) {
}

s, err := f.Stat()
if err != nil {
closeErr := f.Close()
if closeErr != nil {
return nil, closeErr
}

return nil, err
}
if s.IsDir() {
index := filepath.Join(path, "index.html")
if _, err := nfs.fs.Open(index); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions backend/app/server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type templateData struct {
PinSize int
}

func (s Server) render(w http.ResponseWriter, status int, page string, tmplName string, data any) {
func (s Server) render(w http.ResponseWriter, status int, page, tmplName string, data any) {
ts, ok := s.TemplateCache[page]
if !ok {
err := fmt.Errorf("the template %s does not exist", page)
Expand Down Expand Up @@ -78,7 +78,7 @@ func (s Server) render(w http.ResponseWriter, status int, page string, tmplName
}

// renders the home page
func (s Server) indexCtrl(w http.ResponseWriter, r *http.Request) {
func (s Server) indexCtrl(w http.ResponseWriter, r *http.Request) { // nolint
data := templateData{
Form: createMsgForm{
Exp: 15,
Expand Down Expand Up @@ -147,9 +147,9 @@ func (s Server) generateLink(w http.ResponseWriter, r *http.Request) {
return
}

msgUrl := fmt.Sprintf("http://%s/message/%s", s.Domain, msg.Key)
msgURL := fmt.Sprintf("http://%s/message/%s", s.Domain, msg.Key)

s.render(w, http.StatusOK, "secure-link.tmpl.html", "secure-link", msgUrl)
s.render(w, http.StatusOK, "secure-link.tmpl.html", "secure-link", msgURL)
}

// renders the show decoded message page
Expand All @@ -169,7 +169,7 @@ func (s Server) showMessageView(w http.ResponseWriter, r *http.Request) {
}

// renders the about page
func (s Server) aboutView(w http.ResponseWriter, r *http.Request) {
func (s Server) aboutView(w http.ResponseWriter, r *http.Request) { // nolint
s.render(w, http.StatusOK, "about.tmpl.html", baseTmpl, nil)
}

Expand Down
3 changes: 2 additions & 1 deletion backend/app/validator/validator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package validator provides functionality for validating and sanitizing data.
package validator

import (
Expand Down Expand Up @@ -68,7 +69,7 @@ func IsNumber(value string) bool {
}

// MaxDuration validates if a duration is within the maximum allowed duration.
func MaxDuration(d time.Duration, maxDuration time.Duration) bool {
func MaxDuration(d, maxDuration time.Duration) bool {
return d <= maxDuration
}

Expand Down

0 comments on commit 63738bb

Please sign in to comment.