Giter Club home page Giter Club logo

kdl-go's People

Contributors

sblinch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

focusaurus

kdl-go's Issues

Using KDL for config and unmarshal failing

Thanks for creating kdl-go and especially investing so much effort into the docs. Appreciated! I'm trying to move a yaml struct config to kdl structs, and haven't managed to make it work yet.

I've pasted my code below.

When I run this the following is printed:

{Defaults:{Name: Manager:false Shifts:12} Staff:[]}

Defaults is populated with shifts = 12 as expected, but the slice of Staff is empty. Any idea what I'm doing wrong?

package main

import (
	"fmt"
	"github.com/sblinch/kdl-go"
)

func main() {
	data := `
defaults {
  shifts 12
}

team {
  staff "Olivia" manager=true
  staff "Ethan"
  staff "Ava"
  staff "Harper" shifts=10
  staff "Lucas"
  staff "Mason" manager=true
  staff "David" shifts=4
  staff "Ian" manager=true
  staff "Sophia"
  staff "Lily" manager=true
}
`

	var cfg Config

	err := kdl.Unmarshal([]byte(data), &cfg)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", cfg)
}

type Config struct {
	Defaults Staff `kdl:"defaults"`
	Staff []Staff `kdl:"team"`
}

type Staff struct {
	Name    string `kdl:"staff,multiple"`
	Manager bool  `kdl:"manager"`
	Shifts  int  `kdl:"shifts"`
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.