-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
86 lines (78 loc) · 1.87 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"encoding/json"
"flag"
"github.com/howyoungzhou/golive/inbound"
"github.com/howyoungzhou/golive/outbound"
"github.com/howyoungzhou/golive/process"
"github.com/howyoungzhou/golive/server"
"io/ioutil"
)
type Options struct {
Inbounds []struct {
Id string `json:"id"`
Type string `json:"type"`
Options map[string]interface{}
} `json:"inbounds"`
Outbounds []struct {
Id string `json:"id"`
Type string `json:"type"`
Options map[string]interface{}
} `json:"outbounds"`
Processes []struct {
Id string `json:"id"`
Type string `json:"type"`
Options map[string]interface{}
} `json:"processes"`
Pipes []struct {
In string `json:"in"`
Outs []string `json:"outs"`
} `json:"pipes"`
}
func main() {
configPath := flag.String("config", "config.json", "path to the config file")
flag.Parse()
configData, err := ioutil.ReadFile(*configPath)
if err != nil {
panic(err)
}
options := Options{}
err = json.Unmarshal(configData, &options)
if err != nil {
panic(err)
}
s := server.New()
s.RegisterInbound("udp", inbound.RegisterUDPInbound)
s.RegisterInbound("tcp", inbound.RegisterTCPInbound)
s.RegisterInbound("srt", inbound.RegisterSRTInbound)
s.RegisterOutbound("webrtc", outbound.RegisterWebRTC)
s.RegisterOutbound("srt", outbound.RegisterSRTOutbound)
s.RegisterProcess("exec", process.RegisterExecProcess)
for _, i := range options.Inbounds {
err := s.AddInbound(i.Id, i.Type, i.Options)
if err != nil {
panic(err)
}
}
for _, o := range options.Outbounds {
err := s.AddOutbound(o.Id, o.Type, o.Options)
if err != nil {
panic(err)
}
}
for _, p := range options.Processes {
err := s.AddProcess(p.Id, p.Type, p.Options)
if err != nil {
panic(err)
}
}
for _, pipe := range options.Pipes {
err := s.AddPipe(pipe.In, pipe.Outs)
if err != nil {
panic(err)
}
}
s.Run()
for {
}
}