Skip to content

Commit e5fc747

Browse files
committed
feat: add basic source code
0 parents  commit e5fc747

File tree

6 files changed

+756
-0
lines changed

6 files changed

+756
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Sea Wolf
2+
3+
This is made for listening seaweedfs's file metadata changes.
4+
5+
## Install
6+
```bash
7+
go get github.com/tuxmart/seawolf
8+
```
9+
10+
## Usage
11+
12+
```golang
13+
package main
14+
15+
import (
16+
"github.com/tuxmart/seawolf/example"
17+
"github.com/tuxmart/seawolf/v1"
18+
)
19+
20+
func main() {
21+
listener := &example.LogFileEventHandler{}
22+
if err := seawolf.Run("localhost:18888", seawolf.WithListener(listener)); err != nil {
23+
panic(err)
24+
}
25+
}
26+
```
27+
28+
You could implement your own file listeners by implementing `FileListener` interface.
29+
30+
```golang
31+
type FileListener interface {
32+
Create(ev *filer_pb.SubscribeMetadataResponse)
33+
Delete(ev *filer_pb.SubscribeMetadataResponse)
34+
Update(ev *filer_pb.SubscribeMetadataResponse)
35+
Move(ev *filer_pb.SubscribeMetadataResponse)
36+
}
37+
```
38+
39+
## Reference
40+
+ [Filer Change Data Capture](https://github.com/seaweedfs/seaweedfs/wiki/Filer-Change-Data-Capture)

example/just_log.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package example
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
7+
)
8+
9+
type LogFileEventHandler struct {
10+
}
11+
12+
func (l *LogFileEventHandler) Create(ev *filer_pb.SubscribeMetadataResponse) {
13+
// System.out.println("created entry " + event.getDirectory() + "/" + notification.getNewEntry().getName());
14+
fmt.Printf("Created entry %s%s\n", ev.GetDirectory(), ev.GetEventNotification().GetNewEntry().GetName())
15+
}
16+
17+
func (l *LogFileEventHandler) Delete(ev *filer_pb.SubscribeMetadataResponse) {
18+
// System.out.println("deleted entry " + event.getDirectory() + "/" + notification.getOldEntry().getName())
19+
fmt.Printf("Deleted entry %s%s\n", ev.GetDirectory(), ev.GetEventNotification().GetOldEntry().GetName())
20+
}
21+
22+
func (l *LogFileEventHandler) Update(ev *filer_pb.SubscribeMetadataResponse) {
23+
// System.out.println("updated entry " + event.getDirectory() + "/" + notification.getNewEntry().getName())
24+
fmt.Printf("Updated entry %s%s\n", ev.GetDirectory(), ev.GetEventNotification().GetNewEntry().GetName())
25+
}
26+
27+
func (l *LogFileEventHandler) Move(ev *filer_pb.SubscribeMetadataResponse) {
28+
fmt.Printf("Moved %s%s to %s%s", ev.GetDirectory(), ev.GetEventNotification().GetOldEntry().GetName(), ev.GetEventNotification().GetNewParentPath(), ev.GetEventNotification().GetNewEntry().GetName())
29+
}

go.mod

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module github.com/tuxmart/seawolf
2+
3+
go 1.19
4+
5+
require (
6+
github.com/seaweedfs/seaweedfs v0.0.0-20230710161428-6f7008958e60
7+
google.golang.org/grpc v1.56.2
8+
)
9+
10+
require (
11+
github.com/beorn7/perks v1.0.1 // indirect
12+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
13+
github.com/disintegration/imaging v1.6.2 // indirect
14+
github.com/fsnotify/fsnotify v1.6.0 // indirect
15+
github.com/go-errors/errors v1.1.1 // indirect
16+
github.com/golang/protobuf v1.5.3 // indirect
17+
github.com/hashicorp/hcl v1.0.0 // indirect
18+
github.com/magiconair/properties v1.8.7 // indirect
19+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
20+
github.com/mitchellh/mapstructure v1.5.0 // indirect
21+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
22+
github.com/pkg/errors v0.9.1 // indirect
23+
github.com/prometheus/client_golang v1.16.0 // indirect
24+
github.com/prometheus/client_model v0.3.0 // indirect
25+
github.com/prometheus/common v0.42.0 // indirect
26+
github.com/prometheus/procfs v0.11.0 // indirect
27+
github.com/seaweedfs/goexif v1.0.3 // indirect
28+
github.com/spf13/afero v1.9.5 // indirect
29+
github.com/spf13/cast v1.5.1 // indirect
30+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
31+
github.com/spf13/pflag v1.0.5 // indirect
32+
github.com/spf13/viper v1.16.0 // indirect
33+
github.com/subosito/gotenv v1.4.2 // indirect
34+
github.com/viant/ptrie v0.3.0 // indirect
35+
github.com/viant/toolbox v0.33.2 // indirect
36+
golang.org/x/image v0.9.0 // indirect
37+
golang.org/x/net v0.12.0 // indirect
38+
golang.org/x/sys v0.10.0 // indirect
39+
golang.org/x/text v0.11.0 // indirect
40+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
41+
google.golang.org/protobuf v1.31.0 // indirect
42+
gopkg.in/ini.v1 v1.67.0 // indirect
43+
gopkg.in/yaml.v2 v2.4.0 // indirect
44+
gopkg.in/yaml.v3 v3.0.1 // indirect
45+
)

0 commit comments

Comments
 (0)