Add debug flag

This commit is contained in:
Zlatko Čalušić 2016-12-27 12:26:41 +01:00
parent 061d31829d
commit 1f29574118
3 changed files with 31 additions and 0 deletions

View file

@ -63,6 +63,9 @@ func AuthHandler(f *HtpasswdFile, h http.Handler) http.HandlerFunc {
// CheckConfig returns a http.HandlerFunc that checks whether a configuration exists.
func CheckConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("CheckConfig()")
}
config := filepath.Join(c.path, "config")
st, err := os.Stat(config)
if err != nil {
@ -77,6 +80,9 @@ func CheckConfig(c *Context) http.HandlerFunc {
// GetConfig returns a http.HandlerFunc that allows for a config to be retrieved.
func GetConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("GetConfig()")
}
config := filepath.Join(c.path, "config")
bytes, err := ioutil.ReadFile(config)
if err != nil {
@ -91,6 +97,9 @@ func GetConfig(c *Context) http.HandlerFunc {
// SaveConfig returns a http.HandlerFunc that allows for a config to be saved.
func SaveConfig(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("SaveConfig()")
}
config := filepath.Join(c.path, "config")
bytes, err := ioutil.ReadAll(r.Body)
if err != nil {
@ -109,6 +118,9 @@ func SaveConfig(c *Context) http.HandlerFunc {
// ListBlobs returns a http.HandlerFunc that lists all blobs of a given type in an arbitrary order.
func ListBlobs(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("ListBlobs()")
}
vars := strings.Split(r.RequestURI, "/")
dir := vars[1]
path := filepath.Join(c.path, dir)
@ -149,6 +161,9 @@ func ListBlobs(c *Context) http.HandlerFunc {
// CheckBlob returns a http.HandlerFunc that tests whether a blob exists and returns 200, if it does, or 404 otherwise.
func CheckBlob(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("CheckBlob()")
}
vars := strings.Split(r.RequestURI, "/")
dir := vars[1]
name := vars[2]
@ -171,6 +186,9 @@ func CheckBlob(c *Context) http.HandlerFunc {
// GetBlob returns a http.HandlerFunc that retrieves a blob from the repository.
func GetBlob(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("GetBlob()")
}
vars := strings.Split(r.RequestURI, "/")
dir := vars[1]
name := vars[2]
@ -194,6 +212,9 @@ func GetBlob(c *Context) http.HandlerFunc {
// SaveBlob returns a http.HandlerFunc that saves a blob to the repository.
func SaveBlob(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("SaveBlob()")
}
vars := strings.Split(r.RequestURI, "/")
dir := vars[1]
name := vars[2]
@ -249,6 +270,9 @@ func SaveBlob(c *Context) http.HandlerFunc {
// DeleteBlob returns a http.HandlerFunc that deletes a blob from the repository.
func DeleteBlob(c *Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if *debug {
log.Println("DeleteBlob()")
}
vars := strings.Split(r.RequestURI, "/")
dir := vars[1]
name := vars[2]