rename package common to lib
This commit is contained in:
parent
d9e109e3a5
commit
2f1efc9731
6 changed files with 25 additions and 25 deletions
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/common"
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cfg struct {
|
type Cfg struct {
|
||||||
|
@ -12,34 +12,34 @@ type Cfg struct {
|
||||||
ConfigFormat string
|
ConfigFormat string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(ctx common.Context) {
|
func Start(ctx lib.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// definitions
|
// definitions
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
name string
|
name string
|
||||||
starter common.StartFct
|
starter lib.StartFct
|
||||||
children []common.Config
|
children []lib.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Base) Name() string {
|
func (cfg *Base) Name() string {
|
||||||
return cfg.name
|
return cfg.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Base) Starter() common.StartFct {
|
func (cfg *Base) Starter() lib.StartFct {
|
||||||
return cfg.starter
|
return cfg.starter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Base) Children() []common.Config {
|
func (cfg *Base) Children() []lib.Config {
|
||||||
return cfg.children
|
return cfg.children
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Base) Add(child common.Config) {
|
func (cfg *Base) Add(child lib.Config) {
|
||||||
cfg.children = append(cfg.children, child)
|
cfg.children = append(cfg.children, child)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeBase(name string, starter common.StartFct) *Base {
|
func MakeBase(name string, starter lib.StartFct) *Base {
|
||||||
return &Base{
|
return &Base{
|
||||||
name: name,
|
name: name,
|
||||||
starter: starter,
|
starter: starter,
|
||||||
|
|
|
@ -2,11 +2,11 @@ package etc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.sr.ht/~cco/go-scopes"
|
"git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/common"
|
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Config() common.Config {
|
func Config() lib.Config {
|
||||||
ovr := Overrides().Use
|
ovr := Overrides().Use
|
||||||
b := config.MakeBase
|
b := config.MakeBase
|
||||||
cfg := scopes.Cfg{
|
cfg := scopes.Cfg{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdlib_context "context"
|
stdlib_context "context"
|
14
scopes.go
14
scopes.go
|
@ -6,8 +6,8 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/common"
|
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cfg struct {
|
type Cfg struct {
|
||||||
|
@ -16,11 +16,11 @@ type Cfg struct {
|
||||||
Home string
|
Home string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(ctx common.Context) {
|
func Start(ctx lib.Context) {
|
||||||
common.RunCtx(ctx, start)
|
lib.RunCtx(ctx, start)
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(ctx common.Context) {
|
func start(ctx lib.Context) {
|
||||||
defer ctx.Stop()
|
defer ctx.Stop()
|
||||||
for _, cfg := range ctx.Config().Children() {
|
for _, cfg := range ctx.Config().Children() {
|
||||||
cctx := ctx.ChildContext(cfg)
|
cctx := ctx.ChildContext(cfg)
|
||||||
|
@ -34,7 +34,7 @@ func start(ctx common.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func step(ctx common.Context, sig <-chan os.Signal) bool {
|
func step(ctx lib.Context, sig <-chan os.Signal) bool {
|
||||||
select {
|
select {
|
||||||
case <-sig:
|
case <-sig:
|
||||||
fmt.Println("interrupted")
|
fmt.Println("interrupted")
|
||||||
|
@ -54,8 +54,8 @@ func step(ctx common.Context, sig <-chan os.Signal) bool {
|
||||||
|
|
||||||
// definitions
|
// definitions
|
||||||
|
|
||||||
func RunApp(cfg common.Config) {
|
func RunApp(cfg lib.Config) {
|
||||||
ctx := common.AppContext(cfg)
|
ctx := lib.AppContext(cfg)
|
||||||
cfg.Starter()(ctx)
|
cfg.Starter()(ctx)
|
||||||
ctx.WaitGroup().Wait()
|
ctx.WaitGroup().Wait()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes"
|
"git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/common"
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(ctx common.Context) {
|
func Start(ctx lib.Context) {
|
||||||
scopes.Start(ctx)
|
scopes.Start(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ type Map map[string]interface{}
|
||||||
|
|
||||||
type T struct {
|
type T struct {
|
||||||
Base *testing.T
|
Base *testing.T
|
||||||
Ctx common.Context
|
Ctx lib.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeT(tbase *testing.T) *T {
|
func MakeT(tbase *testing.T) *T {
|
||||||
|
@ -36,9 +36,9 @@ func SetUp(tbase *testing.T) *T {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpApp(tbase *testing.T, cfg common.Config) *T {
|
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
|
||||||
t := SetUp(tbase)
|
t := SetUp(tbase)
|
||||||
t.Ctx = common.AppContext(cfg)
|
t.Ctx = lib.AppContext(cfg)
|
||||||
cfg.Starter()(t.Ctx)
|
cfg.Starter()(t.Ctx)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -2,12 +2,12 @@ package etc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.sr.ht/~cco/go-scopes"
|
"git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/common"
|
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
"git.sr.ht/~cco/go-scopes/testing"
|
"git.sr.ht/~cco/go-scopes/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Config() common.Config {
|
func Config() lib.Config {
|
||||||
ovr := Overrides().Use
|
ovr := Overrides().Use
|
||||||
b := config.MakeBase
|
b := config.MakeBase
|
||||||
cfg := scopes.Cfg{
|
cfg := scopes.Cfg{
|
||||||
|
|
Loading…
Add table
Reference in a new issue