Closed nilslice closed 7 years ago
The issue I'm having with Ponzu in the other thread has to do with exactly the same code.I went back to the recording of the gopher academy training on Ponzu to do the exercise again to get the hang of Ponzu. However the updates to channel.go now result in a panic error as soon as I try to create a new channel via admin. Am i doing something wrong or is this connected to this bug?
package content
import (
"fmt"
"github.com/ponzu-cms/ponzu/management/editor"
"github.com/ponzu-cms/ponzu/system/item"
"github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference"
)
type Channel struct {
item.Item
Title string `json:"title"`
Videos []string `json:"videos"`
Rating string `json:"rating"`
Tags []string `json:"tags"`
}
// MarshalEditor writes a buffer of html to edit a Channel within the CMS
// and implements editor.Editable
func (c *Channel) MarshalEditor() ([]byte, error) {
view, err := editor.Form(c,
// Take note that the first argument to these Input-like functions
// is the string version of each Channel field, and must follow
// this pattern for auto-decoding and auto-encoding reasons:
editor.Field{
View: editor.Input("Title", c, map[string]string{
"label": "Title",
"type": "text",
"placeholder": "Enter the Title here",
}),
},
editor.Field{
View: reference.SelectRepeater("Videos", c, map[string]string{
"label": "Videos",
}, "Video", `{{.title}} ({{.rating}})`),
},
editor.Field{
View: editor.Select("Rating", c, map[string]string{
"label": "Rating",
}, map[string]string{
"G": "G",
"PG": "PG",
"PG-13": "PG-13",
"R": "R",
}),
},
editor.Field{
View: editor.Tags("Tags", c, map[string]string{
"label": "Tags",
}),
},
)
if err != nil {
return nil, fmt.Errorf("Failed to render Channel editor view: %s", err.Error())
}
return view, nil
}
func init() {
item.Types["Channel"] = func() interface{} { return new(Channel) }
}
The error I get: 2017/02/19 09:09:07 http: panic serving [::1]:39134: interface conversion: interface {} is nil, not string goroutine 36 [running]: net/http.(conn).serve.func1(0xc4201583c0) /usr/local/go/src/net/http/server.go:1721 +0xd0 panic(0x895a00, 0xc42013da40) /usr/local/go/src/runtime/panic.go:489 +0x2cf github.com/ponzu-cms/ponzu/system/addon.ContentAll(0x90f229, 0x5, 0xc420017650, 0x0, 0xc420017650) /home/arjan/Development/Go/src/github.com/ponzu-cms/ponzu/system/addon/api.go:21 +0x3d2 github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference.encodeDataToOptions(0x90f229, 0x5, 0x91bd00, 0x18, 0xc420104980, 0x1, 0x1) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference/reference.go:122 +0xac github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference.SelectRepeater(0x90fee4, 0x6, 0x8f7d40, 0xc420151050, 0xc4200175f0, 0x90f229, 0x5, 0x91bd00, 0x18, 0x7f2df8309440, ...) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/addons/github.com/bosssauce/reference/reference.go:57 +0x384 github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content.(Channel).MarshalEditor(0xc420151050, 0xc420104940, 0xe200000000000000, 0x8, 0xe20fd6032780c56a, 0x0) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/channel.go:37 +0x280 github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/management/manager.Manage(0xb38580, 0xc420151050, 0xc420117e75, 0x7, 0xc420151050, 0x1, 0x0, 0x0, 0x0) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/management/manager/manager.go:122 +0x4c github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin.editHandler(0xb3ea80, 0xc4219b4460, 0xc420188000) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/handlers.go:1490 +0x27f0 net/http.HandlerFunc.ServeHTTP(0x935828, 0xb3ea80, 0xc4219b4460, 0xc420188000) /usr/local/go/src/net/http/server.go:1942 +0x44 github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/user.Auth.func1(0xb3ea80, 0xc4219b4460, 0xc420188000) /home/arjan/Development/Go/src/github.com/arjanvaneersel/gotv/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/system/admin/user/auth.go:55 +0xda net/http.HandlerFunc.ServeHTTP(0xc4201040b0, 0xb3ea80, 0xc4219b4460, 0xc420188000) /usr/local/go/src/net/http/server.go:1942 +0x44 net/http.(ServeMux).ServeHTTP(0xb803a0, 0xb3ea80, 0xc4219b4460, 0xc420188000) /usr/local/go/src/net/http/server.go:2238 +0x130 net/http.serverHandler.ServeHTTP(0xc420090b00, 0xb3ea80, 0xc4219b4460, 0xc420188000) /usr/local/go/src/net/http/server.go:2568 +0x92 net/http.(conn).serve(0xc4201583c0, 0xb3f380, 0xc420100480) /usr/local/go/src/net/http/server.go:1825 +0x612 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2668 +0x2ce
Hi @arjanvaneersel -
However the updates to channel.go now result in a panic error as soon as I try to create a new channel via admin.
Which updates do you mean?
I obviously haven't been clear. I'm doing the exercise as shown in the recording of the gopher academy training on Ponzu again. After the creation of alle the content types the go files are being changed in the training, so I follow along. The moment when I "update" the editor.Field for Videos, which was just a normal input type, to reference.SelectRepeater and build and run Ponzu again, then I get this error when going into Ponzu's editor for this content type.
Could you try changing the import path for the "reference" package to this:
"github.com/bosssauce/reference"
That is the canonical path, and although you have the package at the import
path you included, running $ ponzu build
will copy that code from your
addon directory into its internal vendor directory where it then compiles
the packages into your project.
On Mon, Feb 20, 2017 at 20:15 Arjan van Eersel notifications@github.com wrote:
I obviously haven't been clear. I'm doing the exercise as shown in the recording of the gopher academy training on Ponzu again. After the creation of alle the content types the go files are being changed in the training, so I follow along. The moment when I "update" the editor.Field for Videos, which was just a normal input type, to reference.SelectRepeater and build and run Ponzu again, then I get this error when going into Ponzu's editor for this content type.
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ponzu-cms/ponzu/issues/59#issuecomment-281241116, or mute the thread https://github.com/notifications/unsubscribe-auth/AHK1S8hP9eLpngiFTPP8QhkTf017isDSks5remTSgaJpZM4L1psB .
That indeed did it. I relied on the auto import function of gogland and never even thought about something as simple as checking the import path... Thanks for your help.
Excellent! Glad it fixed the issue.
values in fields for select repeaters and tags end up being merged/copied into one another in some scenarios
example where it can be reproduced: