i have this code of simple web server but i dont understand this code :
Handler:app.routes(),
const webPort = "80"
type Config struct {}
func main() {
app := Config{}
log.Printf("Starting broker service on port %s\n",webPort)
srv := &http.Server{
Addr: fmt.Sprintf(":%s",webPort),
Handler:app.routes(),
}
err := srv.ListenAndServe()
if(err != nil) {
log.Panic(err)
}
}
and in routes file :
func (app *Config) routes() http.Handler {
mux := chi.NewRouter()
mux.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"http://*","https://*"},
AllowedMethods: []string{"GET", "POST", "DELETE","PUT","OPTIONS"},
AllowedHeaders: []string{"Accept","Authorization","Content-Type","X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials:true,
MaxAge:300,
}))
mux.Use(middleware.Heartbeat("/ping"))
mux.Post("/",app.Broker)
return mux
}
this is wroking and the routes() function called when request recived but how does this routes() knows to be triggered when it attached to empty struct
app := Config{}
from where does app knows about routes() ?
what is the :
func (app *Config)
in the function ?