-
Notifications
You must be signed in to change notification settings - Fork 4
/
ngrok.go
48 lines (38 loc) · 1.04 KB
/
ngrok.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gryphon
import (
"io/ioutil"
"net/http"
"github.com/savaki/jq"
"github.com/whiterabb17/gryphon/variables"
)
// StartNgrokTCP exposes a TCP server on a given port.
func StartNgrokTCP(port int) error {
_, err := CmdOut(F("ngrok tcp %d", port))
return err
}
// StartNgrokHTTP exposes a web server on a given port.
func StartNgrokHTTP(port int) error {
_, err := CmdOut(F("ngrok http %d", port))
return err
}
// GetNgrokURL returns the URL of the Ngrok tunnel exposing the machine.
func GetNgrokURL() (string, error) {
local_url := "http://localhost:4040/api/tunnels"
resp, err := http.Get(local_url)
if err != nil {
return "", err
}
defer resp.Body.Close()
json, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
jq_op_1, _ := jq.Parse(".tunnels")
json_1, _ := jq_op_1.Apply(json)
jq_op_2, _ := jq.Parse(".[0]")
json_2, _ := jq_op_2.Apply(json_1)
jq_op_3, _ := jq.Parse(".public_url")
json_3, _ := jq_op_3.Apply(json_2)
json_sanitized := variables.FullRemove(string(json_3), `"`)
return json_sanitized, nil
}