summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-08-12 10:41:11 +0300
committerPaul Buetow <paul@buetow.org>2024-08-12 10:41:11 +0300
commitb79de37224b40374cd0bc17881b3677138c44935 (patch)
tree94db4343ed6ae9dfc35c820f81a0b862d6e8e652
parent29705a8e5aad0c5edd4ed720e5c4b5d58a91c6e6 (diff)
initially can merge from remote partner but file to disk sync doesn't work yet maybe next time when i work on this this will be sorted.
-rw-r--r--internal/config/server/server.go2
-rw-r--r--internal/easyhttp/easyhttp.go1
-rw-r--r--internal/server/handler/handler.go9
-rw-r--r--internal/server/repository/repository.go3
4 files changed, 11 insertions, 4 deletions
diff --git a/internal/config/server/server.go b/internal/config/server/server.go
index 7ecfac4..b43166c 100644
--- a/internal/config/server/server.go
+++ b/internal/config/server/server.go
@@ -24,7 +24,7 @@ func New(configFile string) (ServerConfig, error) {
conf, _ := config.FromFile[ServerConfig](configFile)
conf.ListenAddr = config.EnvToStr("GOS_LISTEN_ADDR", conf.ListenAddr, "localhost:8080")
- conf.Partner = config.EnvToStr("GOS_PARTNER", conf.Partner)
+ conf.Partner = config.EnvToStr("GOS_PARTNER", "GOS_PARTNERS", conf.Partner)
conf.APIKey = config.EnvToStr("GOS_API_KEY", conf.APIKey)
conf.DataDir = config.EnvToStr("GOS_DATA_DIR", conf.DataDir, "data")
conf.EmailTo = config.EnvToStr("GOS_EMAIL_TO", conf.EmailTo)
diff --git a/internal/easyhttp/easyhttp.go b/internal/easyhttp/easyhttp.go
index 3f4b367..2968454 100644
--- a/internal/easyhttp/easyhttp.go
+++ b/internal/easyhttp/easyhttp.go
@@ -40,7 +40,6 @@ func Get(ctx context.Context, uri, apiKey string) ([]byte, error) {
// Get data from JSON
func GetData[T any](ctx context.Context, uri, apiKey string, data *T) error {
- log.Println("Getting data from ", uri)
bytes, err := Get(ctx, uri, apiKey)
if err != nil {
return err
diff --git a/internal/server/handler/handler.go b/internal/server/handler/handler.go
index fa1022e..25a4d12 100644
--- a/internal/server/handler/handler.go
+++ b/internal/server/handler/handler.go
@@ -20,7 +20,8 @@ type Handler struct {
func New(conf server.ServerConfig) Handler {
return Handler{
conf: conf,
- getIdRe: regexp.MustCompile(`^/[0-9]{4}/[a-z0-9]{64}\.json$`),
+ getIdRe: regexp.MustCompile(`^[a-z0-9]{64}$`),
+ // getIdRe: regexp.MustCompile(`^/[0-9]{4}/[a-z0-9]{64}\.json$`),
}
}
@@ -66,7 +67,11 @@ func (h Handler) Get(w http.ResponseWriter, r *http.Request) error {
return fmt.Errorf("no entry with id %s found", id)
}
- fmt.Fprint(w, ent.String())
+ jsonBytes, err := ent.Serialize()
+ if err != nil {
+ return err
+ }
+ fmt.Fprint(w, string(jsonBytes))
return nil
}
diff --git a/internal/server/repository/repository.go b/internal/server/repository/repository.go
index ffe4d37..3a598af 100644
--- a/internal/server/repository/repository.go
+++ b/internal/server/repository/repository.go
@@ -184,6 +184,7 @@ func (r Repository) Merge(otherEnt types.Entry) error {
return r.fs.WriteFile(r.entryPath(ent), bytes)
}
+// TODO: WHens omething has merged from remotely, make sure to commit/sync to disk
func (r Repository) MergeRemotely(ctx context.Context) error {
var errs []error
@@ -217,6 +218,8 @@ func (r Repository) mergeRemotelyFromPartner(ctx context.Context, partner string
continue
}
+ log.Println("pair", pair, "missing in local reposotory, going to merge it")
+
var (
ent types.Entry
uri = fmt.Sprintf("%s/get?id=%s", partner, pair.ID)