1
0
mirror of https://github.com/go-task/task.git synced 2025-06-08 23:56:21 +02:00
task/taskfile/node_base.go

57 lines
1.1 KiB
Go
Raw Normal View History

package taskfile
type (
NodeOption func(*baseNode)
// baseNode is a generic node that implements the Parent() methods of the
2023-09-06 00:11:13 +00:00
// NodeReader interface. It does not implement the Read() method and it
// designed to be embedded in other node types so that this boilerplate code
// does not need to be repeated.
baseNode struct {
2025-04-28 16:31:12 +00:00
parent Node
dir string
checksum string
}
)
func NewBaseNode(dir string, opts ...NodeOption) *baseNode {
node := &baseNode{
2023-09-06 00:11:13 +00:00
parent: nil,
dir: dir,
}
// Apply options
for _, opt := range opts {
opt(node)
}
return node
}
func WithParent(parent Node) NodeOption {
return func(node *baseNode) {
node.parent = parent
}
}
2025-04-28 16:31:12 +00:00
func WithChecksum(checksum string) NodeOption {
return func(node *baseNode) {
node.checksum = checksum
}
}
func (node *baseNode) Parent() Node {
return node.parent
}
func (node *baseNode) Dir() string {
2024-02-13 01:07:00 +00:00
return node.dir
}
2025-04-28 16:31:12 +00:00
func (node *baseNode) Checksum() string {
return node.checksum
}
func (node *baseNode) Verify(checksum string) bool {
return node.checksum == "" || node.checksum == checksum
}