Skip to content

Commit

Permalink
feat: initial oplog implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Nov 14, 2023
1 parent 23a5609 commit dd9142c
Show file tree
Hide file tree
Showing 16 changed files with 1,203 additions and 179 deletions.
31 changes: 26 additions & 5 deletions cmd/resticui/resticui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/garethgeorge/resticui/internal/api"
"github.com/garethgeorge/resticui/internal/config"
"github.com/garethgeorge/resticui/internal/oplog"
"github.com/garethgeorge/resticui/internal/orchestrator"
static "github.com/garethgeorge/resticui/webui"
"github.com/mattn/go-colorable"
Expand All @@ -27,6 +28,7 @@ func main() {
ctx, cancel := context.WithCancel(ctx)
go onterm(cancel)


if _, err := config.Default.Get(); err != nil {
zap.S().Fatalf("Error loading config: %v", err)
}
Expand All @@ -37,25 +39,36 @@ func main() {
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.FS(&SubdirFilesystem{FS: static.FS, subdir: "dist"})))

server := &http.Server{
Addr: ":9090",
Handler: mux,

// Create and serve API server
oplog, err := oplog.NewOpLog(path.Join(dataPath(), "oplog.boltdb"))
if err != nil {
zap.S().Fatalf("Error creating oplog: %v", err)
}
defer oplog.Close()

orchestrator := orchestrator.NewOrchestrator(config.Default)
apiServer := api.NewServer(
orchestrator.NewOrchestrator(config.Default), // TODO: eliminate default config
oplog,
)

// Serve the API
wg.Add(1)
go func() {
defer wg.Done()
err := api.ServeAPI(ctx, orchestrator, mux)
err := api.ServeAPI(ctx, apiServer, mux)
if err != nil {
zap.S().Fatal("Error serving API", zap.Error(err))
}
cancel() // cancel the context when the API server exits (e.g. on fatal error)
}()

// Serve the HTTP gateway
server := &http.Server{
Addr: ":9090",
Handler: mux,
}

wg.Add(1)
go func() {
defer wg.Done()
Expand Down Expand Up @@ -113,4 +126,12 @@ func (s *SubdirFilesystem) ReadDir(name string) ([]fs.DirEntry, error) {
return nil, &fs.PathError{Op: "readdir", Path: name, Err: errors.New("not implemented")}
}
return readDirFS.ReadDir(path.Join(s.subdir, name))
}

func dataPath() string {
datahome := os.Getenv("XDG_DATA_HOME")
if datahome == "" {
datahome = path.Join(os.Getenv("HOME") + "/.local/share")
}
return path.Join(datahome, "resticui")
}
Loading

0 comments on commit dd9142c

Please sign in to comment.