yogai/service.go

53 lines
1.1 KiB
Go
Raw Normal View History

2023-05-06 12:08:34 +02:00
package main
import (
2023-05-10 16:28:45 +02:00
"ewintr.nl/yogai/fetcher"
2023-05-06 12:08:34 +02:00
"ewintr.nl/yogai/storage"
"fmt"
"os"
2023-05-08 15:53:06 +02:00
"os/signal"
"time"
2023-05-06 12:08:34 +02:00
)
func main() {
2023-05-08 15:53:06 +02:00
postgres, err := storage.NewPostgres(storage.PostgresInfo{
2023-05-06 12:08:34 +02:00
Host: getParam("POSTGRES_HOST", "localhost"),
Port: getParam("POSTGRES_PORT", "5432"),
User: getParam("POSTGRES_USER", "yogai"),
Password: getParam("POSTGRES_PASSWORD", "yogai"),
Database: getParam("POSTGRES_DB", "yogai"),
2023-05-08 15:53:06 +02:00
})
2023-05-06 12:08:34 +02:00
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2023-05-08 15:53:06 +02:00
videoRepo := storage.NewPostgresVideoRepository(postgres)
2023-05-10 16:28:45 +02:00
mflx := fetcher.NewMiniflux(fetcher.MinifluxInfo{
2023-05-08 15:53:06 +02:00
Endpoint: getParam("MINIFLUX_ENDPOINT", "http://localhost/v1"),
ApiKey: getParam("MINIFLUX_APIKEY", ""),
})
fetchInterval, err := time.ParseDuration(getParam("FETCH_INTERVAL", "1m"))
2023-05-06 12:08:34 +02:00
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2023-05-06 14:03:14 +02:00
2023-05-10 16:28:45 +02:00
fetcher := fetcher.NewFetch(videoRepo, mflx, fetchInterval)
2023-05-08 15:53:06 +02:00
go fetcher.Run()
done := make(chan os.Signal)
signal.Notify(done, os.Interrupt)
<-done
//fmt.Println(err)
2023-05-06 12:08:34 +02:00
}
func getParam(param, def string) string {
if val, ok := os.LookupEnv(param); ok {
return val
}
return def
}