github.com/unionj-cloud/go-doudou@v1.3.8-0.20221011095552-0088008e5b31/framework/http/config/handlerimpl.go (about)

     1  package registry
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/unionj-cloud/go-doudou/toolkit/stringutils"
     6  	"net/http"
     7  	"os"
     8  	"strings"
     9  )
    10  
    11  // ConfigHandlerImpl define implementation for ConfigHandler
    12  type ConfigHandlerImpl struct {
    13  }
    14  
    15  // GetConfig returns all environment variables
    16  func (receiver *ConfigHandlerImpl) GetConfig(_writer http.ResponseWriter, _req *http.Request) {
    17  	pre := _req.FormValue("pre")
    18  	var builder strings.Builder
    19  	for _, pair := range os.Environ() {
    20  		if stringutils.IsEmpty(pre) || strings.HasPrefix(pair, pre) {
    21  			builder.WriteString(fmt.Sprintf("%s\n", pair))
    22  		}
    23  	}
    24  	_writer.Header().Set("Content-Type", "text/plain; charset=utf-8")
    25  	_writer.Write([]byte(builder.String()))
    26  }
    27  
    28  // NewConfigHandler creates new ConfigHandlerImpl
    29  func NewConfigHandler() ConfigHandler {
    30  	return &ConfigHandlerImpl{}
    31  }