ergo
/
ergo.go
70 строк · 2.3 Кб
1package ergo
2
3import (
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
16func StartNode(name string, cookie string, opts node.Options) (node.Node, error) {
17return StartNodeWithContext(context.Background(), name, cookie, opts)
18}
19
20// StartNodeWithContext create new node with specified context, name and cookie string
21func StartNodeWithContext(ctx context.Context, name string, cookie string, opts node.Options) (node.Node, error) {
22version := node.Version{
23Release: Version,
24Prefix: VersionPrefix,
25OTP: VersionOTP,
26}
27if opts.Env == nil {
28opts.Env = make(map[gen.EnvKey]interface{})
29}
30opts.Env[node.EnvKeyVersion] = version
31
32// add default applications:
33defaultApps := []gen.ApplicationBehavior{
34system.CreateApp(opts.System), // system application (bus, metrics etc.)
35erlang.CreateApp(), // erlang support
36}
37
38// add cloud support if it's enabled
39if opts.Cloud.Enable {
40cloudApp := cloud.CreateApp(opts.Cloud)
41defaultApps = append(defaultApps, cloudApp)
42if opts.Proxy.Accept == false {
43lib.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}
46opts.Applications = append(defaultApps, opts.Applications...)
47
48if opts.Handshake == nil {
49// create default handshake for the node (Erlang Dist Handshake)
50opts.Handshake = dist.CreateHandshake(dist.HandshakeOptions{})
51}
52
53if opts.Proto == nil {
54// create default proto handler (Erlang Dist Proto)
55protoOptions := node.DefaultProtoOptions()
56opts.Proto = dist.CreateProto(protoOptions)
57}
58
59if opts.StaticRoutesOnly == false && opts.Registrar == nil {
60// create default registrar (with enabled Erlang EPMD server)
61opts.Registrar = dist.CreateRegistrarWithLocalEPMD("", dist.DefaultEPMDPort)
62}
63
64if len(opts.Listeners) == 0 {
65listener := node.DefaultListener()
66opts.Listeners = append(opts.Listeners, listener)
67}
68
69return node.StartWithContext(ctx, name, cookie, opts)
70}
71