Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: renaming module #1

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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