Golang MVC: Unterschied zwischen den Versionen

Aus ahrensburg.city
Zur Navigation springen Zur Suche springen
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 12: Zeile 12:
}
}
</pre>
</pre>
==router.go==
==controller.go==
<pre>
<pre>


Zeile 28: Zeile 28:
fmt.Fprint(h,"Thorsten");
fmt.Fprint(h,"Thorsten");
}
}
 
</pre>
==router==
<pre>
func router() *http.ServeMux {
func router() *http.ServeMux {
router := http.NewServeMux()
router := http.NewServeMux()
router.HandleFunc("/", start)
router.HandleFunc("/", start)
return router
return router
}
</pre>
==controller.go==
<pre>
package main
import (
"fmt"
"net/http"
)
func start(h http.ResponseWriter, r * http.Request) {
fmt.Fprint(h,"Thorsten");
}
}
</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
}