summaryrefslogtreecommitdiffstats
path: root/matterhook/matterhook.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-07-11 23:22:56 +0200
committerWim <wim@42.be>2016-07-11 23:22:56 +0200
commitced371bece6bcdadba3f61bb70f5f5aa24bc3c23 (patch)
tree87f6df50e5a6d4428d3fbbfb2f197575c6b86eda /matterhook/matterhook.go
parenta87cac1982c0869fca161b0c417da3cd13742ce9 (diff)
downloadmatterbridge-msglm-ced371bece6bcdadba3f61bb70f5f5aa24bc3c23.tar.gz
matterbridge-msglm-ced371bece6bcdadba3f61bb70f5f5aa24bc3c23.tar.bz2
matterbridge-msglm-ced371bece6bcdadba3f61bb70f5f5aa24bc3c23.zip
Add port to BindAddress
Diffstat (limited to 'matterhook/matterhook.go')
-rw-r--r--matterhook/matterhook.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/matterhook/matterhook.go b/matterhook/matterhook.go
index f30d44b7..ef983e7b 100644
--- a/matterhook/matterhook.go
+++ b/matterhook/matterhook.go
@@ -10,8 +10,8 @@ import (
"io"
"io/ioutil"
"log"
+ "net"
"net/http"
- "strconv"
)
// OMessage for mattermost incoming webhook. (send to mattermost)
@@ -51,7 +51,6 @@ type Client struct {
// Config for client.
type Config struct {
- Port int // Port to listen on.
BindAddress string // Address to listen on
Token string // Only allow this token from Mattermost. (Allow everything when empty)
InsecureSkipVerify bool // disable certificate checking
@@ -61,10 +60,10 @@ type Config struct {
// New Mattermost client.
func New(url string, config Config) *Client {
c := &Client{Url: url, In: make(chan IMessage), Out: make(chan OMessage), Config: config}
- if c.Port == 0 {
- c.Port = 9999
+ _, _, err := net.SplitHostPort(c.BindAddress)
+ if err != nil {
+ log.Fatalf("incorrect bindaddress %s", c.BindAddress)
}
- c.BindAddress += ":"
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
}
@@ -79,8 +78,8 @@ func New(url string, config Config) *Client {
func (c *Client) StartServer() {
mux := http.NewServeMux()
mux.Handle("/", c)
- log.Printf("Listening on http://%v:%v...\n", c.BindAddress, c.Port)
- if err := http.ListenAndServe((c.BindAddress + strconv.Itoa(c.Port)), mux); err != nil {
+ log.Printf("Listening on http://%v...\n", c.BindAddress)
+ if err := http.ListenAndServe(c.BindAddress, mux); err != nil {
log.Fatal(err)
}
}