From f076ebaa3aec2350ca5d40cbbd55ed5d632055e8 Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Sun, 15 Sep 2024 22:39:34 +0200 Subject: [PATCH] Context: hard foo controller mapping for test purpose --- framework/core.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/framework/core.go b/framework/core.go index dd6c45e..c8934ec 100644 --- a/framework/core.go +++ b/framework/core.go @@ -1,18 +1,36 @@ package framework import ( + "log" "net/http" ) // Core is the core struct of the framework -type Core struct{} +type Core struct { + router map[string]ControllerHandler +} // NewCore initialize the Core. func NewCore() *Core { - return &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) { - // TODO + 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) }