{"record":{"id":"0be7b4ba71f345f5","repo":"kataras/iris","slug":"binder-struct-should-be-a-pointer-to-a-struct-va","errorCode":null,"errorMessage":"binder: struct: should be a pointer to a struct value","messagePattern":"binder: struct: should be a pointer to a struct value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/struct.go","lineNumber":62,"sourceCode":"}\n\ntype singletonStruct interface {\n\tSingleton() bool\n}\n\nfunc isMarkedAsSingleton(structPtr any) bool {\n\tif sing, ok := structPtr.(singletonStruct); ok && sing.Singleton() {\n\t\treturn true\n\t}\n\n\treturn false\n}\n\nfunc makeStruct(structPtr any, c *Container, partyParamsCount int) *Struct {\n\tv := valueOf(structPtr)\n\ttyp := v.Type()\n\tif typ.Kind() != reflect.Ptr || indirectType(typ).Kind() != reflect.Struct {\n\t\tpanic(\"binder: struct: should be a pointer to a struct value\")\n\t}\n\n\tisSingleton := isMarkedAsSingleton(structPtr)\n\n\tdisablePayloadAutoBinding := c.DisablePayloadAutoBinding\n\tenableStructDependents := c.EnableStructDependents\n\tdisableStructDynamicBindings := c.DisableStructDynamicBindings\n\tif isSingleton {\n\t\tdisablePayloadAutoBinding = true\n\t\tenableStructDependents = false\n\t\tdisableStructDynamicBindings = true\n\t}\n\n\t// get struct's fields bindings.\n\tbindings := getBindingsForStruct(v, c.Dependencies, c.MarkExportedFieldsAsRequired, disablePayloadAutoBinding, enableStructDependents, c.DependencyMatcher, partyParamsCount, c.Sorter)\n\n\t// length bindings of 0, means that it has no fields or all mapped deps are static.\n\t// If static then Struct.Acquire will return the same \"value\" instance, otherwise it will create a new one.","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/struct.go#L44-L80","documentation":"makeStruct (used by container.Struct) requires a pointer to a struct so it can set fields via reflection. Passing anything else — a non-pointer struct, a pointer to non-struct, or a primitive — cannot be bound and panics.","triggerScenarios":"c.Struct(MyStructValue{}) (value, not pointer), c.Struct(&someInt), or c.Struct(new(SomeNonStructType)) at container setup.","commonSituations":"Forgetting the & when passing a struct literal; passing an interface holding a non-struct; after changing the target type from struct to something else without updating the call.","solutions":["Pass a pointer to a struct: c.Struct(&MyStruct{}).","Verify the underlying type is actually a struct (indirectType(typ).Kind() == reflect.Struct).","If registering the value itself, use c.Register instead of c.Struct."],"exampleFix":"// before\nc.Struct(Config{}) // value, not pointer\n// after\nc.Struct(&Config{})","handlingStrategy":"validation","validationCode":"func safeStruct(c *hero.Container, v any) {\n\tt := reflect.TypeOf(v)\n\tif t == nil || t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {\n\t\tpanic(\"Struct() requires a pointer to a struct\")\n\t}\n\tc.Struct(v)\n}","typeGuard":"func isStructPtr(v any) bool {\n\tt := reflect.TypeOf(v)\n\treturn t != nil && t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct\n}","tryCatchPattern":null,"preventionTips":["Always call c.Struct(&T{}), never c.Struct(T{}).","Double-check the & for struct literals.","Use c.Register for non-struct values."],"tags":["dependency-injection","struct-binding","panic","pointer-required"],"backgroundTag":"invalid-dependency-value","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}