github.com/ergo-services/ergo@v1.999.224/ergo.go (about) 1 package ergo 2 3 import ( 4 "context" 5 6 "github.com/ergo-services/ergo/apps/cloud" 7 "github.com/ergo-services/ergo/apps/erlang" 8 "github.com/ergo-services/ergo/apps/system" 9 "github.com/ergo-services/ergo/gen" 10 "github.com/ergo-services/ergo/lib" 11 "github.com/ergo-services/ergo/node" 12 "github.com/ergo-services/ergo/proto/dist" 13 ) 14 15 // StartNode create new node with name and cookie string 16 func StartNode(name string, cookie string, opts node.Options) (node.Node, error) { 17 return StartNodeWithContext(context.Background(), name, cookie, opts) 18 } 19 20 // StartNodeWithContext create new node with specified context, name and cookie string 21 func StartNodeWithContext(ctx context.Context, name string, cookie string, opts node.Options) (node.Node, error) { 22 version := node.Version{ 23 Release: Version, 24 Prefix: VersionPrefix, 25 OTP: VersionOTP, 26 } 27 if opts.Env == nil { 28 opts.Env = make(map[gen.EnvKey]interface{}) 29 } 30 opts.Env[node.EnvKeyVersion] = version 31 32 // add default applications: 33 defaultApps := []gen.ApplicationBehavior{ 34 system.CreateApp(opts.System), // system application (bus, metrics etc.) 35 erlang.CreateApp(), // erlang support 36 } 37 38 // add cloud support if it's enabled 39 if opts.Cloud.Enable { 40 cloudApp := cloud.CreateApp(opts.Cloud) 41 defaultApps = append(defaultApps, cloudApp) 42 if opts.Proxy.Accept == false { 43 lib.Warning("Disabled option Proxy.Accept makes this node inaccessible to the other nodes within your cloud cluster, but it still allows initiate connection to the others with this option enabled.") 44 } 45 } 46 opts.Applications = append(defaultApps, opts.Applications...) 47 48 if opts.Handshake == nil { 49 // create default handshake for the node (Erlang Dist Handshake) 50 opts.Handshake = dist.CreateHandshake(dist.HandshakeOptions{}) 51 } 52 53 if opts.Proto == nil { 54 // create default proto handler (Erlang Dist Proto) 55 protoOptions := node.DefaultProtoOptions() 56 opts.Proto = dist.CreateProto(protoOptions) 57 } 58 59 if opts.StaticRoutesOnly == false && opts.Registrar == nil { 60 // create default registrar (with enabled Erlang EPMD server) 61 opts.Registrar = dist.CreateRegistrarWithLocalEPMD("", dist.DefaultEPMDPort) 62 } 63 64 if len(opts.Listeners) == 0 { 65 listener := node.DefaultListener() 66 opts.Listeners = append(opts.Listeners, listener) 67 } 68 69 return node.StartWithContext(ctx, name, cookie, opts) 70 }