This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func run() {
|
||||
func run(updateChan <-chan struct{}) {
|
||||
fmt.Printf("CloudSave server -- v%s.%s.%s\n\n", constants.Version, runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
var documentRoot string
|
||||
@@ -47,6 +47,7 @@ func run() {
|
||||
if err := r.Preload(); err != nil {
|
||||
fatal("failed to load datastore: "+err.Error(), 1)
|
||||
}
|
||||
|
||||
repo = r
|
||||
} else {
|
||||
slog.Info("loading lazy repository...")
|
||||
@@ -61,6 +62,21 @@ func run() {
|
||||
|
||||
server := api.NewServer(documentRoot, s, h.Content(), port)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
<-updateChan
|
||||
if r, ok := repo.(*repository.EagerRepository); ok {
|
||||
r.Reload()
|
||||
}
|
||||
h, err := htpasswd.Open(filepath.Join(documentRoot, ".htpasswd"))
|
||||
if err != nil {
|
||||
fatal("failed to load .htpasswd: "+err.Error(), 1)
|
||||
}
|
||||
slog.Info("users loaded: " + strconv.Itoa(len(h.Content())) + " user(s) loaded")
|
||||
server.SetCredentials(h.Content())
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Println("server started at :" + strconv.Itoa(port))
|
||||
if err := server.Server.ListenAndServe(); err != nil {
|
||||
fatal("failed to start server: "+err.Error(), 1)
|
||||
|
||||
Reference in New Issue
Block a user