rest-api/server.go

29 lines
485 B
Go
Raw Normal View History

2020-09-15 23:09:07 +02:00
package main
import (
"log"
"net/http"
)
// Server base struct
type Server struct {
port string
}
func (s *Server) serve() {
mux := http.NewServeMux()
mux.Handle("/", s.handle())
mux.Handle("/articles", getAllArticles())
log.Print("Listening on", s.port)
log.Fatal(http.ListenAndServe(s.port, mux))
}
func (s *Server) handle() http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(string("Hello World")))
}
return http.HandlerFunc(fn)
}