Skip to content

Commit 6610abd

Browse files
committed
v0.2.0
supports `item-count` and `connection-per-feed` custom rss2full options and more command-line arguments remove HTTP `/version`
1 parent 1407cd3 commit 6610abd

5 files changed

Lines changed: 142 additions & 85 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ RSS2Full
33

44
RSS2Full is a free and cross-platform full text RSS hosting service. Automatic transform summary-only RSS feeds into full-text RSS feeds. Read articles in full, in peace, in your favourite news reading application.
55

6-
Notes: current v0.1 allows max items of each feed is 10.
76

87
## Features
98

@@ -14,12 +13,19 @@ Notes: current v0.1 allows max items of each feed is 10.
1413
## Command-line usage
1514

1615
```
16+
rss2full [options...]
17+
1718
Usage:
18-
rss2full [options...]
19+
rss2full -p 80
20+
rss2full -h
1921
2022
Options:
21-
-a <addr> Bind address [default: *]
22-
-p <port> Bind port [default: 8088]
23+
-a <addr> Bind address [default: *]
24+
-p <port> Bind port [default: 8088]
25+
-h, -help Show help
26+
-v, -version Show version
27+
-item-count <num> Define number of news in feed [default: 10]
28+
-connection-per-feed <num> Define number of parallel connections(workers) per feed [default:2]
2329
```
2430

2531
Start the server in a custom port:

‎http.go‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ func (r *responseReader) Close() error {
5555
return r.rc.Close()
5656
}
5757

58-
func Version(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
59-
w.Write([]byte(appVersion))
60-
}
61-
6258
func FullRss(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
6359
source := strings.TrimLeft(p.ByName("feed"), "/")
6460
if source == "" || !(strings.HasPrefix(source, "http://") || strings.HasPrefix(source, "https://")) {
@@ -99,14 +95,14 @@ func FullRss(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
9995
return
10096
}
10197
if len(feed.Items) > 0 {
102-
if len(feed.Items) > 10 {
103-
feed.Items = feed.Items[:10]
98+
if len(feed.Items) > *aItemCount {
99+
feed.Items = feed.Items[:*aItemCount]
104100
}
105101
var wg sync.WaitGroup
106102
c := make(chan struct{})
107103
// create 2 worker to work.
108104
var queue = make(chan *syndfeed.Item, 1)
109-
for n := 0; n < 2; n++ {
105+
for n := 0; n < *aConnectionPerFeed; n++ {
110106
go func() {
111107
for {
112108
select {

‎main.go‎

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎rss2full.go‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"net"
7+
"net/http"
8+
"os"
9+
"strconv"
10+
"syscall"
11+
12+
"github.com/judwhite/go-svc/svc"
13+
"github.com/julienschmidt/httprouter"
14+
"github.com/sirupsen/logrus"
15+
)
16+
17+
var (
18+
Version = "0.2.0"
19+
20+
aAddr = flag.String("a", "", "Bind address")
21+
aPort = flag.Int("p", 8088, "Port to listen")
22+
aVers = flag.Bool("v", false, "Show version")
23+
aVersl = flag.Bool("version", false, "Show version")
24+
aHelp = flag.Bool("h", false, "Show help")
25+
aHelpl = flag.Bool("help", false, "Show help")
26+
aItemCount = flag.Int("item-count", 10, "Define number of items in feed")
27+
aConnectionPerFeed = flag.Int("connection-per-feed", 2, "Define number of parallel connections per feed")
28+
)
29+
30+
const usage = `rss2full %s
31+
32+
Usage:
33+
rss2full -p 80
34+
rss2full -h | -help
35+
rss2full -v | -version
36+
37+
Options:
38+
-a <addr> Bind address [default: *]
39+
-p <port> Bind port [default: 8088]
40+
-h, -help Show help
41+
-v, -version Show version
42+
-item-count <num> Define number of items in feed
43+
-connection-per-feed <num> Define number of parallel connections(workers) per feed
44+
`
45+
46+
type program struct {
47+
quit chan struct{}
48+
}
49+
50+
func (p *program) Init(env svc.Environment) error {
51+
return nil
52+
}
53+
54+
func (p *program) Start() error {
55+
flag.Usage = func() {
56+
fmt.Fprint(os.Stderr, fmt.Sprintf(usage, Version))
57+
}
58+
flag.Parse()
59+
60+
if *aHelp || *aHelpl {
61+
showUsage()
62+
}
63+
if *aVers || *aVersl {
64+
showVersion()
65+
}
66+
67+
port := getPort(*aPort)
68+
addr := *aAddr + ":" + strconv.Itoa(port)
69+
listener, err := net.Listen("tcp", addr)
70+
if err != nil {
71+
return err
72+
}
73+
74+
go func() {
75+
wwwroot := http.Dir("./wwwroot")
76+
fs := http.FileServer(wwwroot)
77+
78+
router := httprouter.New()
79+
router.GET("/feed/*feed", FullRss)
80+
router.Handler("GET", "/assets/*filepath", fs)
81+
router.Handler("GET", "/", fs)
82+
83+
if err := http.Serve(listener, router); err != nil {
84+
logrus.Fatalf("http.Serve got error: %v", err)
85+
}
86+
<-p.quit
87+
listener.Close()
88+
logrus.Info("exit")
89+
}()
90+
logrus.Infof("version: %s", Version)
91+
logrus.Infof("listen on %s \n", addr)
92+
return nil
93+
}
94+
95+
func (p *program) Stop() error {
96+
close(p.quit)
97+
return nil
98+
}
99+
100+
func main() {
101+
logrus.SetOutput(os.Stdout)
102+
prg := &program{
103+
quit: make(chan struct{}),
104+
}
105+
if err := svc.Run(prg, syscall.SIGINT, syscall.SIGTERM); err != nil {
106+
logrus.Fatal(err)
107+
}
108+
}
109+
110+
func getPort(port int) int {
111+
if portEnv := os.Getenv("PORT"); portEnv != "" {
112+
newPort, _ := strconv.Atoi(portEnv)
113+
if newPort > 0 {
114+
port = newPort
115+
}
116+
}
117+
return port
118+
}
119+
120+
func showVersion() {
121+
fmt.Println(Version)
122+
os.Exit(1)
123+
}
124+
125+
func showUsage() {
126+
flag.Usage()
127+
os.Exit(1)
128+
}

‎wwwroot/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class="fab fa-github fa-lg"></i></a>
2323
</div>
2424
<h1 class="mb-3">Full Text RSS Feed <i class="fas fa-rss fa-sm mr-2 rss-icon"></i><label
25-
class="text-small ml-1">v0.1</label></h1>
25+
class="text-small ml-1">v0.2</label></h1>
2626
<div class="tagline">
2727
<p class="mb-2">Fast convert summary RSS feed to full text RSS feed.<br />Read full article in
2828
your RSS reader.</p>

0 commit comments

Comments
 (0)
⌂ 换网址