Skip to content

Commit

Permalink
Merge pull request #40 from moleculer-go/develop
Browse files Browse the repository at this point in the history
publish docs
  • Loading branch information
pentateu authored Mar 22, 2019
2 parents 84e0712 + 508d722 commit ef63dde
Show file tree
Hide file tree
Showing 239 changed files with 20,106 additions and 150 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Lightning fast, lightweight, simple and fun to develop with. Also easy, very easy to test ;)

[![Gitter](https://badges.gitter.im/moleculer-go/community.svg)](https://gitter.im/moleculer-go/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

[![Build Status](https://travis-ci.org/moleculer-go/moleculer.svg?branch=master)](https://travis-ci.org/moleculer-go/moleculer)
[![Go Report Card](https://goreportcard.com/badge/github.com/moleculer-go/moleculer)](https://goreportcard.com/report/github.com/moleculer-go/moleculer)
[![Coverage Status](https://coveralls.io/repos/github/moleculer-go/moleculer/badge.svg?branch=master)](https://coveralls.io/github/moleculer-go/moleculer?branch=master)
Expand Down
16 changes: 8 additions & 8 deletions broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
log "github.com/sirupsen/logrus"
)

func mergeConfigs(baseConfig moleculer.BrokerConfig, userConfig []*moleculer.BrokerConfig) moleculer.BrokerConfig {
func mergeConfigs(baseConfig moleculer.Config, userConfig []*moleculer.Config) moleculer.Config {
if len(userConfig) > 0 {
for _, config := range userConfig {
if config.LogLevel != "" {
Expand Down Expand Up @@ -85,7 +85,7 @@ type ServiceBroker struct {

rootContext moleculer.BrokerContext

config moleculer.BrokerConfig
config moleculer.Config

delegates moleculer.BrokerDelegates

Expand Down Expand Up @@ -372,9 +372,9 @@ func (broker *ServiceBroker) init() {

broker.registerMiddlewares()

broker.logger.Debug("brokerConfig middleware before: \n", broker.config)
broker.config = broker.middlewares.CallHandlers("brokerConfig", broker.config).(moleculer.BrokerConfig)
broker.logger.Debug("brokerConfig middleware after: \n", broker.config)
broker.logger.Debug("Config middleware before: \n", broker.config)
broker.config = broker.middlewares.CallHandlers("Config", broker.config).(moleculer.Config)
broker.logger.Debug("Config middleware after: \n", broker.config)

broker.delegates = broker.createDelegates()
broker.registry = registry.CreateRegistry(broker.delegates)
Expand Down Expand Up @@ -419,12 +419,12 @@ func (broker *ServiceBroker) createDelegates() moleculer.BrokerDelegates {
}
}

// FromConfig : returns a valid broker based on environment configuration
// New : returns a valid broker based on environment configuration
// this is usually called when creating a broker to starting the service(s)
func FromConfig(userConfig ...*moleculer.BrokerConfig) *ServiceBroker {
func New(userConfig ...*moleculer.Config) *ServiceBroker {
config := mergeConfigs(moleculer.DefaultConfig, userConfig)
broker := ServiceBroker{config: config}
broker.init()
broker.logger.Info("Broker - FromConfig() ")
broker.logger.Info("Broker - New() ")
return &broker
}
68 changes: 34 additions & 34 deletions broker/broker_internals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Broker Internals", func() {
verse := "3 little birds..."
chorus := "don't worry..."
mem := &memory.SharedMemory{}
baseConfig := &moleculer.BrokerConfig{
baseConfig := &moleculer.Config{
LogLevel: logLevel,
TransporterFactory: func() interface{} {
transport := memory.Create(log.WithField("transport", "memory"), mem)
Expand All @@ -39,7 +39,7 @@ var _ = Describe("Broker Internals", func() {
currentStep++
fmt.Println("\n############# New Test Cycle step: ", currentStep, " #############")

soundsBroker := FromConfig(baseConfig, &moleculer.BrokerConfig{
soundsBroker := New(baseConfig, &moleculer.Config{
DiscoverNodeID: func() string { return "SoundsBroker" },
})
soundsBroker.AddService(moleculer.Service{
Expand Down Expand Up @@ -138,7 +138,7 @@ var _ = Describe("Broker Internals", func() {
Expect(counters.Check("music.music.chorus", 3)).ShouldNot(HaveOccurred())
Expect(counters.Check("dj.music.chorus", 3)).ShouldNot(HaveOccurred())

visualBroker := FromConfig(baseConfig, &moleculer.BrokerConfig{
visualBroker := New(baseConfig, &moleculer.Config{
DiscoverNodeID: func() string { return "VisualBroker" },
})
visualBroker.localBus.On("$node.disconnected", func(data ...interface{}) {
Expand Down Expand Up @@ -206,7 +206,7 @@ var _ = Describe("Broker Internals", func() {

fmt.Println("\n############# second instance of the VJ service #############")
//add a second instance of the vj service, but only one should receive emit events.
aquaBroker := FromConfig(baseConfig, &moleculer.BrokerConfig{
aquaBroker := New(baseConfig, &moleculer.Config{
DiscoverNodeID: func() string { return "AquaBroker" },
})
aquaBroker.AddService(vjService)
Expand Down Expand Up @@ -240,7 +240,7 @@ var _ = Describe("Broker Internals", func() {

fmt.Println("\n############# second instance of the DJ service #############")
//add a second instance of the dj service
stormBroker := FromConfig(baseConfig, &moleculer.BrokerConfig{
stormBroker := New(baseConfig, &moleculer.Config{
DiscoverNodeID: func() string { return "StormBroker" },
})
stormBroker.AddService(djService)
Expand Down Expand Up @@ -356,8 +356,8 @@ var _ = Describe("Broker Internals", func() {
}
logLevel := "FATAL"
mem := &memory.SharedMemory{}
bkr1 := FromConfig(
&moleculer.BrokerConfig{
bkr1 := New(
&moleculer.Config{
MCallTimeout: MCallTimeout,
LogLevel: logLevel,
DiscoverNodeID: func() string { return "test-broker1" },
Expand All @@ -381,8 +381,8 @@ var _ = Describe("Broker Internals", func() {
},
})

bkr2 := FromConfig(
&moleculer.BrokerConfig{
bkr2 := New(
&moleculer.Config{
MCallTimeout: MCallTimeout,
LogLevel: logLevel,
DiscoverNodeID: func() string { return "test-broker2" },
Expand Down Expand Up @@ -480,70 +480,70 @@ var _ = Describe("Broker Internals", func() {

It("Should register user middlewares", func() {

config := moleculer.BrokerConfig{DisableInternalMiddlewares: true}
bkr := FromConfig(&config)
Expect(bkr.middlewares.Has("brokerConfig")).Should(BeFalse())
config := moleculer.Config{DisableInternalMiddlewares: true}
bkr := New(&config)
Expect(bkr.middlewares.Has("Config")).Should(BeFalse())

config = moleculer.BrokerConfig{
config = moleculer.Config{
DisableInternalMiddlewares: true,
Middlewares: []moleculer.Middlewares{
map[string]moleculer.MiddlewareHandler{
"brokerConfig": func(params interface{}, next func(...interface{})) {
"Config": func(params interface{}, next func(...interface{})) {
next()
},
},
},
}
bkr = FromConfig(&config)
bkr = New(&config)
fmt.Println(bkr.config)
fmt.Println(bkr.middlewares)
Expect(bkr.middlewares.Has("brokerConfig")).Should(BeTrue())
Expect(bkr.middlewares.Has("Config")).Should(BeTrue())
Expect(bkr.middlewares.Has("anotherOne")).Should(BeFalse())
})

It("Should call brokerConfig middleware on Start and not change the config", func() {
It("Should call Config middleware on Start and not change the config", func() {

brokerConfigCalls := 0
config := moleculer.BrokerConfig{
ConfigCalls := 0
config := moleculer.Config{
DontWaitForNeighbours: true,
DisableInternalMiddlewares: true,
Middlewares: []moleculer.Middlewares{
map[string]moleculer.MiddlewareHandler{
"brokerConfig": func(params interface{}, next func(...interface{})) {
brokerConfigCalls++
"Config": func(params interface{}, next func(...interface{})) {
ConfigCalls++
next()
},
},
},
}
bkr := FromConfig(&config)
Expect(bkr.middlewares.Has("brokerConfig")).Should(BeTrue())
bkr := New(&config)
Expect(bkr.middlewares.Has("Config")).Should(BeTrue())
bkr.Start()
Expect(brokerConfigCalls).Should(Equal(1))
Expect(ConfigCalls).Should(Equal(1))
bkr.Stop()
})

It("Should call brokerConfig middleware on Start and not change the config", func() {
It("Should call Config middleware on Start and not change the config", func() {

brokerConfigCalls := 0
config := moleculer.BrokerConfig{
ConfigCalls := 0
config := moleculer.Config{
DontWaitForNeighbours: true,
Metrics: true,
Middlewares: []moleculer.Middlewares{
map[string]moleculer.MiddlewareHandler{
"brokerConfig": func(params interface{}, next func(...interface{})) {
brokerConfig := params.(moleculer.BrokerConfig)
brokerConfig.Metrics = false
brokerConfigCalls++
next(brokerConfig)
"Config": func(params interface{}, next func(...interface{})) {
Config := params.(moleculer.Config)
Config.Metrics = false
ConfigCalls++
next(Config)
},
},
},
}
Expect(config.Metrics).Should(BeTrue())
bkr := FromConfig(&config)
bkr := New(&config)
bkr.Start()
Expect(brokerConfigCalls).Should(Equal(1))
Expect(ConfigCalls).Should(Equal(1))
Expect(bkr.config.Metrics).Should(BeFalse())
bkr.Stop()
})
Expand Down
14 changes: 7 additions & 7 deletions broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Broker", func() {
},
}

broker := broker.FromConfig(&moleculer.BrokerConfig{
broker := broker.New(&moleculer.Config{
LogLevel: "ERROR",
})
broker.AddService(service)
Expand Down Expand Up @@ -60,17 +60,17 @@ var _ = Describe("Broker", func() {
},
}
mem := &memory.SharedMemory{}
baseConfig := &moleculer.BrokerConfig{
baseConfig := &moleculer.Config{
LogLevel: "DEBUG",
TransporterFactory: func() interface{} {
transport := memory.Create(log.WithField("transport", "memory"), mem)
return &transport
},
}
bkrConfig := &moleculer.BrokerConfig{
bkrConfig := &moleculer.Config{
DiscoverNodeID: func() string { return "do-broker" },
}
bkr := broker.FromConfig(baseConfig, bkrConfig)
bkr := broker.New(baseConfig, bkrConfig)
bkr.AddService(service)
bkr.Start()

Expand All @@ -96,10 +96,10 @@ var _ = Describe("Broker", func() {
},
},
}
bkrConfig = &moleculer.BrokerConfig{
bkrConfig = &moleculer.Config{
DiscoverNodeID: func() string { return "remote-broker" },
}
bkr = broker.FromConfig(baseConfig, bkrConfig)
bkr = broker.New(baseConfig, bkrConfig)
bkr.AddService(service)
bkr.Start()

Expand Down Expand Up @@ -144,7 +144,7 @@ var _ = Describe("Broker", func() {
},
}

broker := broker.FromConfig(&moleculer.BrokerConfig{
broker := broker.New(&moleculer.Config{
LogLevel: "ERROR",
})
broker.AddService(service)
Expand Down
11 changes: 10 additions & 1 deletion context/contextFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ func EventContext(broker moleculer.BrokerDelegates, values map[string]interface{
level: level,
}
if values["groups"] != nil {
newContext.groups = values["groups"].([]string)
temp := values["groups"]
aTransformer := payload.ArrayTransformer(&temp)
if aTransformer != nil {
iArray := aTransformer.InterfaceArray(&temp)
sGroups := make([]string, len(iArray))
for index, item := range iArray {
sGroups[index] = item.(string)
}
newContext.groups = sGroups
}
}
return &newContext
}
Expand Down
6 changes: 3 additions & 3 deletions context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var _ = g.Describe("Context", func() {

g.It("Should be able to cast into moleculer.Context", func() {
delegates := test.DelegatesWithIdAndConfig("x", moleculer.BrokerConfig{})
delegates := test.DelegatesWithIdAndConfig("x", moleculer.Config{})
rawContext := BrokerContext(delegates)
Expect(func() {
moleculerContest := rawContext.(moleculer.Context)
Expand All @@ -21,7 +21,7 @@ var _ = g.Describe("Context", func() {

g.It("Should create a child context with metrics on", func() {

config := moleculer.BrokerConfig{
config := moleculer.Config{
Metrics: true,
}
brokerContext := BrokerContext(test.DelegatesWithIdAndConfig("nodex", config))
Expand All @@ -33,7 +33,7 @@ var _ = g.Describe("Context", func() {
Expect(eventContext.Meta()).ShouldNot(BeNil())
Expect((*eventContext.Meta())["metrics"]).Should(BeTrue())

config = moleculer.BrokerConfig{
config = moleculer.Config{
Metrics: false,
}
brokerContext = BrokerContext(test.DelegatesWithIdAndConfig("nodex", config))
Expand Down
1 change: 1 addition & 0 deletions docs/0.12/docs/benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/benchmark.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/benchmark.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/broker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/broker.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/broker.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/cachers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/cachers.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/cachers.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/circuit-breaker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/circuit-breaker.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/circuit-breaker.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/context.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/context.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/context.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/contributing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/contributing.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/contributing.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/docker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/docker.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/docker.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/errors.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/errors.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/examples.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/examples.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/examples.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/faq.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/faq.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/faq.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/logger.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/logger.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/logger.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/metrics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/metrics.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/metrics.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/modules.html"><meta http-equiv="refresh" content="0; url=/modules.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/moleculer-cli.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/moleculer-cli.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/moleculer-cli.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/moleculer-repl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/moleculer-repl.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/moleculer-repl.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/moleculer-web.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/moleculer-web.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/moleculer-web.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/nodes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/nodes.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/nodes.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/runner.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/runner.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/serializers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/serializers.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/serializers.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/serverless.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/serverless.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/serverless.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/service-registry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/service-registry.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/service-registry.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/service.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/service.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/service.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/statistics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/statistics.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/statistics.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/support.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/support.html"><meta http-equiv="refresh" content="0; url=/support.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/transporters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/transporters.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/transporters.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/usage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/usage.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/usage.html"></head></html>
1 change: 1 addition & 0 deletions docs/0.12/docs/validation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Redirecting...</title><link rel="canonical" href="/docs/0.1/validation.html"><meta http-equiv="refresh" content="0; url=/docs/0.1/validation.html"></head></html>
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gomicro.services
Loading

0 comments on commit ef63dde

Please sign in to comment.