Skip to content

Commit 8c14ad3

Browse files
authored
Adds BaseModule (#7)
1 parent ac02de8 commit 8c14ad3

File tree

26 files changed

+473
-480
lines changed

26 files changed

+473
-480
lines changed

.run/examples_cron.run.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="examples/cron" type="GoApplicationRunConfiguration" factoryName="Go Application">
3+
<module name="indexer-sdk" />
4+
<working_directory value="$PROJECT_DIR$/examples/cron" />
5+
<EXTENSION ID="net.ashald.envfile">
6+
<option name="IS_ENABLED" value="false" />
7+
<option name="IS_SUBST" value="false" />
8+
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
9+
<option name="IS_IGNORE_MISSING_FILES" value="false" />
10+
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
11+
<ENTRIES>
12+
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
13+
</ENTRIES>
14+
</EXTENSION>
15+
<kind value="DIRECTORY" />
16+
<package value="github.com/dipdup-net/indexer-sdk/examples/cron" />
17+
<directory value="$PROJECT_DIR$/examples/cron" />
18+
<filePath value="$PROJECT_DIR$/examples/cron/main.go" />
19+
<method v="2" />
20+
</configuration>
21+
</component>

.run/examples_grpc.run.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="examples/grpc" type="GoApplicationRunConfiguration" factoryName="Go Application">
3+
<module name="indexer-sdk" />
4+
<working_directory value="$PROJECT_DIR$/examples/grpc" />
5+
<EXTENSION ID="net.ashald.envfile">
6+
<option name="IS_ENABLED" value="false" />
7+
<option name="IS_SUBST" value="false" />
8+
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
9+
<option name="IS_IGNORE_MISSING_FILES" value="false" />
10+
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
11+
<ENTRIES>
12+
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
13+
</ENTRIES>
14+
</EXTENSION>
15+
<kind value="DIRECTORY" />
16+
<package value="github.com/dipdup-net/indexer-sdk/examples/grpc" />
17+
<directory value="$PROJECT_DIR$/examples/grpc" />
18+
<filePath value="$PROJECT_DIR$/examples/grpc/main.go" />
19+
<method v="2" />
20+
</configuration>
21+
</component>

.run/examples_zipper.run.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="examples/zipper" type="GoApplicationRunConfiguration" factoryName="Go Application">
3+
<module name="indexer-sdk" />
4+
<working_directory value="$PROJECT_DIR$/examples/zipper" />
5+
<EXTENSION ID="net.ashald.envfile">
6+
<option name="IS_ENABLED" value="false" />
7+
<option name="IS_SUBST" value="false" />
8+
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
9+
<option name="IS_IGNORE_MISSING_FILES" value="false" />
10+
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
11+
<ENTRIES>
12+
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" />
13+
</ENTRIES>
14+
</EXTENSION>
15+
<kind value="DIRECTORY" />
16+
<package value="github.com/dipdup-net/indexer-sdk/examples/zipper/examples/zipper" />
17+
<directory value="$PROJECT_DIR$/examples/zipper" />
18+
<filePath value="$PROJECT_DIR$/examples/zipper/main.go" />
19+
<method v="2" />
20+
</configuration>
21+
</component>

examples/cron/custom.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/rs/zerolog/log"
1010
)
1111

