cli can pass -p 10_000
parent
49064f1ea2
commit
c7375949c2
|
|
@ -6,10 +6,12 @@ import (
|
|||
"os"
|
||||
"show-rss/src/cleanup"
|
||||
"show-rss/src/db"
|
||||
"show-rss/src/server"
|
||||
)
|
||||
|
||||
type Flags struct {
|
||||
DB string
|
||||
DB string
|
||||
Port int
|
||||
}
|
||||
|
||||
func NewFlags(args []string) (Flags, error) {
|
||||
|
|
@ -17,6 +19,7 @@ func NewFlags(args []string) (Flags, error) {
|
|||
|
||||
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||
fs.StringVar(&result.DB, "db", "/tmp/f.db", "path to sqlite.db")
|
||||
fs.IntVar(&result.Port, "p", 10_000, "port for http")
|
||||
err := fs.Parse(args)
|
||||
|
||||
return result, err
|
||||
|
|
@ -33,6 +36,8 @@ func Config(ctx context.Context, args []string) (context.Context, func(), error)
|
|||
return ctx, nil, err
|
||||
}
|
||||
|
||||
ctx = server.Inject(ctx, flags.Port)
|
||||
|
||||
return ctx, func() {
|
||||
cleanup.Extract(ctx)()
|
||||
}, nil
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func oneItem(ctx context.Context, feed feeds.Feed, item feeds.Item) error {
|
|||
Item: item,
|
||||
}
|
||||
|
||||
wmethod, wurl, wbody := feed.Webhook()
|
||||
wmethod, wurl, wbody := feed.Webhook(ctx)
|
||||
|
||||
method, err := render(wmethod, arg)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func Main(ctx context.Context) error {
|
||||
return Run(ctx, fmt.Sprintf(":%d", server.Port))
|
||||
return Run(ctx, fmt.Sprintf(":%d", server.Extract(ctx)))
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, listen string) error {
|
||||
|
|
|
|||
|
|
@ -263,11 +263,11 @@ func initDB(ctx context.Context) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (feed Feed) Webhook() (string, string, string) {
|
||||
func (feed Feed) Webhook(ctx context.Context) (string, string, string) {
|
||||
u, _ := url.Parse(feed.Version.WebhookURL)
|
||||
switch u.Scheme {
|
||||
case "vpntor":
|
||||
return "POST", fmt.Sprintf("http://localhost:%d/v1/vpntor", server.Port), fmt.Sprintf(`{
|
||||
return "POST", fmt.Sprintf("http://localhost:%d/v1/vpntor", server.Extract(ctx)), fmt.Sprintf(`{
|
||||
"Magnet": "{{ .Item.Link }}",
|
||||
"Dir": %q,
|
||||
"URL": "https://vpntor.int.bel.blue/transmission/rpc"
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"context"
|
||||
)
|
||||
|
||||
var Port = func() int {
|
||||
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
||||
if port == 0 {
|
||||
port = 10000
|
||||
func Inject(ctx context.Context, port int) context.Context {
|
||||
return context.WithValue(ctx, "server.port", port)
|
||||
}
|
||||
|
||||
func Extract(ctx context.Context) int {
|
||||
v := ctx.Value("server.port")
|
||||
port, ok := v.(int)
|
||||
if !ok {
|
||||
return 10_000
|
||||
}
|
||||
return port
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue