59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|
|
|
|
func IsSymlink(entry os.DirEntry) bool {
|
|
return entry.Type()&os.ModeSymlink == os.ModeSymlink
|
|
}
|
|
|
|
func IsRegular(entry os.DirEntry) bool {
|
|
return entry.Type().IsRegular()
|
|
}
|
|
|
|
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()
|
|
}
|