GithubHelp home page GithubHelp logo

arielsrv / go-config Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 170 KB

minimal config files inspired by netflix archaius

License: GNU General Public License v3.0

Go 79.70% Dockerfile 15.17% Shell 5.13%
archaius config golang netflix godotenv

go-config's Introduction

Go Config

Configuration

Coverage

go get github.com/arielsrv/go-config

example

package main

import (
	"log"
	"log/slog"
	"os"

	"github.com/arielsrv/go-config/env"
)

func init() {
	err := os.Setenv("ENV", "dev")
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	// config/config.yaml by default
	// native text logger | warn level by default
	env.SetConfigPath("config")
	env.SetConfigFile("config.yaml")
	env.SetLogger(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
		Level: slog.LevelDebug,
	})))

	err := env.Load()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("VAR: %s", os.Getenv("message"))
	log.Printf("ENV: %s", env.GetEnv())
	log.Printf("SCOPE: %s", env.GetScope())
	log.Printf("NOT FOUND: %s", env.Get("MISSING"))
}

Environment configuration is based on Archaius Config, you should use a similar folder structure. SCOPE env variable in remote environment is required

├── config
│	├── config.yaml 				(shared config)
│	├── local
│	│	└── config.yaml             (for local development)
│	└── remote                      (for remote environment)
│		├── config.yaml             (base shared config by env)
│		├── dev.config.yaml
│		├── prod.config.yaml
│		└── {env}.config.yaml

The SDK provides a simple configuration hierarchy

  • config/config.properties (shared config)
  • config/{scope}/config.properties (override shared config by environment)
  • config/{scope}/{env}.config.properties (override env and shared config by scope)

Example test.pets-api.internal.com

└── config
    ├── config.yml                              3th (third)
    └── local
        └── config.yml                          ignored
    └── remote
        └── config.yml (base config)            2nd (second)
        └── test.config.yml (base config)       1st (first)
    ```

    * 1st (first)   remote/test.config.yml
    * 2nd (second)  remote/config.yml
    * 3th (third)   config.yml
INFO go-config: append ../my-app/config/remote/test.config.yaml ...
INFO go-config: append ../my-app/config/remote/config.yaml ...
INFO go-config: append ../my-app/config/config.yaml ...
INFO go-config: ENV: test, SCOPE: remote
ENV: test
SCOPE: remote
WARN go-config: config with name SOME.CONFIG not found

go-config's People

Contributors

actions-user avatar arielpineiro avatar arielsrv avatar dependabot[bot] avatar

Watchers

 avatar

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.