Skip to content

Commit 407520f

Browse files
authored
adds must versions of module methods (#9)
1 parent 8c14ad3 commit 407520f

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

examples/cron/custom.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,29 @@ func (m *CustomModule) Input(name string) (*modules.Input, error) {
4646
}
4747
}
4848

49+
// MustInput -
50+
func (m *CustomModule) MustInput(name string) *modules.Input {
51+
input, err := m.Input(name)
52+
if err != nil {
53+
panic(err)
54+
}
55+
return input
56+
}
57+
4958
// Output -
5059
func (m *CustomModule) Output(name string) (*modules.Output, error) {
5160
return nil, errors.Wrap(modules.ErrUnknownOutput, name)
5261
}
5362

63+
// MustOutput -
64+
func (m *CustomModule) MustOutput(name string) *modules.Output {
65+
output, err := m.Output(name)
66+
if err != nil {
67+
panic(err)
68+
}
69+
return output
70+
}
71+
5472
// AttachTo -
5573
func (m *CustomModule) AttachTo(outputM modules.Module, outputName, inputName string) error {
5674
output, err := outputM.Output(outputName)

examples/grpc/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ func (client *Client) Input(name string) (*modules.Input, error) {
106106
return nil, errors.Wrap(modules.ErrUnknownInput, name)
107107
}
108108

109+
// MustInput -
110+
func (client *Client) MustInput(name string) *modules.Input {
111+
input, err := client.Input(name)
112+
if err != nil {
113+
panic(err)
114+
}
115+
return input
116+
}
117+
109118
// Output -
110119
func (client *Client) Output(name string) (*modules.Output, error) {
111120
if name != "time" {
@@ -114,6 +123,15 @@ func (client *Client) Output(name string) (*modules.Output, error) {
114123
return client.output, nil
115124
}
116125

126+
// MustOutput -
127+
func (client *Client) MustOutput(name string) *modules.Output {
128+
output, err := client.Output(name)
129+
if err != nil {
130+
panic(err)
131+
}
132+
return output
133+
}
134+
117135
// AttachTo -
118136
func (client *Client) AttachTo(outputModule modules.Module, outputName, inputName string) error {
119137
outputChannel, err := outputModule.Output(outputName)

examples/grpc/custom.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,29 @@ func (m *CustomModule) Input(name string) (*modules.Input, error) {
3939
return m.input, nil
4040
}
4141

42+
// MustInput -
43+
func (m *CustomModule) MustInput(name string) *modules.Input {
44+
input, err := m.Input(name)
45+
if err != nil {
46+
panic(err)
47+
}
48+
return input
49+
}
50+
4251
// Output -
4352
func (m *CustomModule) Output(name string) (*modules.Output, error) {
4453
return nil, errors.Wrap(modules.ErrUnknownOutput, name)
4554
}
4655

56+
// MustOutput -
57+
func (m *CustomModule) MustOutput(name string) *modules.Output {
58+
output, err := m.Output(name)
59+
if err != nil {
60+
panic(err)
61+
}
62+
return output
63+
}
64+
4765
// AttachTo -
4866
func (m *CustomModule) AttachTo(outputModule modules.Module, outputName, inputName string) error {
4967
outputChannel, err := outputModule.Output(outputName)

examples/zipper/custom.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func (m *CustomModule) Input(name string) (*modules.Input, error) {
3434
return nil, errors.Wrap(modules.ErrUnknownInput, name)
3535
}
3636

37+
// MustInput -
38+
func (m *CustomModule) MustInput(name string) *modules.Input {
39+
input, err := m.Input(name)
40+
if err != nil {
41+
panic(err)
42+
}
43+
return input
44+
}
45+
3746
// Output -
3847
func (m *CustomModule) Output(name string) (*modules.Output, error) {
3948
if name != "output" {
@@ -42,6 +51,15 @@ func (m *CustomModule) Output(name string) (*modules.Output, error) {
4251
return m.output, nil
4352
}
4453

54+
// MustOutput -
55+
func (m *CustomModule) MustOutput(name string) *modules.Output {
56+
output, err := m.Output(name)
57+
if err != nil {
58+
panic(err)
59+
}
60+
return output
61+
}
62+
4563
// AttachTo -
4664
func (m *CustomModule) AttachTo(outputModule modules.Module, outputName, inputName string) error {
4765
outputChannel, err := outputModule.Output(outputName)

pkg/modules/baseModule.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func (m *BaseModule) Input(name string) (*Input, error) {
4949
return input, nil
5050
}
5151

52+
func (m *BaseModule) MustInput(name string) *Input {
53+
input, err := m.Input(name)
54+
if err != nil {
55+
panic(err)
56+
}
57+
return input
58+
}
59+
5260
func (m *BaseModule) CreateInput(name string) {
5361
m.inputs.Set(name, NewInput(name))
5462
}
@@ -61,6 +69,14 @@ func (m *BaseModule) Output(name string) (*Output, error) {
6169
return output, nil
6270
}
6371

72+
func (m *BaseModule) MustOutput(name string) *Output {
73+
output, err := m.Output(name)
74+
if err != nil {
75+
panic(err)
76+
}
77+
return output
78+
}
79+
6480
func (m *BaseModule) CreateOutput(name string) {
6581
m.outputs.Set(name, NewOutput(name))
6682
}

pkg/modules/module.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type Module interface {
2121
Start(ctx context.Context)
2222

2323
Input(name string) (*Input, error)
24+
MustInput(name string) *Input
2425
Output(name string) (*Output, error)
26+
MustOutput(name string) *Output
2527
AttachTo(output Module, outputName, inputName string) error
2628
}

pkg/modules/zipper/module.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ func (m *Module[Key]) Input(name string) (*modules.Input, error) {
7070
}
7171
}
7272

73+
// MustInput - returns input by name
74+
func (m *Module[Key]) MustInput(name string) *modules.Input {
75+
input, err := m.Input(name)
76+
if err != nil {
77+
panic(err)
78+
}
79+
return input
80+
}
81+
7382
// Output - returns output by name
7483
func (m *Module[Key]) Output(name string) (*modules.Output, error) {
7584
if name != OutputName {
@@ -78,6 +87,15 @@ func (m *Module[Key]) Output(name string) (*modules.Output, error) {
7887
return m.output, nil
7988
}
8089

90+
// MustOutput - returns output by name
91+
func (m *Module[Key]) MustOutput(name string) *modules.Output {
92+
output, err := m.Output(name)
93+
if err != nil {
94+
panic(err)
95+
}
96+
return output
97+
}
98+
8199
// AttachTo - attach input to output with name
82100
func (m *Module[Key]) AttachTo(outputModule modules.Module, outputName, inputName string) error {
83101
outputChannel, err := outputModule.Output(outputName)

0 commit comments

Comments
 (0)