summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorhorus_arch2015-07-27 22:24:09 +0200
committerhorus_arch2015-07-27 22:52:09 +0200
commitebfb0155ac6a4fba93ebb846878ca211e9384226 (patch)
tree0f9faa9e9afed9ce92dbd8e5cac796a833f86cd5 /main.go
downloadngxconf-ebfb0155ac6a4fba93ebb846878ca211e9384226.tar.gz
Initial commit.HEADmaster
Diffstat (limited to 'main.go')
-rw-r--r--main.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..26c0795
--- /dev/null
+++ b/main.go
@@ -0,0 +1,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)
+ }
+}