mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
386b69f473
* fix incorrect exported name in comments * add comments to exported methods
35 lines
892 B
Go
35 lines
892 B
Go
package backuputil
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// BackupExporter defines a backup exporter methods.
|
|
type BackupExporter interface {
|
|
Backup(ctx context.Context, outputPath string) error
|
|
}
|
|
|
|
// BackupHandler for accepting requests to initiate a new database backup.
|
|
func BackupHandler(bk BackupExporter, outputDir string) func(http.ResponseWriter, *http.Request) {
|
|
log := logrus.WithField("prefix", "db")
|
|
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
|
log.Debug("Creating database backup from HTTP webhook")
|
|
|
|
if err := bk.Backup(context.Background(), outputDir); err != nil {
|
|
log.WithError(err).Error("Failed to create backup")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusOK)
|
|
_, err := fmt.Fprint(w, "OK")
|
|
if err != nil {
|
|
log.WithError(err).Error("Failed to write OK")
|
|
}
|
|
}
|
|
}
|