package statsdurl

import (
	"net/url"
	"os"

	"github.com/quipo/statsd"
)

func Connect(prefix string) (*statsd.StatsdClient, error) {
	return ConnectToURL(os.Getenv("STATSD_URL"))
}

func ConnectToURL(s string, prefix string) (c *statsd.StatsdClient, err error) {
	statsdUrl, err := url.Parse(s)

	if err != nil {
		return statsdUrl, err
	}

	c = statsd.NewStatsdClient(statsdUrl.Host, prefix)
	err = c.CreateSocket()
	return c, err
}

package statsdurl

import (
	"os"
	"fmt"
	"net/url"
	"strings"
	"github.com/quipo/statsd"
)

func Connect() (*statsd.StatsdClient, error) {
	return ConnectToURL(os.Getenv("STATSD_URL"))
}

func ConnectToURL(s string) (c *statsd.StatsdClient, err error) {
	statsdUrl, err := url.Parse(s)

	if err != nil {
		return
	}

	prefix := ""

	if len(statsdUrl.Path) > 1 {
		prefix = strings.TrimPrefix(statsdUrl.Path, "/")
		prefix = fmt.Sprintf("/%v", prefix)
	}

	c = statsd.NewStatsdClient(statsdUrl.Host, prefix)
	err = c.CreateSocket()
	return c, err
}

--- 
+++ 
@@ -1,29 +1,21 @@
 package statsdurl
 
 import (
+	"net/url"
 	"os"
-	"fmt"
-	"net/url"
-	"strings"
+
 	"github.com/quipo/statsd"
 )
 
-func Connect() (*statsd.StatsdClient, error) {
+func Connect(prefix string) (*statsd.StatsdClient, error) {
 	return ConnectToURL(os.Getenv("STATSD_URL"))
 }
 
-func ConnectToURL(s string) (c *statsd.StatsdClient, err error) {
+func ConnectToURL(s string, prefix string) (c *statsd.StatsdClient, err error) {
 	statsdUrl, err := url.Parse(s)
 
 	if err != nil {
-		return
-	}
-
-	prefix := ""
-
-	if len(statsdUrl.Path) > 1 {
-		prefix = strings.TrimPrefix(statsdUrl.Path, "/")
-		prefix = fmt.Sprintf("/%v", prefix)
+		return statsdUrl, err
 	}
 
 	c = statsd.NewStatsdClient(statsdUrl.Host, prefix)
Allow prefix to be set by each client
