Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Nov 10, 2023
0 parents commit dd9e14e
Show file tree
Hide file tree
Showing 36 changed files with 4,108 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmd/resticui/resticui
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ResticUI

WIP project to build a UI for restic.

Project goals

* Single binary for easy and _very lightweight_ deployment with or without containerization.
* WebUI supporting
* Backup plan creation and configuration
* Backup status
* Snapshot browsing and restore

# Dependencies

## Dev

```sh
apt install -y protobuf-compiler
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
go install github.com/grpc-ecosystem/protoc-gen-grpc-gateway-ts@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/bufbuild/buf/cmd/buf@v1.27.2
```
78 changes: 78 additions & 0 deletions cmd/resticui/resticui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"context"
"errors"
"net/http"
"os"
"os/signal"
"sync"
"syscall"

"github.com/garethgeorge/resticui/internal/api"
"github.com/garethgeorge/resticui/static"
"go.uber.org/zap"

_ "embed"
)

func main() {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
go onterm(cancel)

var wg sync.WaitGroup

// Configure the HTTP mux
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(http.FS(static.FS)))

// Serve the API
wg.Add(1)
go func() {
defer wg.Done()
defer cancel()
err := api.ServeAPI(ctx, 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)
}()

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

// Serve the HTTP gateway
wg.Add(1)
go func() {
defer wg.Done()
zap.S().Infof("HTTP binding to address %v", server.Addr)
go func() {
<-ctx.Done()
server.Shutdown(context.Background())
}()
if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
zap.S().Error("Error starting server", zap.Error(err))
}
zap.S().Info("HTTP gateway shutdown")
cancel() // cancel the context when the HTTP server exits (e.g. on fatal error)
}()

wg.Wait()
}

func init() {
zap.ReplaceGlobals(zap.Must(zap.NewProduction()))
if os.Getenv("DEBUG") != "" {
zap.ReplaceGlobals(zap.Must(zap.NewDevelopment()))
}
}

func onterm(callback func()) {
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, os.Interrupt, syscall.SIGTERM)
<-sigchan
callback()
}
118 changes: 118 additions & 0 deletions gen/go/google/api/annotations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd9e14e

Please sign in to comment.