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