func replaceEnvVars(input []byte) ([]byte, error) {
	var offset int
	for {
		begin := bytes.Index(input[offset:], spanOpen)
		if begin < 0 {
			break
		}
		begin += offset  
		end := bytes.Index(input[begin+len(spanOpen):], spanClose)
		if end < 0 {
			break
		}
		end += begin + len(spanOpen)  
		envString := input[begin+len(spanOpen) : end]
		if len(envString) == 0 {
			offset = end + len(spanClose)
			continue
		}
		envParts := strings.SplitN(string(envString), envVarDefaultDelimiter, 2)
		envVarValue, found := os.LookupEnv(envParts[0])
		if !found && len(envParts) == 2 {
			envVarValue = envParts[1]
		}
		envVarBytes := []byte(envVarValue)
		input = append(input[:begin],
			append(envVarBytes, input[end+len(spanClose):]...)...)
		offset = begin + len(envVarBytes)
	}
	return input, nil
}
replaceEnvVars replaces all occurrences of environment variables.
package caddyfile
import (
	"bytes"
	"fmt"
	"io"
	"log"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"github.com/caddyserver/caddy/v2"
)
func Parse(filename string, input []byte) ([]ServerBlock, error) {
	tokens, err := allTokens(filename, input)
	if err != nil {
		return nil, err
	}
	p := parser{
		Dispenser: NewDispenser(tokens),
		importGraph: importGraph{
			nodes: make(map[string]bool),
			edges: make(adjacency),
		},
	}
	return p.parseAll()
}