2023-02-14 21:59:56 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MethodNotAllowed(w http.ResponseWriter, allowedMethods ...string) {
|
|
|
|
for _, method := range allowedMethods {
|
|
|
|
w.Header().Add("Allow", strings.ToUpper(method))
|
|
|
|
}
|
|
|
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InternalServerError(w http.ResponseWriter, err error) {
|
|
|
|
log.Println(err)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func And[T any](f1, f2 func(T) bool) func(T) bool {
|
|
|
|
return func(v T) bool {
|
|
|
|
return f1(v) && f2(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Or[T any](f1, f2 func(T) bool) func(T) bool {
|
|
|
|
return func(v T) bool {
|
|
|
|
return f1(v) || f2(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Not[T any](f func(T) bool) func(T) bool {
|
|
|
|
return func(v T) bool {
|
|
|
|
return !f(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-16 12:16:04 +01:00
|
|
|
func IsSymlink(entry os.DirEntry) bool {
|
|
|
|
return entry.Type()&os.ModeSymlink == os.ModeSymlink
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsRegular(entry os.DirEntry) bool {
|
|
|
|
return entry.Type().IsRegular()
|
|
|
|
}
|
|
|
|
|
2023-02-14 21:59:56 +01:00
|
|
|
func IsDir(entry os.DirEntry) bool {
|
|
|
|
return entry.IsDir()
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsHidden(entry os.DirEntry) bool {
|
|
|
|
return strings.HasPrefix(entry.Name(), ".")
|
|
|
|
}
|
|
|
|
|
|
|
|
func FsEntry2Name(entry os.DirEntry) string {
|
|
|
|
return entry.Name()
|
|
|
|
}
|