Skip to content

Commit

Permalink
Favicon return err
Browse files Browse the repository at this point in the history
  • Loading branch information
minhnhatnoe committed Jun 26, 2023
1 parent 86e8418 commit c9764c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cmd/kjudge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ func main() {

if *faviconfile != "" {
log.Printf("Serving favicon from %s", *faviconfile)
opts = append(opts, server.Favicon(*faviconfile))
opt, err := server.Favicon(*faviconfile)
if err != nil {
panic(err)
}
opts = append(opts, opt)
} else {
log.Printf("Not serving favicon")
}
Expand Down
12 changes: 8 additions & 4 deletions server/opts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package server

import "os"
import (
"os"

"github.com/pkg/errors"
)

// Opt represents an option for the server.
type Opt func(s *Server)
Expand All @@ -13,11 +17,11 @@ func Verbose() Opt {
}

// Favicon makes the server serves given file at /favicon.ico
func Favicon(path string) Opt {
func Favicon(path string) (Opt, error) {
if _, err := os.Stat(path); err != nil {
panic(err)
return nil, errors.Wrap(err, "while searching for favicon")
}
return func(s *Server) {
s.faviconPath = path
}
}, nil
}

0 comments on commit c9764c4

Please sign in to comment.