forked from ergo-services/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ergo.go
49 lines (40 loc) · 1.52 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
package ergo
import (
"context"
"github.com/ergo-services/ergo/erlang"
"github.com/ergo-services/ergo/gen"
"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 erlang support application
opts.Applications = append([]gen.ApplicationBehavior{&erlang.KernelApp{}}, 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.Resolver == nil {
// create default resolver (with enabled Erlang EPMD server)
opts.Resolver = dist.CreateResolverWithLocalEPMD("", dist.DefaultEPMDPort)
}
return node.StartWithContext(ctx, name, cookie, opts)
}