-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (78 loc) · 1.74 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
87
88
89
90
91
92
93
94
95
// /home/krylon/go/src/ticker/main.go
// -*- mode: go; coding: utf-8; -*-
// Created on 01. 02. 2021 by Benjamin Walkenhorst
// (c) 2021 Benjamin Walkenhorst
// Time-stamp: <2023-08-27 20:48:29 krylon>
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/blicero/ticker/common"
"github.com/blicero/ticker/reader"
"github.com/blicero/ticker/web"
)
func main() {
fmt.Printf("%s %s, built on %s\n",
common.AppName,
common.Version,
common.BuildStamp)
var (
err error
baseDir string
rdr *reader.Reader
srv *web.Server
msgq = make(chan string, 5)
)
flag.StringVar(
&baseDir,
"basedir",
common.BaseDir,
"The directory to store application-specific data in.",
)
flag.Parse()
if baseDir != common.BaseDir {
fmt.Printf("Set BaseDir to %q\n", baseDir)
common.BaseDir = baseDir
}
if err = common.InitApp(); err != nil {
fmt.Fprintf(
os.Stderr,
"Cannot initialize directory %s: %s\n",
common.BaseDir,
err.Error(),
)
os.Exit(1)
}
if rdr, err = reader.New(msgq); err != nil {
fmt.Fprintf(
os.Stderr,
"Cannot create RSS Reader: %s\n",
err.Error())
os.Exit(1)
} else if srv, err = web.Create(":7777", true); err != nil {
fmt.Fprintf(
os.Stderr,
"Cannnot create web server: %s\n",
err.Error())
os.Exit(1)
}
go forwardMsg(msgq, srv)
go rdr.Loop()
go srv.ListenAndServe()
var sigQ = make(chan os.Signal, 1)
signal.Notify(sigQ, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
sig := <-sigQ
fmt.Printf("Quitting on signal %s\n", sig)
rdr.StopQ <- 1
srv.Close()
os.Exit(0)
} // func main()
func forwardMsg(q <-chan string, srv *web.Server) {
for {
var m = <-q
srv.SendMessage(m)
}
} // func forwardMsg(q <-chan string, srv *web.Server)