kataras/iris · error
struct: method: %s does not exist
Error message
struct: method: %s does not exist
What it means
Struct.MethodHandler panics when the requested methodName does not exist as an exported method on the registered struct's concrete type (hero/struct.go:185). It uses reflect Type.MethodByName, so only exported methods with a method-value receiver are found.
Source
Thrown at hero/struct.go:185
} // #1629
}
elem.FieldByIndex(b.Input.StructFieldIndex).Set(input)
}
}
return ctrl, nil
}
// MethodHandler accepts a "methodName" that should be a valid an exported
// method of the struct and returns its converted Handler.
//
// Second input is optional,
// even zero is a valid value and can resolve path parameters correctly if from root party.
func (s *Struct) MethodHandler(methodName string, paramsCount int) context.Handler {
m, ok := s.ptrValue.Type().MethodByName(methodName)
if !ok {
panic(fmt.Sprintf("struct: method: %s does not exist", methodName))
}
return makeHandler(m.Func, s.Container, paramsCount)
}
View on GitHub (pinned to 7bedaf55a0)
Solutions
- Verify the method name spelling and that it is exported (starts with an uppercase letter).
- Ensure the method is defined on the exact type registered with the hero Struct, not only on an embedded or interface type.
- Use route registration by method reference (e.g. app.Get("/", c.Handler)) so the compiler catches missing methods instead of string lookup.
- Add a test that builds all MethodHandler registrations at startup so the panic surfaces early.
Example fix
// before
h := s.MethodHandler("Indexx", 0) // typo
// after
h := s.MethodHandler("Index", 0) Defensive patterns
Strategy: validation
Validate before calling
// Check the method exists before requesting a handler
if _, ok := reflect.TypeOf(MyController{}).MethodByName("Index"); !ok {
log.Fatal("controller method Index not found")
}
h := s.MethodHandler("Index", 0) Type guard
func hasMethod(obj interface{}, name string) bool {
return reflect.ValueOf(obj).MethodByName(name).IsValid()
} Prevention
- Prefer typed route registration (app.Get("/", c.Index)) over string-based MethodHandler.
- Keep method names in sync with registrations; avoid unexported methods for handlers.
- Add a startup smoke test that builds every route.
When it happens
Trigger: Calling s.MethodHandler("Name", n) where Name is misspelled, unexported, defined on an embedded/unrelated type, or the handler was built from an interface type that lacks the method.
Common situations: Refactoring renames a controller method without updating the manual MethodHandler registration; registering handlers on a struct via routes that reference methods with different casing.
Related errors
- iris: switch: hosts: invalid target type: %T
- <appName> is not a registered Application
- bindings: unresolved: no a func type: %#+v
- bindings: unresolved: not a struct type: %#+v
- HandleError input argument must be a type of func(iris.Conte
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/7ceccf676e169618.
Report an issue: GitHub.