Implement simple client
This commit is contained in:
@@ -7,14 +7,14 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
port string
|
||||
Port string
|
||||
router *router.Router
|
||||
}
|
||||
|
||||
func New() *Server {
|
||||
config := config.Values()
|
||||
return &Server{
|
||||
port: ":" + strings.TrimPrefix(config.Port, ":"),
|
||||
Port: ":" + strings.TrimPrefix(config.Port, ":"),
|
||||
router: router.New(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ func (s *Server) CatchAll(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *Server) get(w http.ResponseWriter, r *http.Request) {
|
||||
config := config.Values()
|
||||
key := strings.Split(r.URL.Path, "/")[1]
|
||||
if v, err := config.DB.Get(key); err == storage.ErrNotFound {
|
||||
if value, err := config.DB.Get(key); err == storage.ErrNotFound {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
} else if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
w.Write(v)
|
||||
w.Write(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Server) Run() error {
|
||||
return http.ListenAndServe(s.port, s)
|
||||
return http.ListenAndServe(s.Port, s)
|
||||
}
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user