| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/json" |
| 5 |
"fmt" |
| 6 |
"io" |
| 7 |
"net/http" |
| 8 |
"os/exec" |
| 9 |
"strings" |
| 10 |
) |
| 11 |
|
| 12 |
var ( |
| 13 |
goobs = "github.com/andreykaipov/goobs" |
| 14 |
root = "" |
| 15 |
|
| 16 |
version = "4.9.1" |
| 17 |
comments = fmt.Sprintf("https://raw.githubusercontent.com/Palakis/obs-websocket/%s/docs/generated/comments.json", version) |
| 18 |
) |
| 19 |
|
| 20 |
func init() { |
| 21 |
var err error |
| 22 |
if root, err = run("git rev-parse --show-toplevel"); err != nil || root == "" { |
| 23 |
panic(err) |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
func main() { |
| 28 |
resp, err := http.Get(comments) |
| 29 |
if err != nil { |
| 30 |
panic(err) |
| 31 |
} |
| 32 |
|
| 33 |
defer resp.Body.Close() |
| 34 |
body, err := io.ReadAll(resp.Body) |
| 35 |
|
| 36 |
data := &Comments{} |
| 37 |
if err := json.Unmarshal(body, data); err != nil { |
| 38 |
panic(err) |
| 39 |
} |
| 40 |
|
| 41 |
fmt.Println("Requests") |
| 42 |
generateRequests(data) |
| 43 |
|
| 44 |
fmt.Println("Events") |
| 45 |
generateEvents(data) |
| 46 |
|
| 47 |
fmt.Println("TypeDefs") |
| 48 |
generateTypeDefs(data) |
| 49 |
} |
| 50 |
|
| 51 |
func run(cmd string) (string, error) { |
| 52 |
output, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput() |
| 53 |
if err != nil { |
| 54 |
return "", fmt.Errorf("Failed running '%s': %s\n\n%s", cmd, err, output) |
| 55 |
} |
| 56 |
|
| 57 |
return strings.TrimSuffix(string(output), "\n"), nil |
| 58 |
} |