Skip to content

Commit

Permalink
Merge pull request #1 from getoutreach/ps/module
Browse files Browse the repository at this point in the history
fix: renaming module
  • Loading branch information
pavelsmejkal authored Apr 30, 2024
2 parents f620910 + f859496 commit 2f15c4b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,36 @@ This example contains just two dependencies with in real world it might gets muc

#### Example
```golang
// a service we want to build with certain dependencies
type service struct {
D1 int
D2 int
}
// application dependency graph holds all application dependencies. It is recommended to structure it based on adapter types.
a := struct {
D1 plumber.D[int]
D2 plumber.D[int]
Service plumber.D[*service]
}{}
// definition of the dependencies
a.D1.Const(1)
a.D2.Const(2)

// service resolver
a.Service.Resolve(func(r *plumber.Resolution[*Service]) {
// service depends on D1 and D2 those needs gets resolved first without an error.
r.Require(&a.D1, &a.D2).Then(func() {
// When all good, we can construct our service
r.Resolve(&Service{
D1: a.D1.Instance(),
D2: a.D2.Instance(),
})
})
})
v, err := a.Service.InstanceError()
assert.NilError(t, err)
assert.Equal(t, v.D1, 1)
assert.Equal(t, v.D2, 2)
// a service we want to build with certain dependencies
type service struct {
D1 int
D2 int
}
// application dependency graph holds all application dependencies. It is recommended to structure it based on adapter types.
a := struct {
D1 plumber.D[int]
D2 plumber.D[int]
Service plumber.D[*service]
}{}
// definition of the dependencies
a.D1.Const(1)
a.D2.Const(2)

// service resolver
a.Service.Resolve(func(r *plumber.Resolution[*Service]) {
// service depends on D1 and D2 those needs gets resolved first without an error.
r.Require(&a.D1, &a.D2).Then(func() {
// When all good, we can construct our service
r.Resolve(&Service{
D1: a.D1.Instance(),
D2: a.D2.Instance(),
})
})
})
v, err := a.Service.InstanceError()
assert.NilError(t, err)
assert.Equal(t, v.D1, 1)
assert.Equal(t, v.D2, 2)
```

### Service task orchestration
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/outreach/plumber
module github.com/getoutreach/plumber

go 1.19

Expand Down
2 changes: 1 addition & 1 deletion looper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/outreach/plumber"
"github.com/getoutreach/plumber"
)

func ExampleLooper() {
Expand Down
2 changes: 1 addition & 1 deletion orchestration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/outreach/plumber"
"github.com/getoutreach/plumber"
"gotest.tools/v3/assert"
)

Expand Down
7 changes: 7 additions & 0 deletions plumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ func (d *D[T]) Const(v T) *D[T] {
return d
}

// Use overwrites defined value with specific instance. Should be used only for testings
func (d *D[T]) Use(v T) *D[T] {
d.resolved = true
d.value = v
return d
}

// Must returns a value or panics in case of the error
func (d *D[T]) Must() T {
v, err := d.InstanceError()
Expand Down
2 changes: 1 addition & 1 deletion plumber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/outreach/plumber"
"github.com/getoutreach/plumber"
"gotest.tools/v3/assert"
)

Expand Down

0 comments on commit 2f15c4b

Please sign in to comment.