forked from Safecast/safestream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 1023 Bytes
/
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
// Copyright 2021 Safecast. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
)
func main() {
// Get our external IP address
rsp, err := http.Get("http://checkip.amazonaws.com")
if err != nil {
fmt.Printf("can't get our own IP address: %v\n", err)
os.Exit(-1)
}
defer rsp.Body.Close()
buf, err := ioutil.ReadAll(rsp.Body)
if err != nil {
fmt.Printf("error fetching IP addr: %v\n", err)
os.Exit(-1)
}
thisServerAddressIPv4 = string(bytes.TrimSpace(buf))
// Get HTTP port
if len(os.Args) > 1 {
thisServerPort = ":" + os.Args[1]
}
// Load the template
err = streamInit()
if err != nil {
fmt.Printf("can't load template: %s\n", err)
os.Exit(-1)
}
// Start up the MQTT listener
mqttInit()
// Fire-up the HTTP handler
go httpInboundHandler()
// Sleep indefinitely
for {
time.Sleep(60 * time.Second)
}
}