Skip to content

E0418: A service or controller that isn't a struct ​

app.Service(NewX) registers a service, and @web.Controller (in Go, web.Routes.Controller or app.Controller) a controller: a struct the container constructs, by a constructor — func(deps…) *T or func(deps…) (*T, error) with T a struct — whose parameters are its dependencies. This one builds something else. Reported at boot, and by vukavet.

Wrong ​

go
type Names []string

func NewNames() Names { return Names{"ada"} }

func main() {
	app := web.New()
	app.Service(NewNames)
	app.Run("")
}
go
type Names struct{ list []string }

func NewNames() *Names { return &Names{list: []string{"ada"}} }

func main() {
	app := web.New()
	app.Service(NewNames)
	app.Run("")
}

Released under the MIT License. Vuka builds on Go and its tools, which are made by the Go Authors. Vuka is not affiliated with Google or the Go project. Go is a trademark of Google LLC.