GithubHelp home page GithubHelp logo

Comments (5)

magiconair avatar magiconair commented on August 25, 2024

Does it work if you embed them into one large struct?

from properties.

BoraBak avatar BoraBak commented on August 25, 2024

@magiconair not sure what you meant:

Option-1 doesn't work.

type Config struct {
	AppPort     string `properties:"app.port,default=3000"`
        DBConfig   *DBConfig
        PGListener *PGListener
}

Option-2 works, but it's not my desired solution/architecture.

type Config struct {
	AppPort     string `properties:"app.port,default=3000"`
	Host          string  `properties:"db.host,default=127.0.0.1"`
	Port           int       `properties:"db.port,default=5432"`
	Username string `properties:"db.username"`
	Password  string `properties:"db.password"`
	MinReconnectInterval time.Duration `properties:"pglistener.min_reconn"`
	MaxReconnectInterval time.Duration `properties:"pglistener.max_reconn"`
}

from properties.

magiconair avatar magiconair commented on August 25, 2024

Does it work if you rename DBConfig to DB in option 1?

from properties.

BoraBak avatar BoraBak commented on August 25, 2024

@magiconair nope.

from properties.

KangKangTao avatar KangKangTao commented on August 25, 2024

maybe embedding mean this, move the prefix in tag of embedded struct to tag of parent struct:

type Config struct {
	AppPort string `properties:"app.port,default=3000"`
	DBConfig `properties:"db"`
	PGListener `properties:"pglistener"`
}

type DBConfig struct {
	Host          string  `properties:"host,default=127.0.0.1"`
	Port           int       `properties:"port,default=5432"`
	Username string `properties:"username"`
	Password  string `properties:"password"`
}

type PGListener struct {
	MinReconnectInterval time.Duration `properties:"min_reconn"`
	MaxReconnectInterval time.Duration `properties:"max_reconn"`
}

from properties.

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.