Skip to content

E0422: A variable not every main gives ​

A package reads user by name, and two package mains import it — an app in cmd/web and another in cmd/admin, say. Each main has its own web.ContextProcessors(…), and the name lowers to one typed read only when every one of them gives it, with one type. Here a main lacks the processor, or gives the name with another type; the message names which. Reported by the compiler.

A main that never calls web.ContextProcessors — a command running migrations — renders no page and isn't counted.

Wrong ​

go
// cmd/web/main.go
web.ContextProcessors(web.RequestContext, auth.Context)

// cmd/admin/main.go: the same layouts, no auth.Context
web.ContextProcessors(web.RequestContext)
go
// cmd/admin/main.go
web.ContextProcessors(web.RequestContext, auth.Context)

A package meant for mains with different lists reads what only some give explicitly, web.Var[*auth.Identity](ctx, "user"), where it knows it is there. See context processors.

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.