// Webserver
package main

import (
	"flag"
	"fmt"
	"gopkg.in/gcfg.v1"
	"log"
	"net/http"
)

var configFile = flag.String("config", "/etc/bobbi.conf", "INI file for bobbi")

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome, %s!", r.URL.Path[1:])
}

type config struct {
	Main struct {
		Port string
	}
}

func getConfig(filename string) config {
	cfg := new(config)

	err := gcfg.ReadFileInto(cfg, filename)

	if err != nil {
		log.Fatalf("Failed reading config: %s", err)
	}

	return *cfg
}

func main() {
	flag.Parse()
	cfg := getConfig(*configFile)
	port := cfg.Main.Port
	if port == "" {
		port = "8000"
	}

	fmt.Println("Listening on port:", port)
	http.HandleFunc("/", handler)
	http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}

// Webserver
package main

import (
	"fmt"
	"gopkg.in/gcfg.v1"
	"log"
	"net/http"
	"os"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome, %s!", r.URL.Path[1:])
}

type config struct {
	Main struct {
		Port string
	}
}

func getConfig() config {
	cfg := new(config)

	err := gcfg.ReadFileInto(cfg, "./config-example.conf")

	if err != nil {
		log.Fatalf("Failed to parse gcfg data: %s", err)
		os.Exit(1)
	}

	return *cfg
}

func main() {
	cfg := getConfig()
	port := cfg.Main.Port
	if port == "" {
		port = "8000"
	}

	fmt.Println(port)
	http.HandleFunc("/", handler)
	http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
}

--- 
+++ 
@@ -2,12 +2,14 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"gopkg.in/gcfg.v1"
 	"log"
 	"net/http"
-	"os"
 )
+
+var configFile = flag.String("config", "/etc/bobbi.conf", "INI file for bobbi")
 
 func handler(w http.ResponseWriter, r *http.Request) {
 	fmt.Fprintf(w, "Welcome, %s!", r.URL.Path[1:])
@@ -19,27 +21,27 @@
 	}
 }
 
-func getConfig() config {
+func getConfig(filename string) config {
 	cfg := new(config)
 
-	err := gcfg.ReadFileInto(cfg, "./config-example.conf")
+	err := gcfg.ReadFileInto(cfg, filename)
 
 	if err != nil {
-		log.Fatalf("Failed to parse gcfg data: %s", err)
-		os.Exit(1)
+		log.Fatalf("Failed reading config: %s", err)
 	}
 
 	return *cfg
 }
 
 func main() {
-	cfg := getConfig()
+	flag.Parse()
+	cfg := getConfig(*configFile)
 	port := cfg.Main.Port
 	if port == "" {
 		port = "8000"
 	}
 
-	fmt.Println(port)
+	fmt.Println("Listening on port:", port)
 	http.HandleFunc("/", handler)
 	http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
 }
Read from a specified config file.
