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

Bug: schema.Array{} returning "gob type not registered for interface error" using memory storage #80

Closed
ultimateboy opened this issue Jan 3, 2017 · 2 comments

Comments

@ultimateboy
Copy link
Contributor

I'm having issues getting an array field to work as expected. Any help would be greatly appreciated. I've tried a number of different ValuesValidators and get similar results with each.

Steps to reproduce:

  1. Create a simple schema with a &schema.Array{} field
  2. Submit a POST with a list of values into the list field

Expected Outcome:

Entity saved correctly

Actual Outcome:

Error: "gob: type not registered for interface: []interface {}"

Sample Code:

package main

import (
	"log"
	"net/http"

	"github.com/justinas/alice"

	mem "github.com/rs/rest-layer-mem"
	"github.com/rs/rest-layer/resource"
	"github.com/rs/rest-layer/rest"
	"github.com/rs/rest-layer/schema"
)

var (
	fooSchema = schema.Schema{
		Description: `A foo object`,
		Fields: schema.Fields{
			"id": schema.IDField,
			"name": {
				Required:   true,
				Filterable: true,
				Validator: &schema.String{
					MaxLen: 150,
				},
			},
			"list": {
				Validator: &schema.Array{
					ValuesValidator: &schema.String{},
				},
			},
		},
	}
)

func main() {
	resource.LoggerLevel = resource.LogLevelDebug

	index := resource.NewIndex()

	fooHandler := mem.NewHandler()
	_ = index.Bind("foo", fooSchema, fooHandler, resource.Conf{
		AllowedModes: resource.ReadWrite,
	})

	api, err := rest.NewHandler(index)
	if err != nil {
		log.Fatalf("Invalid API configuration: %s", err)
	}

	c := alice.New()
	http.Handle("/", c.Then(api))

	log.Print("Serving API on http://localhost:8080")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(err)
	}
}

Sample of error:

$ http post :8080/foo name="test" list:='["a","b"]'
HTTP/1.1 520 status code 520
Content-Length: 79
Content-Type: application/json
Date: Tue, 03 Jan 2017 21:17:32 GMT

{
    "code": 520,
    "message": "gob: type not registered for interface: []interface {}"
}
@smyrman
Copy link
Collaborator

smyrman commented Jan 3, 2017

I can reproduce this (using curl):

curl -X POST -H Content-Type:"application/json" -d '{"name": "test", "list": ["a", "b"]}' http://localhost:8080/foo

It appears to be an easy fix, I will attempt to do a PR for it.

@ultimateboy ultimateboy changed the title Support: schema.Array{} returning "gob type not registered for interface error" Bug: schema.Array{} returning "gob type not registered for interface error" using memory storage Jan 3, 2017
@ultimateboy
Copy link
Contributor Author

Confirmed the PR provided by smyrman in rs/rest-layer-mem#3 fixes this issue. Closing in favor of that PR.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants