forked from garethgeorge/backrest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dd9e14e
Showing
36 changed files
with
4,108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cmd/resticui/resticui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.