func (t *Template) Write(conf config.TemplateConfig) ([]byte, error) {
	tmplBuf := t.bp.Get()
	defer t.bp.Put(tmplBuf)
	outCmdBuf := t.bp.Get()
	defer t.bp.Put(outCmdBuf)
	if glog.V(3) {
		b, err := json.Marshal(conf)
		if err != nil {
			glog.Errorf("unexpected error: %v", err)
		}
		glog.Infof("NGINX configuration: %v", string(b))
	}
	err := t.tmpl.Execute(tmplBuf, conf)
	if err != nil {
		return nil, err
	}
	cmd := exec.Command("/ingress-controller/clean-nginx-conf.sh")
	cmd.Stdin = tmplBuf
	cmd.Stdout = outCmdBuf
	if err := cmd.Run(); err != nil {
		glog.Warningf("unexpected error cleaning template: %v", err)
		return tmplBuf.Bytes(), nil
	}
	return outCmdBuf.Bytes(), nil
}
Write populates a buffer using a template with NGINX configuration
and the servers and upstreams created by Ingress rules
package template
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"math/rand"
	"net"
	"net/url"
	"os"
	"os/exec"
	"strconv"
	"strings"
	text_template "text/template"
	"time"
	"github.com/golang/glog"
	"github.com/pkg/errors"
	"github.com/NCCloud/fluid/internal/file"
	"github.com/NCCloud/fluid/internal/ingress"
	"github.com/NCCloud/fluid/internal/ingress/annotations/ratelimit"
	"github.com/NCCloud/fluid/internal/ingress/controller/config"
	ing_net "github.com/NCCloud/fluid/internal/net"
	extensions "k8s.io/api/extensions/v1beta1"
	"k8s.io/apimachinery/pkg/util/sets"
)
const (
	slash         = "/"
	nonIdempotent = "non_idempotent"
	defBufferSize = 65535
)
type Template struct {
	tmpl *text_template.Template
	bp *BufferPool
}
func NewTemplate(file string, fs file.Filesystem) (*Template, error) {
	data, err := fs.ReadFile(file)
	if err != nil {
		return nil, errors.Wrapf(err, "unexpected error reading template %v", file)
	}
	tmpl, err := text_template.New("nginx.tmpl").Funcs(funcMap).Parse(string(data))
	if err != nil {
		return nil, err
	}
	return &Template{
		tmpl: tmpl,
		bp:   NewBufferPool(defBufferSize),
	}, nil
}