Golang MVC

Aus ahrensburg.city
Version vom 10. Januar 2025, 00:33 Uhr von Thorsten (Diskussion | Beiträge) (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"); }…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

main.go

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
}

controller.go


package main
import (
	"fmt"
	"net/http"
)
func start(h http.ResponseWriter, r * http.Request) {
	fmt.Fprint(h,"Thorsten");
}