-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
87 lines (82 loc) · 2.21 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
package main
import (
"context"
"os"
porter "github.com/tuihub/protos/pkg/librarian/porter/v1"
librarian "github.com/tuihub/protos/pkg/librarian/v1"
"github.com/tuihub/tuihub-go"
"github.com/tuihub/tuihub-go/logger"
"github.com/tuihub/tuihub-rss/internal"
)
// go build -ldflags "-X main.version=x.y.z".
var (
// version is the version of the compiled software.
version string
)
const (
rssServerURLPrefix = "RSS_SERVER_URL_PREFIX"
rssServerHost = "RSS_SERVER_HOST"
rssServerPort = "RSS_SERVER_PORT"
)
func main() {
config := &porter.GetPorterInformationResponse{
BinarySummary: &librarian.PorterBinarySummary{
SourceCodeAddress: "https://github.com/tuihub/tuihub-rss",
BuildVersion: version,
BuildDate: "",
Name: "tuihub-rss",
Version: version,
Description: "",
},
GlobalName: "github.com/tuihub/tuihub-rss",
Region: "",
FeatureSummary: &librarian.FeatureSummary{ //nolint:exhaustruct // no need
FeedSources: []*librarian.FeatureFlag{
{
Id: tuihub.WellKnownToString(librarian.WellKnownFeedSource_WELL_KNOWN_FEED_SOURCE_RSS),
Name: "RSS",
Description: "",
ConfigJsonSchema: tuihub.MustReflectJSONSchema(new(internal.PullRSSConfig)),
},
},
NotifyDestinations: []*librarian.FeatureFlag{
{
Id: tuihub.WellKnownToString(librarian.WellKnownFeedSource_WELL_KNOWN_FEED_SOURCE_RSS),
Name: "RSS",
Description: "",
ConfigJsonSchema: tuihub.MustReflectJSONSchema(new(internal.ServeRSSConfig)),
Extra: map[string]string{
"URLPrefix": os.Getenv(rssServerURLPrefix),
},
},
},
},
ContextJsonSchema: nil,
}
porterServer, err := tuihub.NewPorter(
context.Background(),
config,
internal.NewHandler(),
tuihub.WithAsUser(),
)
if err != nil {
logger.Error(err)
os.Exit(1)
}
rssServer, err := internal.NewServer(porterServer)
if err != nil {
logger.Error(err)
os.Exit(1)
}
go func() {
err = rssServer.Run(os.Getenv(rssServerHost) + ":" + os.Getenv(rssServerPort))
if err != nil {
logger.Error(err)
os.Exit(1)
}
}()
if err = porterServer.Run(); err != nil {
logger.Error(err)
os.Exit(1)
}
}