62 lines
885 B
Go
62 lines
885 B
Go
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
|
|
}
|