-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (45 loc) · 1.25 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
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/provider"
lts "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/lts/v2"
)
var stdout = log.New(os.Stdout, "", 0)
func main() {
ctx, cancel := context.WithCancel(context.Background())
auth, err := provider.BasicCredentialEnvProvider().GetCredentials()
if err != nil {
log.Fatalf("[FATAL] fail instantiating credentials: %v\nSee https://github.com/huaweicloud/huaweicloud-sdk-go-v3#241-environment-variables-top.", err)
}
ltsc := lts.NewLtsClient(lts.LtsClientBuilder().
WithCredential(auth).
WithRegion(regionFromEnv()).
Build())
errc := make(chan error)
go func() {
mgr := LogstreamManager{
client: ltsc,
streams: map[LogstreamID]*Logstream{},
queue: make(chan *Logstream),
maxEndFromNow: maxEndFromNow,
maxFetchRange: maxFetchRange,
minFetchRange: minFetchRange,
maxLag: maxLag,
}
errc <- mgr.Start(ctx, streamRoutine)
}()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
select {
case <-sigs:
cancel()
case err := <-errc:
if err != nil {
log.Fatalf("[FATAL] fail to get initial log groups and streams: %v\n", err)
}
}
}