Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
add host node to tui
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 6, 2022
1 parent 4a575c4 commit d681a5d
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 309 deletions.
2 changes: 1 addition & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
var (
cmd = &cobra.Command{
Use: "gohost",
Short: "Simple host switcher tool made by ingbyr",
Short: "Simple gohost switcher tool made by ingbyr",
Run: func(cmd *cobra.Command, args []string) {
//m := tui.New()
//p := tea.NewProgram(m)
Expand Down
22 changes: 16 additions & 6 deletions store/store.go → db/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store
package db

import (
"errors"
"github.com/timshannon/bolthold"
"go.etcd.io/bbolt"
"gohost/config"
Expand All @@ -9,11 +10,11 @@ import (
)

var (
instance *store
instance *Store
once sync.Once
)

func Store() *store {
func Instance() *Store {
once.Do(func() {
cfg := config.Config()
instance = New(&options{
Expand All @@ -33,14 +34,23 @@ type options struct {
*bolthold.Options
}

type store struct {
type Store struct {
*bolthold.Store
}

func New(opt *options) *store {
func New(opt *options) *Store {
s, err := bolthold.Open(opt.File, os.ModePerm, opt.Options)
if err != nil {
panic(err)
}
return &store{Store: s}
return &Store{Store: s}
}

func (s *Store) FindNullable(result interface{}, query *bolthold.Query) error {
err := s.Find(result, query)

if !errors.Is(bolthold.ErrNotFound, err) {
return err
}
return nil
}
8 changes: 4 additions & 4 deletions store/store_test.go → db/store_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package store
package db

import (
"fmt"
Expand Down Expand Up @@ -62,21 +62,21 @@ func TestBoltHold(t *testing.T) {
a.NoError(err)

//var res []Item
//err = store.Find(&res, bolthold.Where("Category").Eq("blue").And("Created").Ge(time.Now().Add(-1*time.Hour)))
//err = db.Find(&res, bolthold.Where("Category").Eq("blue").And("Created").Ge(time.Now().Add(-1*time.Hour)))
//a.NoError(err)
//
//for _, r := range res {
// fmt.Println(r)
//}

//res = []Item{}
//err = store.Find(&res, bolthold.Where(bolthold.Key).Ne(2))
//err = db.Find(&res, bolthold.Where(bolthold.Key).Ne(2))
//a.NoError(err)
//for _, r := range res {
// fmt.Println(r)
//}
//
//err = store.Insert(bolthold.NextSequence(), "!23")
//err = db.Insert(bolthold.NextSequence(), "!23")
//a.NoError(err)

err = store.ForEach(bolthold.Where("Category").Eq("blue"), func(record *Item) error {
Expand Down
34 changes: 0 additions & 34 deletions host/group.go

This file was deleted.

40 changes: 0 additions & 40 deletions host/group_test.go

This file was deleted.

7 changes: 0 additions & 7 deletions host/host.go

This file was deleted.

7 changes: 0 additions & 7 deletions host/local.go

This file was deleted.

46 changes: 0 additions & 46 deletions host/node.go

This file was deleted.

4 changes: 0 additions & 4 deletions host/remote.go

This file was deleted.

107 changes: 0 additions & 107 deletions host/service.go

This file was deleted.

5 changes: 0 additions & 5 deletions host/sys.go

This file was deleted.

0 comments on commit d681a5d

Please sign in to comment.