From 63d5d0dc5950638797f2fa8130b3b3d8d04097ca Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Thu, 5 Sep 2024 17:30:59 +0200 Subject: [PATCH] Add framework core type --- framework/core.go | 18 ++++++++++++++++++ main.go | 16 +++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 framework/core.go diff --git a/framework/core.go b/framework/core.go new file mode 100644 index 0000000..dd6c45e --- /dev/null +++ b/framework/core.go @@ -0,0 +1,18 @@ +package framework + +import ( + "net/http" +) + +// Core is the core struct of the framework +type Core struct{} + +// NewCore initialize the Core. +func NewCore() *Core { + return &Core{} +} + +// ServeHTTP implements the Handler interface +func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // TODO +} diff --git a/main.go b/main.go index 66cf6ab..99ae4c8 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "html" "log" "net/http" + + "git.vinchent.xyz/vinchent/go-web/framework" ) type FooHandler struct{} @@ -14,12 +16,12 @@ func (foo FooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func main() { - var fooHandler FooHandler - http.Handle("/foo", fooHandler) + server := &http.Server{ + Addr: ":8080", + Handler: framework.NewCore(), + } - http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) - }) - - log.Fatal(http.ListenAndServe(":8080", nil)) + if err := server.ListenAndServe(); err != nil { + log.Panic(err) + } }