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

Parsing slice data to map failed #435

Open
dong50252409 opened this issue Jan 7, 2025 · 1 comment
Open

Parsing slice data to map failed #435

dong50252409 opened this issue Jan 7, 2025 · 1 comment

Comments

@dong50252409
Copy link

dong50252409 commented Jan 7, 2025

I want to map the data to the collect structure when parsing the ImportExtension field, so that I can quickly determine whether the table is supported at runtime. Unfortunately, I have tried a lot of methods and cannot call back the UnmarshalText method during parsing. What should I do? I can't parse the data through the UnmarshalTOML implementation interface because I actually have a lot of configuration

Example:

package main

import (
	"github.com/BurntSushi/toml"
	"log"
)

type collect struct {
	Set map[string]any
}

type contacts struct {
	Source             string
	ImportExtension    collect
}

func (c *collect) UnmarshalText(v []byte) error {
	// It won't be called here
	return nil
}

func main() {
	blob := `
		source = "./samples/"
		import_extension = ["csv", "xlsx"]
	`
	var c contacts
	_, err := toml.Decode(blob, &c)
	if err != nil {
		log.Fatal(err)
	}

}
@qdongxu
Copy link

qdongxu commented Jan 11, 2025

What is the X problem you want to resolve? It's unusual to request to parse a slice into a map.

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