|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"net/http"
|
|
|
|
|
"errors"
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
@ -17,9 +18,10 @@ func init() {
|
|
|
|
|
lock <- true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetupHTTPUpdates configures the endopint needed for triggering updates via http
|
|
|
|
|
func SetupHTTPUpdates(apiToken string, updateFunction func()) error {
|
|
|
|
|
if apiToken == "" {
|
|
|
|
|
return errors.New("API token is empty or has not been set. Not starting API.")
|
|
|
|
|
return errors.New("api token is empty or has not been set. not starting api")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("Watchtower HTTP API started.")
|
|
|
|
@ -48,12 +50,12 @@ func SetupHTTPUpdates(apiToken string, updateFunction func()) error {
|
|
|
|
|
log.Debug("Skipped. Another update already running.")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WaitForHTTPUpdates starts the http server and listens for requests.
|
|
|
|
|
func WaitForHTTPUpdates() error {
|
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
|
os.Exit(0)
|
|
|
|
|