diff --git a/README.md b/README.md index f6eeaa9..6eb7c58 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,6 @@ machine api.github.com Usage of github-events: -endpoint string Set custom server endpoint - -forward string - Send events to HTTP server running on this port -only string Filter events by type -pretty @@ -84,12 +82,12 @@ github-events -only=push github-events -save -pretty ``` -You can also forward event data to a local HTTP server: +You can also forward event data to a local HTTP endpoint: ```bash # lets say you have an app running on localhost:5000 # forward requests by running this command -github-events -forward=5000 +github-events http://locahost:5000/events ``` While the event proxy server is hosted on Heroku, you can run the server locally: diff --git a/main.go b/main.go index 1c1db0d..228a111 100644 --- a/main.go +++ b/main.go @@ -118,10 +118,8 @@ func startWebsocketPing(conn *websocket.Conn, done chan bool) { } } -func forwardMessage(port string, message Message) { - url := fmt.Sprintf("http://localhost:%v", port) +func forwardMessage(url string, message Message) { body := bytes.NewReader(message.Payload) - req, err := http.NewRequest(http.MethodPost, url, body) if err != nil { log.Println("Request setup error:", err) @@ -159,15 +157,18 @@ func main() { var pretty bool var saveFiles bool var endpoint string - var forwardPort string + var forwardURL string - flag.StringVar(&forwardPort, "forward", "", "Send events to HTTP server running on this port") flag.StringVar(&filterType, "only", "", "Filter events by type") flag.BoolVar(&pretty, "pretty", false, "Pretty print JSON") flag.BoolVar(&saveFiles, "save", false, "Save each event into separate file") flag.StringVar(&endpoint, "endpoint", "", "Set custom server endpoint") flag.Parse() + if len(os.Args) > 1 { + forwardURL = os.Args[1] + } + if endpoint != "" { proxyEndpoint = endpoint reEventHook = regexp.MustCompile(proxyEndpoint + `/(.*)`) @@ -287,8 +288,8 @@ func main() { } } - if forwardPort != "" { - go forwardMessage(forwardPort, message) + if forwardURL != "" { + go forwardMessage(forwardURL, message) } } }()