summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/main.go b/main.go
index 2ed8b93..c4bf010 100644
--- a/main.go
+++ b/main.go
@@ -33,7 +33,7 @@ type Metadata struct {
ContentType string `json:"contentType"`
}
-//go:embed post.html
+//go:embed form.html
var static embed.FS
func detectMimetype(input io.Reader) (mimeType string, fileext string, recycled io.Reader, err error) {
@@ -158,13 +158,6 @@ func (s *Server) formPost(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusFound)
}
-func (s *Server) formGet(w http.ResponseWriter, r *http.Request) {
- f, _ := static.Open("post.html")
- if _, err := io.Copy(w, f); err != nil {
- w.WriteHeader(http.StatusInternalServerError)
- }
-}
-
func (s *Server) servePosting(w http.ResponseWriter, r *http.Request, name string) {
filename := filepath.Join(s.data, name)
m, err := readMetadata(filename + MetadataExt)
@@ -240,8 +233,11 @@ func (s *Server) indexPost(w http.ResponseWriter, r *http.Request) {
func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
- w.Header().Add("content-type", "text/plain; charset=UTF-8")
- w.Write([]byte("Bin-ки и глогинки."))
+ w.Header().Add("content-type", "text/html; charset=UTF-8")
+ f, _ := static.Open("form.html")
+ if _, err := io.Copy(w, f); err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ }
} else {
s.servePosting(w, r, filepath.Base(path))
}
@@ -249,11 +245,10 @@ func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) {
func (s *Server) Post(w http.ResponseWriter, r *http.Request) {
switch r.Method {
- case http.MethodGet:
- s.formGet(w, r)
case http.MethodPost:
s.formPost(w, r)
default:
+ w.WriteHeader(http.StatusBadRequest)
}
}