Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil) #39

Open
darcys22 opened this issue Sep 27, 2020 · 0 comments

Comments

@darcys22
Copy link

Have been trying to set up a JSON Post Request using the Macaron Example

  type ContactForm struct {
    Name string `json:"name" binding:"Required"`
  }
  r.Post("/api/journals", binding.Bind(ContactForm{}), func(contact ContactForm) string {
    return fmt.Sprintf("Name: %s", contact.Name)
  })

However calling this with the following JSON request from within jquery:

      $.ajax({
          type: 'POST',
          url: '/api/journals',
          data: '{"name":"hello"}',
          success: function(data) { alert('data: ' + data); },
          contentType: "application/json",
          dataType: 'json'
      });

returns the following error when the request is sent:

*Called inject.InterfaceOf with a value that is not a pointer to an interface. (MyInterface)(nil)

with the following stack trace:

/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:113 (0x792c6d)
	InterfaceOf: panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)")
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:222 (0x793a7e)
	(*injector).MapTo: i.values[InterfaceOf(ifacePtr)] = reflect.ValueOf(val)
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/binding.go:752 (0x8258c4)
	validateAndMap: ctx.MapTo(obj.Elem().Interface(), ifacePtr[0])
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/binding.go:210 (0x826edb)
	Json.func1: validateAndMap(jsonStruct, ctx, errors, ifacePtr...)
/usr/local/go/src/reflect/value.go:475 (0x49af66)
	Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))
/usr/local/go/src/reflect/value.go:336 (0x49a458)
	Value.Call: return v.call("Call", in)
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:177 (0x793379)
	(*injector).callInvoke: return reflect.ValueOf(f).Call(in), nil
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:137 (0x792d4a)
	(*injector).Invoke: return inj.callInvoke(f, t, t.NumIn())
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/binding.go:45 (0x81e5be)
	bind: ctx.Invoke(Json(obj, ifacePtr...))
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/binding.go:104 (0x8260c5)
	Bind.func1: bind(ctx, obj, ifacePtr...)
/home/sean/go/pkg/mod/gopkg.in/[email protected]/context.go:79 (0x7c5a72)
	ContextInvoker.Invoke: invoke(params[0].(*Context))
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:157 (0x793094)
	(*injector).fastInvoke: return f.Invoke(in)
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:135 (0x792e39)
	(*injector).Invoke: return inj.fastInvoke(v, t, t.NumIn())
/home/sean/go/pkg/mod/gopkg.in/[email protected]/context.go:121 (0x7c5bfc)
	(*Context).run: vals, err := c.Invoke(c.handler())
/home/sean/go/pkg/mod/gopkg.in/[email protected]/context.go:112 (0x7d6da5)
	(*Context).Next: c.run()
/home/sean/go/pkg/mod/gopkg.in/[email protected]/recovery.go:161 (0x7d6d98)
	Recovery.func1: c.Next()
/home/sean/go/pkg/mod/gopkg.in/[email protected]/logger.go:40 (0x7c97b7)
	LoggerInvoker.Invoke: invoke(params[0].(*Context), params[1].(*log.Logger))
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:157 (0x793094)
	(*injector).fastInvoke: return f.Invoke(in)
/home/sean/go/pkg/mod/github.com/go-macaron/[email protected]/inject.go:135 (0x792e39)
	(*injector).Invoke: return inj.fastInvoke(v, t, t.NumIn())
/home/sean/go/pkg/mod/gopkg.in/[email protected]/context.go:121 (0x7c5bfc)
	(*Context).run: vals, err := c.Invoke(c.handler())
/home/sean/go/pkg/mod/gopkg.in/[email protected]/router.go:187 (0x7d7ff0)
	(*Router).Handle.func1: c.run()
/home/sean/go/pkg/mod/gopkg.in/[email protected]/router.go:303 (0x7d2125)
	(*Router).ServeHTTP: h(rw, req, p)
/home/sean/go/pkg/mod/gopkg.in/[email protected]/macaron.go:220 (0x7cab0d)
	(*Macaron).ServeHTTP: m.Router.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:2843 (0x767bc2)
	serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1925 (0x7633cc)
	(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_amd64.s:1374 (0x470480)
	goexit: BYTE	$0x90	// NOP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant