Files
cloudsave/cmd/server/security/htpasswd/htpasswd.go
Aurélie DELHAIE 46f312078d
Some checks failed
CloudSave/pipeline/head Something is wrong with the build of this commit
fix sec
2025-09-07 01:31:14 +02:00

39 lines
539 B
Go

package htpasswd
import (
"os"
"path/filepath"
"strings"
)
type (
File struct {
data map[string]string
}
)
func Open(path string) (File, error) {
c, err := os.ReadFile(filepath.Clean(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
}