This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
248 additions
and
253 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package host | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var ( | ||
ErrGroupExist = errors.New("nodes is already existed") | ||
) | ||
|
||
type Group struct { | ||
ID uint `boltholdKey:"ID"` | ||
ParentID uint | ||
Name string | ||
Desc string | ||
} | ||
|
||
func (g Group) Title() string { | ||
return g.Name | ||
} | ||
func (g Group) Description() string { | ||
return g.Desc | ||
} | ||
func (g Group) FilterValue() string { | ||
return g.Name | ||
} | ||
|
||
func (g Group) GetID() uint { | ||
return g.ID | ||
} | ||
|
||
func (g Group) GetParentID() uint { | ||
return g.ParentID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package host | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"gohost/store" | ||
"testing" | ||
) | ||
|
||
func TestGroupService_Save(t *testing.T) { | ||
s := store.Store() | ||
defer s.Close() | ||
a := assert.New(t) | ||
service := GetService() | ||
groups := []Group{ | ||
{ID: 1, ParentID: 0, Name: "g-1", Desc: "desc1"}, | ||
{ID: 11, ParentID: 1, Name: "g-1-1", Desc: "desc11"}, | ||
{ID: 111, ParentID: 11, Name: "g-1-1-1", Desc: "desc111"}, | ||
{ID: 112, ParentID: 11, Name: "g-1-1-2", Desc: "desc112"}, | ||
{ID: 12, ParentID: 1, Name: "g-1-2", Desc: "desc12"}, | ||
{ID: 13, ParentID: 1, Name: "g-1-3", Desc: "desc13"}, | ||
{ID: 131, ParentID: 13, Name: "g-1-3-1", Desc: "desc131"}, | ||
{ID: 132, ParentID: 13, Name: "g-1-3-2", Desc: "desc132"}, | ||
{ID: 2, ParentID: 0, Name: "g-2", Desc: "desc2"}, | ||
{ID: 3, ParentID: 0, Name: "g-3", Desc: "desc3"}, | ||
{ID: 31, ParentID: 3, Name: "g-3-1", Desc: "desc31"}, | ||
{ID: 32, ParentID: 3, Name: "g-3-2", Desc: "desc32"}, | ||
{ID: 4, ParentID: 0, Name: "g-4", Desc: "desc4"}, | ||
} | ||
for _, g := range groups { | ||
if err := service.SaveGroup(g); err != nil { | ||
a.NoError(err) | ||
} | ||
} | ||
savedGroups, err := service.loadGroups() | ||
a.NoError(err) | ||
for i := range savedGroups { | ||
fmt.Println("wtf", savedGroups[i]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package host | ||
|
||
type DBHost struct { | ||
type Local struct { | ||
Name string | ||
Content string | ||
Group int | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package host | ||
|
||
import "github.com/charmbracelet/bubbles/list" | ||
|
||
type Type uint | ||
|
||
const ( | ||
GroupType Type = iota | ||
LocalHostType | ||
RemoteHostType | ||
) | ||
|
||
type TreeNode interface { | ||
list.Item | ||
GetID() uint | ||
GetParentID() uint | ||
} | ||
|
||
type Node[T TreeNode] struct { | ||
Data T | ||
Children []*Node[T] | ||
Depth int | ||
Type Type | ||
IsFold bool | ||
} | ||
|
||
func NewNode[T TreeNode](data T, depth int) *Node[T] { | ||
return &Node[T]{ | ||
Data: data, | ||
Children: make([]*Node[T], 0), | ||
Depth: depth, | ||
IsFold: true, | ||
} | ||
} | ||
|
||
func (n *Node[T]) FilterValue() string { | ||
return n.FilterValue() | ||
} | ||
|
||
func (n *Node[T]) GetID() uint { | ||
return n.Data.GetID() | ||
} | ||
|
||
func (n *Node[T]) GetParentID() uint { | ||
return n.Data.GetParentID() | ||
} |
Oops, something went wrong.