I am going through a course in udemy about testing in golang and they gave a project as an example. The main.go file is like this:
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
type application struct {
}
func (a *application) routes() http.Handler {
mux := chi.NewRouter()
mux.Use(middleware.Recoverer)
return mux
}
and at the same level i have a file called routes.go which is like this:
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func (a *application) routes() http.Handler {
mux := chi.NewRouter()
mux.Use(middleware.Recoverer)
return mux
}
When I ran the program it gives me this error: ./main.go:13:13: app.routes undefined (type application has no field or method routes)
If I delete the routes.go file and put everything on the main.go it works, but I don't understand why this is happening because routes and main are on the same package. Could someone explain me why this is happening?