version2 (#1)

Co-authored-by: u80864958 <niklas.breitenstein@bit.admin.ch>
Reviewed-on: #1
This commit is contained in:
2025-04-02 17:29:26 +02:00
parent abe9c7d1fb
commit 158e963c7b
11 changed files with 310 additions and 130 deletions

61
pkg/cat/cater.go Normal file
View File

@@ -0,0 +1,61 @@
package cat
import (
"fmt"
"os"
"strings"
)
type Cater map[string]string
func Path(paths ...string) (c Cater, err error) {
c = make(Cater)
var p os.FileInfo
for _, path := range paths {
p, err = os.Stat(path)
if err != nil {
return
}
if p.IsDir() {
err = c.dir(path)
} else {
err = c.file(path)
}
if err != nil {
return
}
}
return
}
func (c Cater) Ignored(ignore ignorer) Cater {
cat := make(Cater)
for name, content := range c {
if ignore.Ignore(name) {
continue
}
cat[name] = content
}
return cat
}
func (c Cater) ToString(delemiter string) string {
var sb strings.Builder
for name, content := range c {
sb.WriteString(fmt.Sprintf(delemiter, name))
sb.WriteString(content)
}
return sb.String()
}
type ignorer interface {
// Ignore() returns true when the given path shall be Ignored.
Ignore(path string) bool
}