-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
43 lines (40 loc) · 938 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
package main
import (
"flag"
telemetry "github.com/anacrolix/telemetry/go"
"log/slog"
"net/url"
"os"
)
func main() {
err := mainErr()
if err != nil {
slog.Error("error in main", "err", err)
os.Exit(1)
}
}
func mainErr() (err error) {
// Can switch to http for example to demonstrate POST.
scheme := flag.String("scheme", "ws", "telemetry scheme")
urlStr := flag.String("url", "", "telemetry url")
flag.Parse()
_url := &url.URL{
Scheme: *scheme,
// Should derive this from the default port somewhere.
Host: "localhost:4318",
}
if *urlStr != "" {
_url, err = url.Parse(*urlStr)
if err != nil {
return err
}
}
telemetryWriter := telemetry.Writer{
Url: _url,
}
jsonHandler := slog.NewJSONHandler(&telemetryWriter, nil)
logger := slog.New(jsonHandler)
logger.Info("hi mom")
// TODO: This message could be written to the streams table.
return telemetryWriter.Close("i have to go now. goodbye!")
}