mirror of
https://github.com/restic/rest-server.git
synced 2026-09-26 05:51:24 -07:00
small refactoring
This commit is contained in:
@@ -20,9 +20,5 @@ func Authorize(r *http.Request) error {
|
|||||||
return errors.New("unknown user")
|
return errors.New("unknown user")
|
||||||
}
|
}
|
||||||
|
|
||||||
if username != repo {
|
|
||||||
return errors.New("unauthorized")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,6 @@ func NewContext(path string) Context {
|
|||||||
return Context{path}
|
return Context{path}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the file structure of the Context
|
|
||||||
func (c *Context) Init() error {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) Repository(name string) (Repository, error) {
|
func (c *Context) Repository(name string) (Repository, error) {
|
||||||
name, err := ParseRepositoryName(name)
|
name, err := ParseRepositoryName(name)
|
||||||
return Repository{filepath.Join(c.path, name)}, err
|
return Repository{filepath.Join(c.path, name)}, err
|
||||||
|
|||||||
@@ -7,17 +7,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
context := Context{"/tmp/restic"}
|
context := NewContext("/tmp/restic")
|
||||||
|
|
||||||
repo, _ := context.Repository("user")
|
repo, _ := context.Repository("user")
|
||||||
repo.Init()
|
repo.Init()
|
||||||
|
|
||||||
errc := context.Init()
|
|
||||||
if errc != nil {
|
|
||||||
log.Println("context initialization failed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
router := Router{context}
|
router := Router{context}
|
||||||
port := ":8000"
|
port := ":8000"
|
||||||
log.Printf("start server on port %s", port)
|
log.Printf("start server on port %s", port)
|
||||||
|
|||||||
Reference in New Issue
Block a user