@@ -11,6 +11,7 @@ import (
1111)
1212
1313type SeaWolf struct {
14+ client filer_pb.SeaweedFilerClient
1415 Listeners []internal.FileListener
1516}
1617
@@ -22,26 +23,30 @@ func WithListener(listener internal.FileListener) Option {
2223 }
2324}
2425
25- func Run (address string , opts ... Option ) error {
26+ func New (address string , opts ... Option ) * SeaWolf {
2627 conn , err := grpc .Dial (address , grpc .WithInsecure ())
2728 if err != nil {
28- return err
29+ panic ( err )
2930 }
3031 defer conn .Close ()
32+ client := filer_pb .NewSeaweedFilerClient (conn )
3133
3234 wolf := & SeaWolf {
35+ client : client ,
3336 Listeners : make ([]internal.FileListener , 0 ),
3437 }
3538
3639 for _ , opt := range opts {
3740 opt (wolf )
3841 }
3942
40- client := filer_pb .NewSeaweedFilerClient (conn )
43+ return wolf
44+ }
4145
46+ func (wolf * SeaWolf ) Run () error {
4247 fmt .Println ("Listening file metadata..." )
4348 for {
44- req , err := client .SubscribeMetadata (context .TODO (), & filer_pb.SubscribeMetadataRequest {
49+ req , err := wolf . client .SubscribeMetadata (context .TODO (), & filer_pb.SubscribeMetadataRequest {
4550 SinceNs : time .Now ().UnixNano (),
4651 })
4752 if err != nil {
@@ -78,3 +83,7 @@ func Run(address string, opts ...Option) error {
7883 }
7984 }
8085}
86+
87+ func (wolf * SeaWolf ) Client () filer_pb.SeaweedFilerClient {
88+ return wolf .client
89+ }
0 commit comments