cannot use jv (type util.JsonView) as type util.View in assignment: util.JsonView does not implement util.View (Render method requires pointer receiver)
I can't see what I'm doing wrong, I have implemented the interface several times already. I've even tried altering how JsonView is implemented, using a slice of bytes rather than an interface but that didn't do it. Am I just missing something core?
My interface:
type View interface { Render(w http.ResponseWriter) (os.Error) }
type that doesn't work:
type JsonView struct {
Value interface {}
}
func (j *JsonView) Render(w http.ResponseWriter) (os.Error) {
b, _ := json.Marshal(j.Value)
_, err:= w.Write(b)
return err
}
type that does work:
type JsonSuccessView struct { }
func (j *JsonSuccessView) Render(w http.ResponseWriter) (os.Error) {
m := make(map[string] bool)
m["success"] = true
b, _ := json.Marshal(m)
_, err:= w.Write(b)
return err
}
The problem is in the code you're not showing us.
Somewhere (the line that error message indicates) you are attempting
to assign a value of type util.JsonView to an util.View.
You want a *util.JsonView instead since *util.JsonView satisfies that
interface and util.JsonView doesn't.
>
>
> I can't see what I'm doing wrong, I have implemented the interface several
> times already. I've even tried altering how JsonView is implemented, using a
> slice of bytes rather than an interface but that didn't do it. Am I just
> missing something core?
>
>
> My interface:
>
> type View interface {
> Render(w http.ResponseWriter) (os.Error)
> }
>
>
>
> type that doesn't work:
>
>
> type JsonView struct {
> Value interface {}
> }
>
>
> func (j *JsonView) Render(w http.ResponseWriter) (os.Error) {
> b, _ := json.Marshal(j.Value)
> _, err:= w.Write(b)
> return err
> }
>
>
> type that does work:
>
>
> type JsonSuccessView struct { }
>
>
> func (j *JsonSuccessView) Render(w http.ResponseWriter) (os.Error) {
> m := make(map[string] bool)
> m["success"] = true
> b, _ := json.Marshal(m)
> _, err:= w.Write(b)
> return err
> }
--
=====================
http://jessta.id.au
We need to see the line that fails (and the contrasting one that succeeds),
but my guess is that in one of them you have a *Wossname and in the other
just a Wossname. It's the *Wossname that satisfies the interface, not the
Wossname on its own.
(Wossname = JsonView / JsonSuccessView, as appropriate.)
Chris
--
Chris "allusive" Dollin