diff --git a/actor/context_test.go b/actor/context_test.go index 963678e..a56dd76 100644 --- a/actor/context_test.go +++ b/actor/context_test.go @@ -10,7 +10,7 @@ import ( ) func TestChildEventNoRaceCondition(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) assert.Nil(t, err) parentPID := e.SpawnFunc(func(c *Context) { @@ -30,7 +30,7 @@ func TestContextSendRepeat(t *testing.T) { mu sync.Mutex sr SendRepeater ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) @@ -57,7 +57,7 @@ func TestSpawnChildPID(t *testing.T) { childfn = func(c *Context) {} expectedPID = NewPID(LocalLookupAddr, "parent/1/child/1") ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) e.SpawnFunc(func(c *Context) { @@ -77,7 +77,7 @@ func TestChild(t *testing.T) { var ( wg = sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) e.SpawnFunc(func(c *Context) { @@ -99,7 +99,7 @@ func TestParent(t *testing.T) { wg = sync.WaitGroup{} parent = NewPID(LocalLookupAddr, "foo/bar/baz") ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) @@ -123,7 +123,7 @@ func TestParent(t *testing.T) { } func TestGetPID(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} wg.Add(1) @@ -142,7 +142,7 @@ func TestSpawnChild(t *testing.T) { var ( wg = sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) childFunc := func(c *Context) { diff --git a/actor/deadletter_test.go b/actor/deadletter_test.go index 65f976a..7b23296 100644 --- a/actor/deadletter_test.go +++ b/actor/deadletter_test.go @@ -11,7 +11,7 @@ import ( // TestDeadLetterCustom tests the custom deadletter handling. // It is using the custom deadletter receiver defined inline. func TestDeadLetterCustom(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) assert.NoError(t, err) wg := &sync.WaitGroup{} wg.Add(1) diff --git a/actor/engine.go b/actor/engine.go index 259442b..8c785d8 100644 --- a/actor/engine.go +++ b/actor/engine.go @@ -9,6 +9,7 @@ import ( "time" ) +// Remoter is an interface that abstract a remote that is tied to an engine. type Remoter interface { Address() string Send(*PID, any, *PID) @@ -34,19 +35,30 @@ type Engine struct { // EngineConfig holds the configuration of the engine. type EngineConfig struct { - Remote Remoter + remote Remoter } -// NewEngine returns a new actor Engine. -// No mandatory arguments, but you can pass in a EngineConfig struct to configure the engine -func NewEngine(opts *EngineConfig) (*Engine, error) { +// NewEngineConfig returns a new default EngineConfig. +func NewEngineConfig() EngineConfig { + return EngineConfig{} +} + +// WithRemote sets the remote which will configure the engine so its capable +// to send and receive messages over the network. +func (config EngineConfig) WithRemote(remote Remoter) EngineConfig { + config.remote = remote + return config +} + +// NewEngine returns a new actor Engine given an EngineConfig. +func NewEngine(config EngineConfig) (*Engine, error) { e := &Engine{} e.Registry = newRegistry(e) // need to init the registry in case we want a custom deadletter e.address = LocalLookupAddr - if opts != nil && opts.Remote != nil { - e.remote = opts.Remote - e.address = opts.Remote.Address() - err := opts.Remote.Start(e) + if config.remote != nil { + e.remote = config.remote + e.address = config.remote.Address() + err := config.remote.Start(e) if err != nil { return nil, fmt.Errorf("failed to start remote: %w", err) } diff --git a/actor/engine_test.go b/actor/engine_test.go index 83b0aa1..4c2855c 100644 --- a/actor/engine_test.go +++ b/actor/engine_test.go @@ -37,7 +37,7 @@ func newTickReceiver(wg *sync.WaitGroup) Producer { } func TestRegistryGetPID(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) expectedPID1 := e.SpawnFunc(func(c *Context) {}, "foo", WithID("1")) expectedPID2 := e.SpawnFunc(func(c *Context) {}, "foo", WithID("2")) pid := e.Registry.GetPID("foo", "1") @@ -47,7 +47,7 @@ func TestRegistryGetPID(t *testing.T) { } func TestSendToNilPID(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) e.Send(nil, "foo") } @@ -55,7 +55,7 @@ func TestSendRepeat(t *testing.T) { var ( wg = &sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) pid := e.Spawn(newTickReceiver(wg), "test") @@ -65,7 +65,7 @@ func TestSendRepeat(t *testing.T) { } func TestRestartsMaxRestarts(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) restarts := 2 type payload struct { @@ -94,7 +94,7 @@ func TestProcessInitStartOrder(t *testing.T) { wg = sync.WaitGroup{} started, init bool ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) pid := e.SpawnFunc(func(c *Context) { switch c.Message().(type) { @@ -117,7 +117,7 @@ func TestProcessInitStartOrder(t *testing.T) { } func TestRestarts(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} type payload struct { @@ -151,7 +151,7 @@ func TestSendWithSender(t *testing.T) { sender = NewPID("local", "sender") wg = sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) @@ -167,7 +167,7 @@ func TestSendWithSender(t *testing.T) { } func TestSendMsgRaceCon(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} @@ -187,7 +187,7 @@ func TestSendMsgRaceCon(t *testing.T) { } func TestSpawn(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} @@ -205,7 +205,7 @@ func TestSpawn(t *testing.T) { } func TestSpawnDuplicateId(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg := sync.WaitGroup{} pid1 := e.Spawn(NewTestProducer(t, func(t *testing.T, ctx *Context) {}), "dummy") @@ -220,7 +220,7 @@ func TestStopWaitGroup(t *testing.T) { wg = sync.WaitGroup{} x = int32(0) ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) @@ -242,7 +242,7 @@ func TestStop(t *testing.T) { var ( wg = sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) for i := 0; i < 4; i++ { wg.Add(1) @@ -268,7 +268,7 @@ func TestPoisonWaitGroup(t *testing.T) { wg = sync.WaitGroup{} x = int32(0) ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) wg.Add(1) @@ -290,7 +290,7 @@ func TestPoison(t *testing.T) { var ( wg = sync.WaitGroup{} ) - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) for i := 0; i < 4; i++ { wg.Add(1) @@ -316,7 +316,7 @@ func TestRequestResponse(t *testing.T) { type responseEvent struct { d time.Duration } - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) assert.NoError(t, err) a := e.SpawnFunc(func(c *Context) { switch c.Message().(type) { @@ -346,7 +346,7 @@ func TestRequestResponse(t *testing.T) { } func TestPoisonPillPrivate(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) successCh := make(chan struct{}, 1) failCh := make(chan struct{}, 1) @@ -373,7 +373,7 @@ func TestPoisonPillPrivate(t *testing.T) { // 45.84 ns/op 25 B/op => 13th Gen Intel(R) Core(TM) i9-13900KF func BenchmarkSendMessageLocal(b *testing.B) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(b, err) pid := e.SpawnFunc(func(_ *Context) {}, "bench", WithInboxSize(128)) @@ -386,7 +386,7 @@ func BenchmarkSendMessageLocal(b *testing.B) { } func BenchmarkSendWithSenderMessageLocal(b *testing.B) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(b, err) p := NewTestProducer(nil, func(_ *testing.T, _ *Context) {}) pid := e.Spawn(p, "bench", WithInboxSize(1024*8)) diff --git a/actor/event_stream_test.go b/actor/event_stream_test.go index 2d19428..4d39210 100644 --- a/actor/event_stream_test.go +++ b/actor/event_stream_test.go @@ -13,7 +13,7 @@ type CustomEvent struct { } func TestEventStreamLocal(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) assert.NoError(t, err) wg := sync.WaitGroup{} wg.Add(2) @@ -43,7 +43,7 @@ func TestEventStreamLocal(t *testing.T) { } func TestEventStreamActorStartedEvent(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) wg := sync.WaitGroup{} wg.Add(1) @@ -61,7 +61,7 @@ func TestEventStreamActorStartedEvent(t *testing.T) { } func TestEventStreamActorStoppedEvent(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) wg := sync.WaitGroup{} wg.Add(1) diff --git a/actor/event_test.go b/actor/event_test.go index 6229bca..f1a4eed 100644 --- a/actor/event_test.go +++ b/actor/event_test.go @@ -1,13 +1,14 @@ package actor import ( - "github.com/stretchr/testify/assert" "sync" "testing" + + "github.com/stretchr/testify/assert" ) func TestDuplicateIdEvent(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) assert.NoError(t, err) wg := sync.WaitGroup{} wg.Add(1) diff --git a/actor/process_test.go b/actor/process_test.go index b0e7dc9..9256f3d 100644 --- a/actor/process_test.go +++ b/actor/process_test.go @@ -3,15 +3,16 @@ package actor import ( "bytes" "fmt" - "github.com/stretchr/testify/require" "testing" "time" + + "github.com/stretchr/testify/require" ) // Test_CleanTrace tests that the stack trace is cleaned up correctly and that the function // which triggers the panic is at the top of the stack trace. func Test_CleanTrace(t *testing.T) { - e, err := NewEngine(nil) + e, err := NewEngine(NewEngineConfig()) require.NoError(t, err) type triggerPanic struct { data int diff --git a/actor/registry_test.go b/actor/registry_test.go index fc67b60..9914fff 100644 --- a/actor/registry_test.go +++ b/actor/registry_test.go @@ -17,7 +17,7 @@ func (p fooProc) Invoke([]Envelope) {} func (p fooProc) Shutdown(*sync.WaitGroup) {} func TestGetRemoveAdd(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) reg := newRegistry(e) eproc := fooProc{} reg.add(eproc) diff --git a/cluster/agent.go b/cluster/agent.go index 0f91b3b..3d38226 100644 --- a/cluster/agent.go +++ b/cluster/agent.go @@ -20,14 +20,13 @@ type ( getActive struct{ id string } ) +// Agent is an actor/receiver that is responsible for managing the state +// of the cluster. type Agent struct { - members *MemberSet - cluster *Cluster - - kinds map[string]bool - + members *MemberSet + cluster *Cluster + kinds map[string]bool localKinds map[string]kind - // All the actors that are available cluster wide. activated map[string]*actor.PID } @@ -142,7 +141,7 @@ func (a *Agent) activate(kind, id, region string) *actor.PID { activationResp = a.handleActivationRequest(req) } else { // Remote activation - + // // TODO: topology hash resp, err := a.cluster.engine.Request(activatorPID, req, a.cluster.config.requestTimeout).Result() if err != nil { diff --git a/cluster/cluster.go b/cluster/cluster.go index 56f9f68..dca35ce 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -119,7 +119,7 @@ type Cluster struct { func New(config Config) (*Cluster, error) { if config.engine == nil { remote := remote.New(config.listenAddr, nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: remote}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(remote)) if err != nil { return nil, err } diff --git a/cluster/cluster_test.go b/cluster/cluster_test.go index 07ef320..9927fe3 100644 --- a/cluster/cluster_test.go +++ b/cluster/cluster_test.go @@ -200,7 +200,7 @@ func TestMemberLeave(t *testing.T) { c2Addr := getRandomLocalhostAddr() remote := remote.New(c2Addr, nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: remote}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(remote)) if err != nil { log.Fatal(err) } diff --git a/cluster/selfmanaged.go b/cluster/selfmanaged.go index 66eb166..e80d4d1 100644 --- a/cluster/selfmanaged.go +++ b/cluster/selfmanaged.go @@ -109,6 +109,7 @@ func (s *SelfManaged) Receive(c *actor.Context) { member := s.members.GetByHost(msg.ListenAddr) s.removeMember(member) case *actor.Ping: + case actor.Initialized: _ = msg default: slog.Warn("received unhandled message", "msg", msg, "t", reflect.TypeOf(msg)) diff --git a/examples/chat/client/main.go b/examples/chat/client/main.go index 366ecc7..2b8fb89 100644 --- a/examples/chat/client/main.go +++ b/examples/chat/client/main.go @@ -4,12 +4,13 @@ import ( "bufio" "flag" "fmt" - "github.com/anthdm/hollywood/actor" - "github.com/anthdm/hollywood/examples/chat/types" - "github.com/anthdm/hollywood/remote" "log/slog" "math/rand" "os" + + "github.com/anthdm/hollywood/actor" + "github.com/anthdm/hollywood/examples/chat/types" + "github.com/anthdm/hollywood/remote" ) type client struct { @@ -52,7 +53,7 @@ func main() { *listenAt = fmt.Sprintf("127.0.0.1:%d", rand.Int31n(50000)+10000) } rem := remote.New(*listenAt, nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: rem}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(rem)) if err != nil { slog.Error("failed to create engine", "err", err) os.Exit(1) diff --git a/examples/chat/server/main.go b/examples/chat/server/main.go index a372028..b881d44 100644 --- a/examples/chat/server/main.go +++ b/examples/chat/server/main.go @@ -82,7 +82,7 @@ func main() { ) flag.Parse() rem := remote.New(*listenAt, nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: rem}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(rem)) if err != nil { panic(err) } diff --git a/examples/childprocs/main.go b/examples/childprocs/main.go index 1447e77..a4f5a59 100644 --- a/examples/childprocs/main.go +++ b/examples/childprocs/main.go @@ -62,7 +62,7 @@ type message struct { } func main() { - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/eventstream-monitor/main.go b/examples/eventstream-monitor/main.go index b5cacfe..78d0509 100644 --- a/examples/eventstream-monitor/main.go +++ b/examples/eventstream-monitor/main.go @@ -51,7 +51,6 @@ func (m *monitor) Receive(c *actor.Context) { type customMessage struct{} type unstableActor struct { - restarts int spawnTime time.Time } @@ -73,7 +72,7 @@ func (m *unstableActor) Receive(c *actor.Context) { } func main() { - e, _ := actor.NewEngine(nil) + e, _ := actor.NewEngine(actor.NewEngineConfig()) // Spawn a monitor actor and then an unstable actor. monitor := e.Spawn(newMonitor, "monitor") ua := e.Spawn(newUnstableActor, "unstable_actor", actor.WithMaxRestarts(10000)) diff --git a/examples/eventstream/main.go b/examples/eventstream/main.go index c248ea3..340609f 100644 --- a/examples/eventstream/main.go +++ b/examples/eventstream/main.go @@ -15,7 +15,7 @@ type MyCustomEvent struct { // Spawn 2 actors and subscribe them to the event stream. // When we call engine.PublishEvent both actors will be notified. func main() { - e, _ := actor.NewEngine(nil) + e, _ := actor.NewEngine(actor.NewEngineConfig()) actorA := e.SpawnFunc(func(c *actor.Context) { switch msg := c.Message().(type) { case actor.Started: diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go index 1c986a4..461961f 100644 --- a/examples/helloworld/main.go +++ b/examples/helloworld/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/anthdm/hollywood/actor" ) @@ -38,7 +39,7 @@ func main() { fmt.Printf("ds len: %d\n", len(ds)) fmt.Printf("%+v\n", ds) - engine, err := actor.NewEngine(nil) + engine, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/mdns/main.go b/examples/mdns/main.go index 484f38d..aabffcf 100644 --- a/examples/mdns/main.go +++ b/examples/mdns/main.go @@ -3,13 +3,14 @@ package main import ( "flag" "fmt" + "log/slog" + "math/rand" + "os" + "github.com/anthdm/hollywood/actor" "github.com/anthdm/hollywood/examples/mdns/chat" "github.com/anthdm/hollywood/examples/mdns/discovery" "github.com/anthdm/hollywood/remote" - "log/slog" - "math/rand" - "os" ) var ( @@ -25,7 +26,7 @@ func main() { *port = rand.Intn(10000) + 2000 } rem := remote.New(fmt.Sprintf("%s:%d", *ip, *port), nil) - engine, err := actor.NewEngine(&actor.EngineConfig{Remote: rem}) + engine, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(rem)) if err != nil { panic(err) } diff --git a/examples/metrics/main.go b/examples/metrics/main.go index f00c721..fcb22c7 100644 --- a/examples/metrics/main.go +++ b/examples/metrics/main.go @@ -86,7 +86,7 @@ func main() { go func() { http.ListenAndServe(*promListenAddr, promhttp.Handler()) }() - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/middleware/hooks/main.go b/examples/middleware/hooks/main.go index 3424af7..a42f5b7 100644 --- a/examples/middleware/hooks/main.go +++ b/examples/middleware/hooks/main.go @@ -44,7 +44,7 @@ func WithHooks() func(actor.ReceiveFunc) actor.ReceiveFunc { func main() { // Create a new engine - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/persistance/main.go b/examples/persistance/main.go index 684b238..602fbec 100644 --- a/examples/persistance/main.go +++ b/examples/persistance/main.go @@ -143,7 +143,7 @@ func (r *fileStore) Load(key string) ([]byte, error) { } func main() { - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { log.Fatal(err) } diff --git a/examples/remote/client/main.go b/examples/remote/client/main.go index d0d6d08..852fb9a 100644 --- a/examples/remote/client/main.go +++ b/examples/remote/client/main.go @@ -13,7 +13,7 @@ import ( func main() { slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))) r := remote.New("127.0.0.1:3000", nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: r}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(r)) if err != nil { panic(err) } diff --git a/examples/remote/server/main.go b/examples/remote/server/main.go index 7d438ad..1e481f4 100644 --- a/examples/remote/server/main.go +++ b/examples/remote/server/main.go @@ -34,7 +34,7 @@ func (f *server) Receive(ctx *actor.Context) { func main() { slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))) r := remote.New("127.0.0.1:4000", nil) - e, err := actor.NewEngine(&actor.EngineConfig{Remote: r}) + e, err := actor.NewEngine(actor.NewEngineConfig().WithRemote(r)) if err != nil { panic(err) } diff --git a/examples/request/main.go b/examples/request/main.go index 7a2745a..7aa0b03 100644 --- a/examples/request/main.go +++ b/examples/request/main.go @@ -43,7 +43,7 @@ func (r *nameResponder) Receive(ctx *actor.Context) { // actor is spawned with a custom name, showing you how to pass custom // arguments to your actors. func main() { - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { log.Fatal(err) } diff --git a/examples/restarts/main.go b/examples/restarts/main.go index d723850..8b370b9 100644 --- a/examples/restarts/main.go +++ b/examples/restarts/main.go @@ -34,7 +34,7 @@ func (f *foo) Receive(ctx *actor.Context) { } func main() { - engine, err := actor.NewEngine(nil) + engine, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/tcpserver/main.go b/examples/tcpserver/main.go index e0cfca2..3034a4c 100644 --- a/examples/tcpserver/main.go +++ b/examples/tcpserver/main.go @@ -142,7 +142,7 @@ func (s *server) acceptLoop(c *actor.Context) { func main() { listenAddr := flag.String("listenaddr", ":6000", "listen address of the TCP server") - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { panic(err) } diff --git a/examples/trade-engine/main.go b/examples/trade-engine/main.go index f26dbfd..ce27f18 100644 --- a/examples/trade-engine/main.go +++ b/examples/trade-engine/main.go @@ -17,7 +17,7 @@ func main() { // this script creates a trade order, gets the trade info and then cancels the order // create the actor engine - e, err := actor.NewEngine(nil) + e, err := actor.NewEngine(actor.NewEngineConfig()) if err != nil { fmt.Printf("failed to create actor engine: %v", err) os.Exit(1) diff --git a/remote/remote_test.go b/remote/remote_test.go index d4197e8..1127a78 100644 --- a/remote/remote_test.go +++ b/remote/remote_test.go @@ -219,7 +219,7 @@ func makeRemoteEngine(listenAddr string) (*actor.Engine, *Remote, error) { var e *actor.Engine r := New(listenAddr, nil) var err error - e, err = actor.NewEngine(&actor.EngineConfig{Remote: r}) + e, err = actor.NewEngine(actor.NewEngineConfig().WithRemote(r)) if err != nil { return nil, nil, fmt.Errorf("actor.NewEngine: %w", err) } diff --git a/remote/remote_tls_test.go b/remote/remote_tls_test.go index 910b9f1..4892214 100644 --- a/remote/remote_tls_test.go +++ b/remote/remote_tls_test.go @@ -9,13 +9,14 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" - "github.com/anthdm/hollywood/actor" - "github.com/stretchr/testify/assert" "math/big" "net" "sync" "testing" "time" + + "github.com/anthdm/hollywood/actor" + "github.com/stretchr/testify/assert" ) type sharedConfig struct { @@ -172,7 +173,7 @@ func makeRemoteEngineTls(listenAddr string, config *tls.Config) (*actor.Engine, var eng *actor.Engine var err error rem := New(listenAddr, &Config{TlsConfig: config}) - eng, err = actor.NewEngine(&actor.EngineConfig{Remote: rem}) + eng, err = actor.NewEngine(actor.NewEngineConfig().WithRemote(rem)) if err != nil { return nil, nil, fmt.Errorf("actor.NewEngine: %w", err) }