Compare commits

..

2 Commits
master ... wip

Author SHA1 Message Date
Chris Sexton 2912909957 go: more refactoring
* rename validation => verification
* still some disconnects between the JS and abckend
2019-10-29 01:37:56 -04:00
Chris Sexton ed411d5a5c go: refactor
* Move web stuff out to respective files
* Move DB stuff to its own package
* Move user stuff to its own package
2019-10-29 01:19:38 -04:00
2 changed files with 4 additions and 19 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/rs/zerolog/log"
)
var Develop = true
var Develop = false
type RegisterResponse struct {
ID string

View File

@ -1,10 +1,8 @@
package web
import (
"mime"
"net/http"
"path"
"path/filepath"
"github.com/rs/zerolog/log"
)
@ -19,7 +17,7 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h
log.Error().Err(err).Msg("Error finding file")
w.WriteHeader(http.StatusNotFound)
}
write(w, f, p)
w.Write(f)
return
}
if web.box.HasDir(p) && web.box.Has(path.Join(p, "index.html")) {
@ -28,12 +26,12 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h
log.Error().Err(err).Msg("Error finding file")
w.WriteHeader(http.StatusNotFound)
}
write(w, f, p)
w.Write(f)
return
}
if f, err := web.box.Find(p); err != nil {
write(w, f, p)
w.Write(f)
return
}
@ -41,16 +39,3 @@ func (web *Web) indexHandler(entryPoint string) func(w http.ResponseWriter, r *h
}
return fn
}
func write(w http.ResponseWriter, f []byte, path string) {
ctype := mime.TypeByExtension(filepath.Ext(path))
log.Debug().Msgf("detected type %s for %s by extension", ctype, path)
if ctype == "" {
ctype = http.DetectContentType(f)
log.Debug().Msgf("detected type %s for %s by content", ctype, path)
}
if ctype != "" {
w.Header().Set("Content-Type", ctype)
}
w.Write(f)
}