mirror of
https://github.com/restic/rest-server.git
synced 2026-04-12 13:11:50 -07:00
Make Server use the new repo.Handler
This contains all the glue to make Server use the new repo.Handler: - Remove all old handlers - Add ServeHTTP to make Server a single http.Handler - Remove Goji routing and replace by net/http and custom routing logic Additionally, this implements two-level backup repositories.
This commit is contained in:
committed by
Alexander Neumann
parent
55e549e92c
commit
1f593fafaf
@@ -75,21 +75,6 @@ func tlsSettings() (bool, string, string, error) {
|
||||
return server.TLS, key, cert, nil
|
||||
}
|
||||
|
||||
func getHandler(server restserver.Server) (http.Handler, error) {
|
||||
mux := restserver.NewHandler(server)
|
||||
if server.NoAuth {
|
||||
log.Println("Authentication disabled")
|
||||
return mux, nil
|
||||
}
|
||||
|
||||
log.Println("Authentication enabled")
|
||||
htpasswdFile, err := restserver.NewHtpasswdFromFile(filepath.Join(server.Path, ".htpasswd"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load .htpasswd (use --no-auth to disable): %v", err)
|
||||
}
|
||||
return server.AuthHandler(htpasswdFile, mux), nil
|
||||
}
|
||||
|
||||
func runRoot(cmd *cobra.Command, args []string) error {
|
||||
if showVersion {
|
||||
fmt.Printf("rest-server %s compiled with %v on %v/%v\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
@@ -112,7 +97,13 @@ func runRoot(cmd *cobra.Command, args []string) error {
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
handler, err := getHandler(server)
|
||||
if server.NoAuth {
|
||||
log.Println("Authentication disabled")
|
||||
} else {
|
||||
log.Println("Authentication enabled")
|
||||
}
|
||||
|
||||
handler, err := restserver.NewHandler(&server)
|
||||
if err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user