Missing type in composite literal

前端 未结 2 753
日久生厌
日久生厌 2020-11-28 12:41
type A struct {
    B struct {
        Some string
        Len  int
    }
}

Simple question. How to initialize this struct? I would like to do somet

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 13:01

    do it this way:

    type Config struct {
        Element struct {    
            Name string 
            ConfigPaths []string 
        } 
    }
    
    config = Config{}
    config.Element.Name = "foo"
    config.Element.ConfigPaths = []string{"blah"}
    

提交回复
热议问题