diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9234918 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Fabricio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 8bcd76b..fb8e097 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ in favor of the dashboard. However, you can change the dashboard's name with `-d ##### Preview -![dashboard](https://i.imgur.com/V2mEUfZ.png) +![dashboard](https://i.imgur.com/YTukk5J.png) ## Building diff --git a/capture.go b/capture.go index 88c8edf..5113602 100644 --- a/capture.go +++ b/capture.go @@ -38,6 +38,7 @@ type CaptureMetadata struct { type CaptureDump struct { Request string `json:"request"` Response string `json:"response"` + Curl string `json:"curl"` } func (c *Capture) Metadata() CaptureMetadata { diff --git a/dashboard.go b/dashboard.go index cdcdb1b..bf4b8ff 100644 --- a/dashboard.go +++ b/dashboard.go @@ -193,6 +193,7 @@ const dashboardHTML = `
+
{{request}}
@@ -225,6 +226,7 @@ const dashboardHTML = ` $http.get(path).then(r => { $scope.request = r.data.request; $scope.response = r.data.response; + $scope.curl = r.data.curl; }); } @@ -252,6 +254,19 @@ const dashboardHTML = ` return $scope[name].indexOf('Content-Type: application/json') != -1; } + $scope.canGenerateCurl = () => { + return $scope['request'] != null; + } + + $scope.generateCurl = () => { + let e = document.createElement('textarea'); + e.value = $scope.curl; + document.body.appendChild(e); + e.select(); + document.execCommand('copy'); + document.body.removeChild(e); + } + $scope.prettifyBody = key => { let regex = /\n([\{\[](.*\s*)*[\}\]])/; let data = $scope[key]; diff --git a/go.mod b/go.mod index 3d54f60..eeca8ba 100644 --- a/go.mod +++ b/go.mod @@ -4,4 +4,5 @@ require ( github.com/googollee/go-engine.io v0.0.0-20180829091931-e2f255711dcb // indirect github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49 github.com/gorilla/websocket v1.4.0 // indirect + github.com/ofabricio/curl v0.1.0 ) diff --git a/go.sum b/go.sum index 12c5cff..fc6a78f 100644 --- a/go.sum +++ b/go.sum @@ -4,3 +4,5 @@ github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49 h1:vKXGRzlh github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49/go.mod h1:ftBGBMhSYToR5oV4ImIPKvAIsNaTkLC+tTvoNafqxlQ= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/ofabricio/curl v0.1.0 h1:ntXuBULZLQmCdAMxZNXzse069DbAKb/Flxe/2uuZuNk= +github.com/ofabricio/curl v0.1.0/go.mod h1:RtLkZIOgxjm+l0jdj04lrETzu8u5SmPPdLyGAuC4ukg= diff --git a/main.go b/main.go index 97b6d9f..9a5d2e4 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/googollee/go-socket.io" + "github.com/ofabricio/curl" ) var dashboardSocket socketio.Socket @@ -156,7 +157,11 @@ func dump(c *Capture) CaptureDump { if err != nil { fmt.Printf("could not dump response: %v\n", err) } - return CaptureDump{Request: string(reqDump), Response: string(resDump)} + strcurl, err := curl.New(c.Req) + if err != nil { + fmt.Printf("could not convert request to curl: %v\n", err) + } + return CaptureDump{Request: string(reqDump), Response: string(resDump), Curl: strcurl} } func dumpRequest(req *http.Request) ([]byte, error) {