https://github.com/siberia-projects/siberia-configuration-properties
Siberia-configuration-properties is a library which allows you write 1 config file which could be divided on small configs with env variables expansion
https://github.com/siberia-projects/siberia-configuration-properties
configuration customizable easy-to-use env expansion framework go properties siberia yaml
Last synced: 5 months ago
JSON representation
Siberia-configuration-properties is a library which allows you write 1 config file which could be divided on small configs with env variables expansion
- Host: GitHub
- URL: https://github.com/siberia-projects/siberia-configuration-properties
- Owner: siberia-projects
- License: apache-2.0
- Created: 2024-01-17T17:23:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-29T16:55:59.000Z (over 2 years ago)
- Last Synced: 2024-06-21T19:53:12.236Z (about 2 years ago)
- Topics: configuration, customizable, easy-to-use, env, expansion, framework, go, properties, siberia, yaml
- Language: Go
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Siberia Configuration Properties
=================
[](https://github.com/siberia-projects/siberia-configuration-properties)
[](https://github.com/siberia-projects/siberia-configuration-properties)

[](https://coveralls.io/github/siberia-projects/siberia-configuration-properties?branch=main)
## What is it?
Siberia-configuration-properties is a library which provides a convenient way of
parsing a configuration file with replacing environment variables with real and separation
a parsed data by small configs
## Why?
When I parse a configuration file I want to see 2 things:
- I can simply type a declaration of an environment variable in the file
and I will be sure this variable will be parsed automatically
- I can use only a part of a configuration
When I dived into the internet for looking something similar, I found everything
but not what I wanted to see: Or it was 1 structure for all configuration, or environment
variables were not parsed, or I was forced to provide additional structures which were useless,
or the stars didn't align well etc
Based on the mentioned above this library has the right to life
## How to download?
```console
john@doe-pc:~$ go get github.com/siberia-projects/siberia-configuration-properties
```
## How to use?
Comparing with other libraries it may look a bit complicated, but it's not
All you need is to create a couple of tools, declare your data model and
parse the config into the model using the tools:
- Declare a structure in a way it implements the **Properties** interface
(it provides a starting point where your data really begins (could be empty - which literally means
"all"))
- Read your configuration file a **ReadConfiguration(ConfigurationPath)** method
- (Optional) Create a **SimpleSeparator**
- Create an instance of your data model
- Call **Configuration.WriteTo(Properties)** method or use the **Separator.Separate(Configuration, Properties)**
## Examples
```yaml
my:
custom:
properties:
headers:
- key: Cache-Control
value: ${CACHE_CONTROL:no-cache}
- key: Content-Type
value: application/json
not:
my:
properties:
supportsHttps: true
```
```go
package main
import (
"fmt"
"github.com/siberia-projects/siberia-configuration-properties/pkg/configuration"
)
const (
configFilepath = "path/to/config.yaml"
)
type CustomProperties struct {
Headers []Header
}
type Header struct {
Key string
Value string
}
func (properties *CustomProperties) GetPrefix() string {
return "my.custom.properties"
}
func (properties *CustomProperties) String() string {
return fmt.Sprintf("%#v", properties)
}
type NotMyProperties struct {
SupportsHttps bool
}
func (properties *NotMyProperties) GetPrefix() string {
return "not.my.properties"
}
func (properties *NotMyProperties) String() string {
return fmt.Sprintf("%#v", properties)
}
func main() {
configurationInstance, err := configuration.ReadConfiguration(configFilepath)
if err != nil {
panic(err.Error())
}
customProperties := &CustomProperties{}
notMyProperties := &NotMyProperties{}
err = configurationInstance.WriteTo(customProperties)
if err != nil {
panic(err.Error())
}
err = configurationInstance.WriteTo(notMyProperties)
if err != nil {
panic(err.Error())
}
customPropertiesString := customProperties.String()
notMyPropertiesString := notMyProperties.String()
println(customPropertiesString)
println(notMyPropertiesString)
}
```
```text
Result:
&main.CustomProperties{Headers:[]main.Header{main.Header{Key:"Cache-Control", Value:"no-cache"}, main.Header{Key:"Content-Type", Value:"application/json"}}}
&main.NotMyProperties{SupportsHttps:false}
```