Add framework core type
This commit is contained in:
parent
b96656a469
commit
63d5d0dc59
18
framework/core.go
Normal file
18
framework/core.go
Normal file
@ -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
|
||||||
|
}
|
16
main.go
16
main.go
@ -5,6 +5,8 @@ import (
|
|||||||
"html"
|
"html"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FooHandler struct{}
|
type FooHandler struct{}
|
||||||
@ -14,12 +16,12 @@ func (foo FooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var fooHandler FooHandler
|
server := &http.Server{
|
||||||
http.Handle("/foo", fooHandler)
|
Addr: ":8080",
|
||||||
|
Handler: framework.NewCore(),
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
|
if err := server.ListenAndServe(); err != nil {
|
||||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
log.Panic(err)
|
||||||
})
|
}
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user