Git Product home page Git Product logo

Comments (1)

pancakebasspanda avatar pancakebasspanda commented on May 26, 2024

I noticed that in the current version if I use the config tag and json tags I get very different behaviors:

package main

import (
	"context"
	"github.com/heetch/confita"
	"github.com/heetch/confita/backend/file"
	"github.com/heetch/confita/backend/flags"
	log "github.com/sirupsen/logrus"
	"time"
)

type Config struct {
	Host        string        `config:"host"`
	Port        uint32        `config:"port"`
	Timeout     time.Duration `config:"timeout"`
	Password    string        `config:"password"`
	Name string `config:"name,required"`
	OrderValue float64 `config:"order_value"`
	itemNumber int `config:"item_number"`
}

func main() {
	loader := confita.NewLoader(
		file.NewBackend("cmd/confita/config.json"),
		flags.NewBackend(),
		)

	// default values
	cfg := Config{
		Host: "127.0.0.1",
		Port: 5656,
		Timeout: 5 * time.Second,
	}

	ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
	defer cancel()

	// loading configuration
	if err := loader.Load(ctx, &cfg); err != nil {
		log.WithError(err).Fatal("loading config")
	}


	// check the config
	log.WithField("config", cfg).Info("config loaded")
}

Using the config tag, strings seem to load fine however floats and ints don't. If I then use the json tag, strings and floats load fine but not ints.

example JSON FIle:
{ "name" : "red shoes", "item_number" : 2, "order_value": 23.45 }

output with config tags:
time="2021-02-15T20:31:04Z" level=info msg="config loaded" config="{127.0.0.1 5656 5s red shoes 0 0}"

output with json tags:
time="2021-02-15T20:38:12Z" level=info msg="config loaded" config="{127.0.0.1 5656 5s red shoes 23.45 0}"

from confita.

Related Issues (20)

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.