Added interval flag
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,3 +6,5 @@ h.html
|
||||
*.bak
|
||||
/bin
|
||||
*.exe
|
||||
*secret*
|
||||
mangaGetter
|
||||
|
||||
@@ -26,7 +26,7 @@ func (s *Server) HandleLoginPost(w http.ResponseWriter, r *http.Request) {
|
||||
Value: secret,
|
||||
Path: "/",
|
||||
MaxAge: 3600,
|
||||
Secure: true,
|
||||
Secure: false,
|
||||
HttpOnly: false,
|
||||
SameSite: http.SameSiteLaxMode,
|
||||
})
|
||||
|
||||
@@ -67,7 +67,6 @@ func (s *Server) RegisterRoutes() {
|
||||
s.mux.HandleFunc("/favicon.ico", s.HandleFavicon)
|
||||
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
|
||||
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) StartTLS(port int, certFile, keyFile string) error {
|
||||
@@ -90,7 +89,8 @@ func (s *Server) Start(port int) error {
|
||||
return server.ListenAndServe()
|
||||
}
|
||||
|
||||
func (s *Server) RegisterUpdateMangas(interval time.Duration) {
|
||||
func (s *Server) RegisterUpdater(interval time.Duration) {
|
||||
go func(s *Server) {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(interval):
|
||||
@@ -107,6 +107,7 @@ func (s *Server) RegisterUpdateMangas(interval time.Duration) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}(s)
|
||||
}
|
||||
|
||||
func (s *Server) LoadNext() {
|
||||
|
||||
7
main.go
7
main.go
@@ -25,6 +25,7 @@ var (
|
||||
databaseFlag = flag.String("database", "", "Path to sqlite.db file")
|
||||
certFlag = flag.String("cert", "", "Path to cert file, has to be used in conjunction with key")
|
||||
keyFlag = flag.String("key", "", "Path to key file, has to be used in conjunction with cert")
|
||||
updateIntervalFlag = flag.String("update", "1h", "Interval to update Mangas")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -84,7 +85,13 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
interval, err := time.ParseDuration(*updateIntervalFlag)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.RegisterUpdater(interval)
|
||||
s.RegisterRoutes()
|
||||
|
||||
if *certFlag != "" && *keyFlag != "" {
|
||||
err = s.StartTLS(*portFlag, *certFlag, *keyFlag)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user