about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--go.mod7
-rw-r--r--hosted/index.html5
-rw-r--r--src/http/go.mod3
-rw-r--r--src/main.go67
-rw-r--r--src/structs/go.mod3
5 files changed, 85 insertions, 0 deletions
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..c968279
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,7 @@
+module git.darknebu.la/emile/faila
+
+go 1.13
+
+replace git.darknebu.la/emile/faila/src/structs => ./src/structs
+
+replace git.darknebu.la/emile/faila/src/http => ./src/http
diff --git a/hosted/index.html b/hosted/index.html
new file mode 100644
index 0000000..80a2095
--- /dev/null
+++ b/hosted/index.html
@@ -0,0 +1,5 @@
+{{ define "index" }}
+
+index
+
+{{ end }}
\ No newline at end of file
diff --git a/src/http/go.mod b/src/http/go.mod
new file mode 100644
index 0000000..2ebe99f
--- /dev/null
+++ b/src/http/go.mod
@@ -0,0 +1,3 @@
+module git.darknebu.la/emile/faila/src/http
+
+go 1.13
diff --git a/src/main.go b/src/main.go
new file mode 100644
index 0000000..6a1a118
--- /dev/null
+++ b/src/main.go
@@ -0,0 +1,67 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"net/http"
+	"strings"
+
+	"git.darknebu.la/emile/corona-metrics/src/structs"
+	"github.com/sirupsen/logrus"
+	"github.com/spf13/viper"
+)
+
+func main() {
+	initConfig()
+	initLogging()
+
+	go ExitHandler()
+
+	http.Serve()
+}
+
+// initialize the config (config.yml)
+func initConfig() {
+	// parse the config
+	viper.SetConfigName("config")
+	viper.AddConfigPath(".")
+	viper.AutomaticEnv()
+
+	// Fix nested keys don't work with .
+	viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+
+	// read the config
+	err := viper.ReadInConfig()
+	if err != nil {
+		panic(fmt.Errorf("Fatal error config file: %s", err))
+	}
+
+	// unmarshal the config
+	var conf structs.Configuration
+	err = viper.Unmarshal(&conf)
+	if err != nil {
+		log.Fatalf("unable to decode into struct, %v", err)
+	}
+}
+
+// Initialize the loglevel using the value given in the config
+func initLogging() {
+
+	switch viper.GetString("verbose.level") {
+	case "1":
+		logrus.SetLevel(logrus.PanicLevel)
+	case "2":
+		logrus.SetLevel(logrus.FatalLevel)
+	case "3":
+		logrus.SetLevel(logrus.ErrorLevel)
+	case "4":
+		logrus.SetLevel(logrus.WarnLevel)
+	case "5":
+		logrus.SetLevel(logrus.InfoLevel)
+	case "6":
+		logrus.SetLevel(logrus.DebugLevel)
+	case "7":
+		logrus.SetLevel(logrus.TraceLevel)
+	}
+
+}
diff --git a/src/structs/go.mod b/src/structs/go.mod
new file mode 100644
index 0000000..886a426
--- /dev/null
+++ b/src/structs/go.mod
@@ -0,0 +1,3 @@
+module git.darknebu.la/emile/faila/src/structs
+
+go 1.13