Skip to content

Commit

Permalink
add GoDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Nov 4, 2023
1 parent 2246e2a commit 6bc3f9e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions example/like_cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func sampleWalker() error {
// Output:
// WalkerNode's methods called...
// Name : a
// Branch :
// Branch :
// Row : a
// Level : 1
// Path : a
Expand Down Expand Up @@ -164,7 +164,7 @@ func sampleWalker() error {
// Path : a/kk/t
// WalkerNode's methods called...
// Name : e
// Branch :
// Branch :
// Row : e
// Level : 1
// Path : e
Expand Down
2 changes: 1 addition & 1 deletion example/programmable/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func sampleWalker() {
// Output:
// WalkerNode's methods called...
// Name : root
// Branch :
// Branch :
// Row : root
// Level : 1
// Path : root
Expand Down
9 changes: 7 additions & 2 deletions simple_tree_walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package gtree

// WalkerNode is used in user-defined function that can be executed with Walk/WalkProgrammably function.
type WalkerNode struct {
name string
branch string
Expand All @@ -10,22 +11,27 @@ type WalkerNode struct {
path string
}

// Name returns name of node in completed tree structure.
func (wn *WalkerNode) Name() string {
return wn.name
}

// Branch returns branch of node in completed tree structure.
func (wn *WalkerNode) Branch() string {
return wn.branch
}

// Row returns row of node in completed tree structure.
func (wn *WalkerNode) Row() string {
return wn.row
}

// Level returns level of node in completed tree structure.
func (wn *WalkerNode) Level() uint {
return wn.level
}

// Path returns path of node in completed tree structure.
func (wn *WalkerNode) Path() string {
return wn.path
}
Expand All @@ -50,12 +56,11 @@ func (dw *defaultWalkerSimple) walkNode(current *Node, cb func(*WalkerNode) erro
if !current.isRoot() {
row = current.branch() + " " + current.name
}

wn := &WalkerNode{
name: current.name,
branch: current.branch(),
row: row,
level: current.hierarchy,
level: current.hierarchy,
path: current.path(),
}
if err := cb(wn); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tree_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Verify(r io.Reader, options ...Option) error {
return initializeTree(cfg).verify(r, cfg)
}

// TODO: add doc
// Walk executes user-defined function while traversing tree structure.
func Walk(r io.Reader, cb func(*WalkerNode) error, options ...Option) error {
cfg := newConfig(options)
return initializeTree(cfg).walk(r, cb, cfg)
Expand Down
3 changes: 2 additions & 1 deletion tree_handler_programmably.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func VerifyProgrammably(root *Node, options ...Option) error {
return initializeTree(cfg).verifyProgrammably(root, cfg)
}

// TODO: add doc
// WalkProgrammably executes user-defined function while traversing tree structure.
// This function requires node generated by NewRoot function.
func WalkProgrammably(root *Node, cb func(*WalkerNode) error, options ...Option) error {
if err := validateTreeRoot(root); err != nil {
return err
Expand Down

0 comments on commit 6bc3f9e

Please sign in to comment.