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

Converting comman seperated strings into slice of string. #40

Closed
henrikbjorn opened this issue May 12, 2015 · 2 comments
Closed

Converting comman seperated strings into slice of string. #40

henrikbjorn opened this issue May 12, 2015 · 2 comments

Comments

@henrikbjorn
Copy link

Currently if I add a custom converter like decoder.RegisterConverter([]string{}, func (input string) reflect.Value {}) it wont call the custom converter but instead ignore it.

package schema_test

import (
    "fmt"
    "reflect"
    "testing"

    "github.com/gorilla/schema"
)

func TestStrings(t *testing.T) {
    decoder := schema.NewDecoder()
    decoder.RegisterConverter([]string{}, func(input string) reflect.Value {
        fmt.Printf("%+v", input)

        return reflect.ValueOf(input)
    })

    i := struct {
        Multiple []string `schema:"multiple"`
    }{}

    decoder.Decode(&i, map[string][]string{
        "multiple": []string{"one,two,three"},
    })
}

Would have suspected i.Multiple to contain a []string{"one", "two", "three"}

@kisielk
Copy link
Contributor

kisielk commented May 12, 2015

The above fix should work.

@Demznak
Copy link

Demznak commented Jul 20, 2018

hello, I have problem when I convert slice
decoder.RegisterConverter([]string{}, func (input []string) reflect.Value {})

func(input []string) reflect.Value {
for _, val := range input {
              fmt.P rintf("%+v", val)
              //validate val   
              //if err  {return reflect.Value{}}
       }
        return reflect.ValueOf(input)
    }

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

3 participants