go-web/framework/core.go

37 lines
699 B
Go

package framework
import (
"log"
"net/http"
)
// Core is the core struct of the framework
type Core struct {
router map[string]ControllerHandler
}
// NewCore initialize the Core.
func NewCore() *Core {
return &Core{router: map[string]ControllerHandler{}}
}
// Get is a simple get router
func (c *Core) Get(url string, handler ControllerHandler) {
c.router[url] = handler
}
// ServeHTTP implements the Handler interface
func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println("Welcome to the Araneae framework")
ctx := NewContext(w, r)
// XXX: hard code foo handler for test purpose
router := c.router["foo"]
if router == nil {
return
}
_ = router(ctx)
}