Skip to content
Gx
GitHub

GX3001: pattern variable has no field

The route pattern has a variable and the route type has no field for it.

Cause

The route pattern has a variable and the route type has no field for it. A variable binds to the field with the same name; upper and lower case are equal.

Example

shop/route/route.go
package route

import "github.com/alternayte/gx"

type Show struct {
	gx.Route `GET /products/{id}`
}

gx check reports:

gx check
shop/route/route.go:5:6: GX3001: pattern variable "id" has no field in "Show"

Fix

  1. Add a field with the name of the variable.
  2. Or add a path:"name" tag to the field that takes the value.