diff options
| -rw-r--r-- | cmd/server/auth.go | 6 | ||||
| -rw-r--r-- | cmd/server/edit.go | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/cmd/server/auth.go b/cmd/server/auth.go index 5e2316e..635b6e2 100644 --- a/cmd/server/auth.go +++ b/cmd/server/auth.go @@ -4,10 +4,11 @@ import ( "crypto/rand" "encoding/base64" "encoding/json" + "errors" "fmt" + "io/fs" "net/http" "os" - "strings" "riedstra.dev/mitch/go-website/users" ) @@ -59,8 +60,7 @@ func (a *App) ReadAuth(fn string) error { //nolint fh, err := os.Open(fn) if err != nil { - if strings.Contains(err.Error(), "no such file") || - strings.Contains(err.Error(), "system cannot find the file specified") { + if errors.Is(err, fs.ErrNotExist) { goto write } diff --git a/cmd/server/edit.go b/cmd/server/edit.go index eb0c4cc..694028b 100644 --- a/cmd/server/edit.go +++ b/cmd/server/edit.go @@ -2,13 +2,14 @@ package main import ( "bytes" + "errors" "html" "io" + "io/fs" "log" "net/http" "os" "path/filepath" - "strings" "riedstra.dev/mitch/go-website/page" ) @@ -29,7 +30,7 @@ func (a *App) EditPage(w http.ResponseWriter, r *http.Request) { p = filepath.Clean(p) fh, err := os.Open("./" + p + page.Suffix) - if err != nil && strings.Contains(err.Error(), "no such file or directory") { + if err != nil && errors.Is(err, fs.ErrNotExist) { fh, err = os.Open("./" + page.TemplateDirectory + "/new-template" + page.Suffix) } |
