advancing
Former-commit-id: 0ea003b2683a6174d3d304e4bd32dd01540b87df
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"local/router"
|
||||
"local/rssmon3/config"
|
||||
"local/storage"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *Server) Routes() error {
|
||||
@@ -47,46 +42,11 @@ func (s *Server) error(w http.ResponseWriter, r *http.Request, err error) {
|
||||
}
|
||||
|
||||
func (s *Server) tag(w http.ResponseWriter, r *http.Request) {
|
||||
foo := s.notFound
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
foo = s.getFeedByTag
|
||||
if r.Method != "GET" {
|
||||
s.notFound(w, r)
|
||||
return
|
||||
}
|
||||
foo(w, r)
|
||||
}
|
||||
|
||||
func (s *Server) getFeedByTag(w http.ResponseWriter, r *http.Request) {
|
||||
tag := regexp.MustCompile("^.*\\/").ReplaceAllString(r.URL.Path, "")
|
||||
log.Println(tag)
|
||||
s.error(w, r, errors.New("not impl"))
|
||||
}
|
||||
|
||||
func (s *Server) auctions(w http.ResponseWriter, r *http.Request) {
|
||||
foo := http.NotFound
|
||||
r.ParseForm()
|
||||
switch strings.ToLower(r.Method) {
|
||||
case "get":
|
||||
foo = s.get
|
||||
}
|
||||
foo(w, r)
|
||||
}
|
||||
|
||||
func (s *Server) get(w http.ResponseWriter, r *http.Request) {
|
||||
db := config.Values().DB
|
||||
if len(strings.Split(r.URL.Path, "/")) < 3 {
|
||||
s.notFound(w, r)
|
||||
return
|
||||
}
|
||||
key := strings.Split(r.URL.Path, "/")[2]
|
||||
log.Println("GET", key)
|
||||
value, err := db.Get(key)
|
||||
if err == storage.ErrNotFound {
|
||||
s.notFound(w, r)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
s.error(w, r, err)
|
||||
return
|
||||
}
|
||||
io.Copy(w, bytes.NewBuffer(value))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user