12+
var _ modules.Module = (*CustomModule)(nil)
13+
1214
// CustomModule -
1315
type CustomModule struct {
1416
everySecond *modules.Input
@@ -50,8 +52,22 @@ func (m *CustomModule) Output(name string) (*modules.Output, error) {
5052
}
5153

5254
// AttachTo -
53-
func (m *CustomModule) AttachTo(name string, input *modules.Input) error {
54-
return errors.Wrap(modules.ErrUnknownOutput, name)
55+
func (m *CustomModule) AttachTo(outputM modules.Module, outputName, inputName string) error {
56+
output, err := outputM.Output(outputName)
57+
if err != nil {
58+
return nil
59+
}
60+
61+
switch inputName {
62+
case "every_second":
63+
output.Attach(m.everySecond)
64+
return nil
65+
case "every_five_second":
66+
output.Attach(m.everyFiveSecond)
67+
return nil
68+
default:
69+
return errors.Wrap(modules.ErrUnknownInput, inputName)
70+
}
5571
}
5672

5773
func (m *CustomModule) listen(ctx context.Context) {

examples/duplicator/main.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/grpc/client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Client struct {
2323
wg *sync.WaitGroup
2424
}
2525

26+
var _ modules.Module = (*Client)(nil)
27+
2628
// NewClient -
2729
func NewClient(server string) *Client {
2830
return &Client{
@@ -113,12 +115,18 @@ func (client *Client) Output(name string) (*modules.Output, error) {
113115
}
114116

115117
// AttachTo -
116-
func (client *Client) AttachTo(name string, input *modules.Input) error {
117-
output, err := client.Output(name)
118+
func (client *Client) AttachTo(outputModule modules.Module, outputName, inputName string) error {
119+
outputChannel, err := outputModule.Output(outputName)
120+
if err != nil {
121+
return err
122+
}
123+
124+
input, err := client.Input(inputName)
118125
if err != nil {
119126
return err
120127
}
121-
output.Attach(input)
128+
129+
outputChannel.Attach(input)
122130
return nil
123131
}
124132

examples/grpc/custom.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,19 @@ func (m *CustomModule) Output(name string) (*modules.Output, error) {
4545
}
4646

4747
// AttachTo -
48-
func (m *CustomModule) AttachTo(name string, input *modules.Input) error {
49-
return errors.Wrap(modules.ErrUnknownOutput, name)
48+
func (m *CustomModule) AttachTo(outputModule modules.Module, outputName, inputName string) error {
49+
outputChannel, err := outputModule.Output(outputName)
50+
if err != nil {
51+
return err
52+
}
53+
54+
input, err := m.Input(inputName)
55+
if err != nil {
56+
return err
57+
}
58+
59+
outputChannel.Attach(input)
60+
return nil
5061
}
5162

5263
func (m *CustomModule) listen(ctx context.Context) {

examples/zipper/custom.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ func (m *CustomModule) Output(name string) (*modules.Output, error) {
4343
}
4444

4545
// AttachTo -
46-
func (m *CustomModule) AttachTo(name string, input *modules.Input) error {
47-
output, err := m.Output(name)
46+
func (m *CustomModule) AttachTo(outputModule modules.Module, outputName, inputName string) error {
47+
outputChannel, err := outputModule.Output(outputName)
4848
if err != nil {
4949
return err
5050
}
51-
output.Attach(input)
51+
52+
input, err := m.Input(inputName)
53+
if err != nil {
54+
return err
55+
}
56+
57+
outputChannel.Attach(input)
5258
return nil
5359
}
5460

examples/zipper/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ func main() {
1515
first := NewCustomModule(10, -1, "first")
1616
second := NewCustomModule(0, 1, "second")
1717

18-
if err := modules.Connect(first, zip, "output", zipper.FirstInputName); err != nil {
18+
if err := modules.Connect(first, zip, zipper.OutputName, zipper.FirstInputName); err != nil {
1919
log.Panic(err)
2020
}
21-
if err := modules.Connect(second, zip, "output", zipper.SecondInputName); err != nil {
21+
if err := modules.Connect(second, zip, zipper.OutputName, zipper.SecondInputName); err != nil {
2222
log.Panic(err)
2323
}
2424

2525
fakeInput := modules.NewInput("fake")
26-
if err := zip.AttachTo(zipper.OutputName, fakeInput); err != nil {
26+
zipOutput, err := zip.Output(zipper.OutputName)
27+
if err != nil {
2728
log.Panic(err)
2829
}
30+
zipOutput.Attach(fakeInput)
2931

3032
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
3133
defer cancel()

pkg/modules/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,3 @@ gRPC module where realized default client and server. Detailed docs can be found
9797
### Cron
9898

9999
Cron module implements cron scheduler. Detailed docs can be found [here](/pkg/modules/cron/).
100-
101-
### Duplicator
102-
103-
Duplicator module repeats signal from one of inputs to all outputs. Detailed docs can be found [here](/pkg/modules/duplicator/).

0 commit comments

Comments
 (0)