Golang MVC: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Die Seite wurde neu angelegt: „==main.go== <pre> package main import ( "net/http" ) func main() { router := newRouter() http.ListenAndServe(":9000", router) } ==router.go== <pre> package main import ( "net/http" ) func router() *http.ServeMux { router := http.NewServeMux() router.HandleFunc("/", start) return router } </pre> ==controller.go== <pre> package main import ( "fmt" "net/http" ) func start(h http.ResponseWriter, r * http.Request) { fmt.Fprint(h,"Thorsten"); }…“ |
|||
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 11: | Zeile 11: | ||
http.ListenAndServe(":9000", router) | http.ListenAndServe(":9000", router) | ||
} | } | ||
== | </pre> | ||
==controller.go== | |||
<pre> | <pre> | ||
Zeile 19: | Zeile 20: | ||
"net/http" | "net/http" | ||
) | ) | ||
package main | package main | ||
import ( | import ( | ||
Zeile 36: | Zeile 27: | ||
func start(h http.ResponseWriter, r * http.Request) { | func start(h http.ResponseWriter, r * http.Request) { | ||
fmt.Fprint(h,"Thorsten"); | fmt.Fprint(h,"Thorsten"); | ||
} | |||
</pre> | |||
==router== | |||
<pre> | |||
func router() *http.ServeMux { | |||
router := http.NewServeMux() | |||
router.HandleFunc("/", start) | |||
return router | |||
} | } | ||
</pre> | </pre> |
Aktuelle Version vom 10. Januar 2025, 00:36 Uhr
main.go
package main import ( "net/http" ) func main() { router := newRouter() http.ListenAndServe(":9000", router) }
controller.go
package main import ( "net/http" ) package main import ( "fmt" "net/http" ) func start(h http.ResponseWriter, r * http.Request) { fmt.Fprint(h,"Thorsten"); }
router
func router() *http.ServeMux { router := http.NewServeMux() router.HandleFunc("/", start) return router }