You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Huge fan of your product. I seem unable to figure out, how to encode a simple slice type type People []Person. Using
package main
import (
"fmt"
"github.com/gorilla/schema"
)
type Person struct {
Name string `schema:"name"`
Age int
}
type People []Person
func main() {
jay := Person{"Jay", 34}
may := Person{"May", 43}
peeps := People{jay, may}
values := make(map[string][]string)
encoder := schema.NewEncoder()
err := encoder.Encode(peeps, values)
if err != nil {
panic(err)
}
fmt.Printf("Encoded people: %v\n", values)
}
I get the error panic: schema: interface must be a struct.
Wrapping People into a struct now called Group also does not work:
package main
import (
"fmt"
"github.com/gorilla/schema"
)
type Person struct {
Name string `schema:"name"`
Age int
}
type Group struct {
People []Person
}
func main() {
jay := Person{"Jay", 34}
may := Person{"May", 43}
peeps := Group{[]Person{jay, may}}
values := make(map[string][]string)
encoder := schema.NewEncoder()
err := encoder.Encode(peeps, values)
if err != nil {
panic(err)
}
fmt.Printf("Encoded group %v\n", values)
}
Exits with error: panic: schema: encoder not found for [{Jay 34} {May 43}]
What am I doing wrong here? Ideally I would like to work with the first version of type People []Person.
The text was updated successfully, but these errors were encountered:
Huge fan of your product. I seem unable to figure out, how to encode a simple slice type
type People []Person
. UsingI get the error
panic: schema: interface must be a struct
.Wrapping People into a
struct
now calledGroup
also does not work:Exits with error:
panic: schema: encoder not found for [{Jay 34} {May 43}]
What am I doing wrong here? Ideally I would like to work with the first version of
type People []Person
.The text was updated successfully, but these errors were encountered: