gonfig | a config parser for GO | JSON Processing library
kandi X-RAY | gonfig Summary
kandi X-RAY | gonfig Summary
a config parser for GO with support for path selectors. a loaded config gonfig.FromJson("path/to/config.json") exposes the following methods.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Get value by key
- FromYml creates a Gonfig from a io . Reader
- FromJson creates a Gonfig from a reader
gonfig Key Features
gonfig Examples and Code Snippets
Community Discussions
Trending Discussions on gonfig
QUESTION
I develop application on my Ubuntu 18.04 with go.
I have config package. The idea is to use this package in another packages to get configurations. Package config has struct variable _Config
. The idea that function GetConfig
will return _Config
, and when _Config
not filled the function will firstly fill _Config
from json file.
The config package looks like this:
...ANSWER
Answered 2020-Feb-26 at 08:55You have a line in GetConfig()
function -
_Config := Config{}
.
Here, you are declaring a new variable _Config
in local scope and shadowing the global variable. Remove this line and try again. Due to shadowing, global variable is not populated with config from json.
QUESTION
I just play a little with Go to learn the handling.
I have a main go program. I created a sub-folder for a database module, in that I want to do database operations.
For the parameters I have a struct type with credentials etc. How can I pass the struct to the module?
I want all of the configuration and global variables needed in an configuration struct and pass it to the modules if needed.
Is this a good method to achieve the goal? Thanks for the help.
./main.go
:
ANSWER
Answered 2019-Aug-25 at 12:49AppConfig on your Test function of type Configuration struct, which you have declared on your main package. Since go doesn't support cyclic dependencies, you can not import Configuration struct into the dbapi package to use it there. So, I would move Configuration struct from the main package and declare it in the dbapi package.
QUESTION
I use MacOS Mojave with IntelliJ Ultimate 2018.2.
I wrote a go application that loads a config file from the directory of my project. I created an InitConfig()
function to load the JSON file into a struct. this is thee code of my Config.go
file
ANSWER
Answered 2018-Oct-03 at 14:22it seems that the solution is simple. all I needed is to set the "Output Directory" of my run/debug configuration to my project's directory. and then intellij executes the file in that same directory and it can find /config/config.json
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gonfig
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page