W0402: A direct read where a processor variable would do
A vuka file — a .vuka.html file's markup or script, or a .vuka file — calls auth.Can(ctx, "x"), auth.Current(ctx), auth.Current(ctx).Can("x") or web.Request(ctx) for what a context processor's variable gives: perms.Has("x"), user or request (its Path, Query and Params). Both read the same value, but only the variable is tracked: in markup, a spot calling auth.Can doesn't render again when the visitor's permissions change, and a staying layout calling web.Request reloads where one reading request.Path renders that spot again. In an event or Mount the variable is as current as the call: the processor's input is the identity and its permission version. One spelling, the variable, keeps vuka files from mixing the two. Reported by vuka vet.
When main doesn't list the processor (auth.Context, web.RequestContext), the help says to add it. A read the variable can't give — web.Request(ctx).Header — isn't reported.
vuka fix ctx-vars rewrites the reads, dropping the imports of web and auth left unused; the editor offers the same rewrite as a quick fix. From 3.0 this is a compile error in vuka files.
Plain .go packages — services, jobs, libraries — keep auth.Can, auth.Current and web.Request: they have no template variables.
Wrong
<script lang="go">
func (d *Index) Approve(ctx context.Context) error {
if !auth.Can(ctx, "approve") {
return web.Forbidden
}
return nil
}
</script>
if auth.Can(ctx, "approve") {
<button onClick={Approve}>Approve</button>
}
<small>{web.Request(ctx).URL.Path}</small>Right
<script lang="go">
func (d *Index) Approve(ctx context.Context) error {
if !perms.Has("approve") {
return web.Forbidden
}
return nil
}
</script>
if perms.Has("approve") {
<button onClick={Approve}>Approve</button>
}
<small>{request.Path}</small>