Skip to content
@go-cnfg

go-cnfg

Dead simple config handling

Quick start - More info at go-cnfg.github.io/website

package main

import (
	"encoding/json"
	"log"
	"time"

	"github.com/go-cnfg/cnfg"
	"github.com/go-cnfg/validator"
)

type Config struct {
	Addr    string        `usage:"address to listen on" validate:"required,hostname_port"`
	Timeout time.Duration `usage:"request timeout" validate:"min=1s"`
	Debug   bool          `usage:"enable debug logging"`
}

func main() {
	defaults := Config{
		Addr:    ":8080",
		Timeout: 5 * time.Second,
	}

	cfg := cnfg.MustParse(defaults,
		cnfg.File(json.Unmarshal, "/etc/app/config.json"),
		cnfg.Env("APP"),
		cnfg.Flags(),
		validator.Validate(),
	)

	log.Printf("%+v", cfg)
}

Pinned Loading

  1. cnfg cnfg Public

    Dead simple zero dependency config parser for Go

    Go 2

  2. validator validator Public

    go-playground/validator as a parser for cnfg

    Go

Repositories

Showing 4 of 4 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…