From 3364f3e476f10b615b9b3135464903e9488c8824 Mon Sep 17 00:00:00 2001 From: "maxim.manuylov" Date: Fri, 2 Dec 2016 11:20:41 +0300 Subject: [PATCH] create directory for unix socket --- jongleur/jongleur.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/jongleur/jongleur.go b/jongleur/jongleur.go index 45e8145..da28125 100644 --- a/jongleur/jongleur.go +++ b/jongleur/jongleur.go @@ -9,6 +9,8 @@ import ( "io" "log" "net" + "os" + "path/filepath" "strings" "time" ) @@ -52,7 +54,7 @@ func Run(config *Config, logger *log.Logger) error { } }() - listener, err := net.Listen(config.SplitNetAddr()) + listener, err := config.listen() if err != nil { return err } @@ -131,3 +133,15 @@ func (config *Config) SplitNetAddr() (string, string) { return config.Listen[:atPos], config.Listen[atPos + 1:] } } + +func (config *Config) listen() (net.Listener, error) { + network, addr := config.SplitNetAddr() + + if strings.HasPrefix(network, "unix") { + if err := os.MkdirAll(filepath.Dir(addr), 0755); err != nil { + return nil, err + } + } + + return net.Listen(network, addr) +}