Created
January 17, 2016 09:47
-
-
Save josdirksen/fc1ad9eb86e395bd1f8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"github.com/josdirksen/slackproxy/config" | |
"github.com/josdirksen/slackproxy/handlers" | |
"log" | |
"net/http" | |
) | |
// setup the listener, with a config passed in. | |
func GetConfigListener(config *config.Configuration) func(http.ResponseWriter, *http.Request) { | |
return func(w http.ResponseWriter, req *http.Request) { | |
// get the contents from the request body, convert it to a command | |
req.ParseForm() | |
cmdToExecute := handlers.ParseInput(req.Form) | |
// now check whether the token is valid | |
if config.Token == cmdToExecute.Token { | |
// execute the command | |
handler := handlers.GetHandler("docker", config) | |
handler.HandleCommand(cmdToExecute, w) | |
} else { | |
w.WriteHeader(406) | |
} | |
} | |
} | |
func StartListening(config *config.Configuration) { | |
http.HandleFunc("/handleSlackCommand", GetConfigListener(config)) | |
err := http.ListenAndServe(":9000", nil) | |
if err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
} | |
} | |
func main() { | |
var configLocation = flag.String("config", "config.json", "specify the config file") | |
flag.Parse() | |
// first parse the config | |
config.ParseConfig(*configLocation) | |
// setup the handler that listens to 9000 | |
StartListening(config.GetConfig()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment