Format the source file

This commit is contained in:
Quentin 2021-08-19 22:14:53 +02:00
parent d69640894d
commit 8f7e8d2c73

33
main.go
View file

@ -2,15 +2,15 @@ package main
import ( import (
"context" "context"
"log"
"fmt"
"os"
"io/fs"
"time"
"errors" "errors"
"fmt"
"io/fs"
"log"
"net/http" "net/http"
"strings" "os"
"path" "path"
"strings"
"time"
"golang.org/x/net/webdav" "golang.org/x/net/webdav"
@ -21,6 +21,7 @@ import (
) )
type bagageCtxKey string type bagageCtxKey string
const garageEntry = bagageCtxKey("garage") const garageEntry = bagageCtxKey("garage")
type garageCtx struct { type garageCtx struct {
@ -45,18 +46,18 @@ func main() {
} }
//http.Handle("/", srv) //http.Handle("/", srv)
http.HandleFunc(pathPrefix + "/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc(pathPrefix+"/", func(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if !ok { if !ok {
NotAuthorized(w,r) NotAuthorized(w, r)
return return
} }
ldapSock, err := ldap.Dial("tcp", "127.0.0.1:1389") ldapSock, err := ldap.Dial("tcp", "127.0.0.1:1389")
if err != nil { if err != nil {
log.Println(err) log.Println(err)
InternalError(w,r) InternalError(w, r)
return return
} }
defer ldapSock.Close() defer ldapSock.Close()
@ -66,7 +67,7 @@ func main() {
err = ldapSock.Bind(userDn, password) err = ldapSock.Bind(userDn, password)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
NotAuthorized(w,r) NotAuthorized(w, r)
return return
} }
@ -85,13 +86,13 @@ func main() {
sr, err := ldapSock.Search(searchRequest) sr, err := ldapSock.Search(searchRequest)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
InternalError(w,r) InternalError(w, r)
return return
} }
if len(sr.Entries) != 1 { if len(sr.Entries) != 1 {
log.Println("Wrong number of LDAP entries, expected 1, got", len(sr.Entries)) log.Println("Wrong number of LDAP entries, expected 1, got", len(sr.Entries))
InternalError(w,r) InternalError(w, r)
return return
} }
@ -100,7 +101,7 @@ func main() {
if access_key == "" || secret_key == "" { if access_key == "" || secret_key == "" {
log.Println("Either access key or secret key is missing in LDAP for ", userDn) log.Println("Either access key or secret key is missing in LDAP for ", userDn)
InternalError(w,r) InternalError(w, r)
return return
} }
@ -110,7 +111,7 @@ func main() {
}) })
if err != nil { if err != nil {
log.Println(err) log.Println(err)
InternalError(w,r) InternalError(w, r)
return return
} }
@ -146,7 +147,7 @@ func InternalError(w http.ResponseWriter, r *http.Request) {
Else Else
return obj return obj
*/ */
type GarageFS struct {} type GarageFS struct{}
func NewGarageFS() *GarageFS { func NewGarageFS() *GarageFS {
grg := new(GarageFS) grg := new(GarageFS)
@ -246,7 +247,7 @@ func (gf *GarageFile) readDirChild(count int, bucket, prefix string) ([]fs.FileI
Recursive: false, Recursive: false,
}) })
entries := make([]fs.FileInfo,0) entries := make([]fs.FileInfo, 0)
for object := range objs_info { for object := range objs_info {
if object.Err != nil { if object.Err != nil {
return nil, object.Err return nil, object.Err