diff --git a/config.yaml b/config.yaml
deleted file mode 100644
index 34ee96b..0000000
--- a/config.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-server:
- port: "3000"
diff --git a/example.config.yml b/example.config.yml
new file mode 100644
index 0000000..c861b6b
--- /dev/null
+++ b/example.config.yml
@@ -0,0 +1,6 @@
+server:
+ port: "3000"
+
+site:
+ title: "Cat Gallery"
+ header: "Cat Gallery"
diff --git a/main.go b/main.go
index 592de8f..81b76ba 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,8 @@ import (
var images []string
var logger = logrus.New()
+var title string
+var header string
var port string
// Cache for image list, it should expire every 10 minutes
@@ -35,7 +37,7 @@ var tmpl = template.Must(template.New("index").Parse(`
- Image Gallery
+ {{.Title}}
- Image Gallery
+ {{.Header}}
{{range $index, $img := .Images}}
@@ -79,9 +81,8 @@ func init() {
// Set the log level (info, warning, error, etc.)
logger.SetLevel(logrus.InfoLevel)
-}
-func main() {
+ // Load config
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.AddConfigPath(".") // path to look for the config file in
@@ -93,6 +94,12 @@ func main() {
port = viper.GetString("server.port")
images = getImages()
+ // Load site settings (title and header)
+ title = viper.GetString("site.title")
+ header = viper.GetString("site.header")
+}
+
+func main() {
// Add request logging middleware
mux := http.NewServeMux()
mux.HandleFunc("/", homeHandler)
@@ -136,11 +143,18 @@ func getImages() []string {
return images
}
+
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
tmpl.Execute(w, struct {
+ Title string
+ Header string
Images []string
- }{Images: getCachedImages()})
+ }{
+ Title: title,
+ Header: header,
+ Images: getCachedImages(),
+ })
}
func idHandler(w http.ResponseWriter, r *http.Request) {