Skip to content

Default value for slice of struct doesn't work for golang v 1.12 #14

@pavankumar-bit

Description

@pavankumar-bit
package controllers

import (
	"fmt"

	"github.com/creasty/defaults"
)

func main() {

	foo := &Parent{}
	if err := defaults.Set(foo); err != nil {
		fmt.Println(err)
	}
	fmt.Print(foo)
}

type Child struct {
	Name string
	Age  int `default:"33"`
}

type Parent struct {
	children []Child
}

output: &{[]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions