improvements/convenience for daemon mode - twitch-go - twitch.tv web application in Go
 (HTM) git clone git://git.codemadness.org/twitch-go
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 139769a621f12341f563609d14c98cf5a67083d8
 (DIR) parent c8815efa5feed2bb13b44286806eb568b3f13b3e
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 17 May 2015 15:00:41 +0200
       
       improvements/convenience for daemon mode
       
       - add -d: chdir to (data)dir.
       - when type is unix domain socket unlink socket before bind.
       - remove old password variable.
       - go fmt
       
       Diffstat:
         M main.go                             |      34 ++++++++++++++++++++-----------
       
       1 file changed, 22 insertions(+), 12 deletions(-)
       ---
 (DIR) diff --git a/main.go b/main.go
       @@ -21,7 +21,7 @@ import (
        type Config struct {
                Addr             string
                AddrType         string
       -        Password         string // password to reload templates etc, see /admin route.
       +        Datadir          string
                TemplateThemeDir string
                TemplatePageDir  string
                StaticContentDir string
       @@ -117,7 +117,7 @@ func (t *Templates) LoadTemplates(path string) (map[string]*template.Template, e
        }
        
        func BadRequest(w http.ResponseWriter, err string) {
       -        http.Error(w, "400 " + err, http.StatusBadRequest)
       +        http.Error(w, "400 "+err, http.StatusBadRequest)
        }
        
        func MakeHandler(h TwitchHandler) func(http.ResponseWriter, *http.Request) {
       @@ -126,12 +126,12 @@ func MakeHandler(h TwitchHandler) func(http.ResponseWriter, *http.Request) {
                        if err == nil {
                                err = h(w, r)
                        } else {
       -                        BadRequest(w, "Can't parse form: " + err.Error())
       +                        BadRequest(w, "Can't parse form: "+err.Error())
                                return
                        }
                        // unhandled error so far: 500
                        if err != nil {
       -                        http.Error(w, "500 " + err.Error(), http.StatusInternalServerError)
       +                        http.Error(w, "500 "+err.Error(), http.StatusInternalServerError)
                        }
                }
        }
       @@ -143,21 +143,31 @@ func usage() {
        
        func main() {
                appconfig = Config{
       -                TemplateThemeDir: "data/templates/themes/default",
       -                TemplatePageDir:  "data/templates/pages/",
       -                StaticContentDir: "data/static/",
       -        }
       -        appconfig.Pidfile = *flag.String("f", "", "PID file")
       -        appconfig.Addr = *flag.String("l", "127.0.0.1:8080", "listen address")
       -        appconfig.Password = *flag.String("p", "", "admin password")
       -        appconfig.AddrType = *flag.String("t", "tcp4", `listen type: "tcp", "tcp4", "tcp6", "unix" or "unixpacket"`)
       +                TemplateThemeDir: "templates/themes/default",
       +                TemplatePageDir:  "templates/pages/",
       +                StaticContentDir: "static/",
       +        }
       +        flag.StringVar(&appconfig.Datadir, "d", "", "Chdir to data directory")
       +        flag.StringVar(&appconfig.Pidfile, "f", "", "PID file")
       +        flag.StringVar(&appconfig.Addr, "l", "127.0.0.1:8080", "listen address")
       +        flag.StringVar(&appconfig.AddrType, "t", "tcp4", `listen type: "tcp", "tcp4", "tcp6", "unix" or "unixpacket"`)
                flag.Parse()
        
       +        // Remove previous UDS if it exists.
       +        if appconfig.AddrType == "unix" {
       +                os.Remove(appconfig.Addr)
       +        }
       +
                l, err := net.Listen(appconfig.AddrType, appconfig.Addr)
                if err != nil {
                        panic(err)
                }
        
       +        err = os.Chdir(appconfig.Datadir)
       +        if err != nil {
       +                panic(err)
       +        }
       +
                // Write PID to pid file.
                if appconfig.Pidfile != "" {
                        pid := os.Getpid()