func UpdateConfigContent(config []byte, replacements []Replacement) []byte {
	for _, rep := range replacements {
		regex := regexp.MustCompile(rep.Key)
		config = regex.ReplaceAll(config, []byte(rep.Value))
	}
	return config
}
UpdateConfigContent replaces placeholders with values from environment variables
package main
import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"regexp"
	"strings"
)
type Replacement struct {
	Key   string
	Value string
}
type EnvVar struct {
	Name     string
	Required bool
	Desc     string
	Default  string
}
func main() {
	var configFile string
	flag.StringVar(&configFile, "c", "/etc/traefik/traefik.toml", "Traefik config file to use, default: /etc/traefik/traefik.toml")
	flag.Parse()
	if _, err := os.Stat(configFile); err != nil {
		fmt.Println("Config file", configFile, "not found")
		os.Exit(1)
	}
	if len(os.Args) <= 1 {
		fmt.Println("You must provide a command to run after entrypoint process completes. You probably want: /traefik")
	}
	replacements, err := BuildReplacementsFromEnv()
	handleError(err)
	configToml, err := ReadTraefikToml(configFile)
	handleError(err)
	configToml = UpdateConfigContent(configToml, replacements)
	err = WriteTraefikToml(configFile, configToml)
	handleError(err)
	runCmd()
	os.Exit(0)
}
func runCmd() {
	executable := os.Args[1]
	args := os.Args[2:]
	cmd := exec.Command(executable, args...)
	cmdStdout, err := cmd.StdoutPipe()
	handleError(err)
	scanner := bufio.NewScanner(cmdStdout)
	go func() {
		for scanner.Scan() {
			fmt.Println(scanner.Text())
		}
	}()
	err = cmd.Start()
	handleError(err)
	err = cmd.Wait()
	handleError(err)
}
func handleError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func ReadTraefikToml(filename string) ([]byte, error) {
	file, err := ioutil.ReadFile(filename)
	if err != nil {
		return []byte{}, fmt.Errorf("Unable to read config file at %s", filename)
	}
	return file, nil
}
func WriteTraefikToml(filename string, contents []byte) error {
	err := ioutil.WriteFile(filename, contents, 0644)
	if err != nil {
		return err
	}
	return nil
}