Skip to content

Toml cannot be used map #79

Description

@xweis
#config.toml 
title       = "blabla"
[servers]
    [servers.a]
    ip      = "1.1.1.1"
    dc      = "abc"
    [servers.b]
    ip      = "2.2.2.2"
    dc      = "cba"


#main.go
type (
	WebSiteConfig struct {
		Title string
		Servers map[string]Server
	}
)

type Server struct {
		IP string
		DC string
}

func Load() *WebSiteConfig {
	config := new(WebSiteConfig)
	multiconfig.NewWithPath(LogPath). MustLoad(config)

	return config
}


#error 
panic: not struct

goroutine 1 [running]:
github.com/fatih/structs.strctVal(0xc0001c4500, 0xc0001b88f8, 0x16, 0xc0001c4500, 0xc0001b88f8)
        /Users/Xwei/go/src/github.com/fatih/structs/structs.go:437 +0x12f
github.com/fatih/structs.(*Field).FieldOk(0xc0002122d0, 0xc0002143c2, 0x1, 0xc0001ddc80, 0xc0001caa10)
        /Users/Xwei/go/src/github.com/fatih/structs/field.go:129 +0x98
github.com/fatih/structs.(*Field).Field(0xc0002122d0, 0xc0002143c2, 0x1, 0x157ad93)
        /Users/Xwei/go/src/github.com/fatih/structs/field.go:109 +0x3f
github.com/koding/multiconfig.(*EnvironmentLoader).processField(0xc0001c02a0, 0x1596ef3, 0xd, 0xc0002122d0, 0x157ad93, 0x7, 0x15fa320, 0xc0001b93b0, 0x0, 0x0)
        /Users/Xwei/go/src/github.com/koding/multiconfig/env.go:61 +0x164
github.com/koding/multiconfig.(*EnvironmentLoader).Load(0xc0001c02a0, 0x15c80e0, 0xc0001b88d0, 0x0, 0x0)


Activity

  1. AlanW0ng commented on Sep 22, 2020

    @AlanW0ng
    #config.toml 
    title       = "blabla"
    [servers]
        [servers.a]
        ip      = "1.1.1.1"
        dc      = "abc"
        [servers.b]
        ip      = "2.2.2.2"
        dc      = "cba"
    
    
    #main.go
    type (
    	WebSiteConfig struct {
    		Title string
    		Servers map[string]Server
    	}
    )
    
    type Server struct {
    		IP string
    		DC string
    }
    
    func Load() *WebSiteConfig {
    	config := new(WebSiteConfig)
    	multiconfig.NewWithPath(LogPath). MustLoad(config)
    
    	return config
    }
    
    
    #error 
    panic: not struct
    
    goroutine 1 [running]:
    github.com/fatih/structs.strctVal(0xc0001c4500, 0xc0001b88f8, 0x16, 0xc0001c4500, 0xc0001b88f8)
            /Users/Xwei/go/src/github.com/fatih/structs/structs.go:437 +0x12f
    github.com/fatih/structs.(*Field).FieldOk(0xc0002122d0, 0xc0002143c2, 0x1, 0xc0001ddc80, 0xc0001caa10)
            /Users/Xwei/go/src/github.com/fatih/structs/field.go:129 +0x98
    github.com/fatih/structs.(*Field).Field(0xc0002122d0, 0xc0002143c2, 0x1, 0x157ad93)
            /Users/Xwei/go/src/github.com/fatih/structs/field.go:109 +0x3f
    github.com/koding/multiconfig.(*EnvironmentLoader).processField(0xc0001c02a0, 0x1596ef3, 0xd, 0xc0002122d0, 0x157ad93, 0x7, 0x15fa320, 0xc0001b93b0, 0x0, 0x0)
            /Users/Xwei/go/src/github.com/koding/multiconfig/env.go:61 +0x164
    github.com/koding/multiconfig.(*EnvironmentLoader).Load(0xc0001c02a0, 0x15c80e0, 0xc0001b88d0, 0x0, 0x0)
    

    +1, TOML map lead to "panic struct" error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions