Some checks failed
CloudSave/pipeline/head Something is wrong with the build of this commit
39 lines
539 B
Go
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
|
|
}
|