Add initial triplestore rebuild functionality

This commit is contained in:
Tom Wiesing 2024-04-04 13:52:15 +02:00
parent 8a1319df16
commit 674b9d8d07
No known key found for this signature in database
11 changed files with 252 additions and 56 deletions

View file

@ -0,0 +1,28 @@
package triplestore
import (
"context"
"fmt"
"io"
"net/http"
"github.com/pkg/errors"
)
var errTSRestoreWrongStatusCode = errors.New("Triplestore.Restore: Wrong status code")
// RestoreDB snapshots the provided repository into dst
func (ts Triplestore) RestoreDB(ctx context.Context, repo string, reader io.Reader) error {
// submit the form
res, err := ts.DoRestWithReader(ctx, 0, http.MethodPut, "/repositories/"+repo+"/statements", &RequestHeaders{ContentType: nquadsContentType}, reader)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusNoContent {
message, _ := io.ReadAll(res.Body)
return fmt.Errorf("%w: %s", errTSRestoreWrongStatusCode, message)
}
return nil
}