summaryrefslogtreecommitdiff
path: root/main.go
blob: 26c079586477e06965947fe269d287df80c364a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import (
	"flag"
	"log"
	"os"
	"text/template"
)

//go:generate go run generate/include.go

func main() {
	conf_f := flag.String("config", "config.json", "Path to the configuration file.")
	genConf_f := flag.Bool("genconfig", false, "Generate new configuration file and exit.")
	flag.Parse()

	if *genConf_f {
		GenConfig(*conf_f)
		return
	}

	Conf = NewConfiguration(*conf_f)
	var err error

	if isGenerated() {
		tmpl := template.Must(template.New("ngxconf").Parse(getTemplate()))
		err = tmpl.Execute(os.Stdout, Conf)
	} else {
		tmpl := template.Must(template.New("ngxconf").ParseGlob(Conf.TemplateDir + "/*.tmpl"))
		err = tmpl.ExecuteTemplate(os.Stdout, "server.tmpl", Conf)
	}
	if err != nil {
		log.Fatal(err)
	}
}