This commit is contained in:
2025-05-15 00:46:57 +02:00
parent 30c71cb449
commit b2b27b2c3d
18 changed files with 622 additions and 234 deletions

View File

@@ -0,0 +1,37 @@
package htpasswd
import (
"os"
"strings"
)
type (
File struct {
data map[string]string
}
)
func Open(path string) (File, error) {
c, err := os.ReadFile(path)
if err != nil {
return File{}, err
}
f := File{
data: make(map[string]string),
}
creds := strings.Split(string(c), "\n")
for _, cred := range creds {
kv := strings.Split(cred, ":")
if len(kv) != 2 {
continue
}
f.data[kv[0]] = kv[1]
}
return f, nil
}
func (f File) Content() map[string]string {
return f.data
}