Skip to content
This repository was archived by the owner on Feb 7, 2020. It is now read-only.

Commit ba45b07

Browse files
authored
Merge pull request #5 from choria-io/4
(#4) allow Identity() extract a event identity
2 parents 21552f0 + 37fe4df commit ba45b07

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

event.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ package lifecycle
44
type Event interface {
55
Target() (string, error)
66
String() string
7-
Component() string
87
Type() Type
98
SetIdentity(string)
9+
Component() string
10+
Identity() string
1011
}

options_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var _ = Describe("Options", func() {
1515
Describe("Identity", func() {
1616
It("Should set the identity", func() {
1717
Identity("ginkgo")(event)
18-
Expect(event.Identity).To(Equal("ginkgo"))
18+
Expect(event.Ident).To(Equal("ginkgo"))
1919
})
2020
})
2121

shutdown.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// ShutdownEvent is a choria:lifecycle:shutdown:1 event
99
type ShutdownEvent struct {
1010
Protocol string `json:"protocol"`
11-
Identity string `json:"identity"`
11+
Ident string `json:"identity"`
1212
Comp string `json:"component"`
1313
Timestamp int64 `json:"timestamp"`
1414
}
@@ -64,7 +64,12 @@ func (e *ShutdownEvent) SetComponent(c string) {
6464

6565
// SetIdentity sets the identity for the event
6666
func (e *ShutdownEvent) SetIdentity(i string) {
67-
e.Identity = i
67+
e.Ident = i
68+
}
69+
70+
// Identity sets the identity for the event
71+
func (e *ShutdownEvent) Identity() string {
72+
return e.Ident
6873
}
6974

7075
// Target is where to publish the event to
@@ -78,7 +83,7 @@ func (e *ShutdownEvent) Target() (string, error) {
7883

7984
// String is text suitable to display on the console etc
8085
func (e *ShutdownEvent) String() string {
81-
return fmt.Sprintf("[shutdown] %s: %s", e.Identity, e.Component())
86+
return fmt.Sprintf("[shutdown] %s: %s", e.Ident, e.Component())
8287
}
8388

8489
// Type is the type of event

shutdown_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var _ = Describe("ShutdownEvent", func() {
4545
It("Should set the identity", func() {
4646
e := &ShutdownEvent{}
4747
e.SetIdentity("node.example")
48-
Expect(e.Identity).To(Equal("node.example"))
48+
Expect(e.Ident).To(Equal("node.example"))
4949
})
5050
})
5151

startup.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// StartupEvent is a choria:lifecycle:startup:1 event
99
type StartupEvent struct {
1010
Protocol string `json:"protocol"`
11-
Identity string `json:"identity"`
11+
Ident string `json:"identity"`
1212
Version string `json:"version"`
1313
Timestamp int64 `json:"timestamp"`
1414
Comp string `json:"component"`
@@ -70,7 +70,12 @@ func (e *StartupEvent) SetVersion(v string) {
7070

7171
// SetIdentity sets the identity for the event
7272
func (e *StartupEvent) SetIdentity(i string) {
73-
e.Identity = i
73+
e.Ident = i
74+
}
75+
76+
// Identity retrieves the identity
77+
func (e *StartupEvent) Identity() string {
78+
return e.Ident
7479
}
7580

7681
// Target is where to publish the event to
@@ -84,7 +89,7 @@ func (e *StartupEvent) Target() (string, error) {
8489

8590
// String is text suitable to display on the console etc
8691
func (e *StartupEvent) String() string {
87-
return fmt.Sprintf("[startup] %s: %s version %s", e.Identity, e.Component(), e.Version)
92+
return fmt.Sprintf("[startup] %s: %s version %s", e.Ident, e.Component(), e.Version)
8893
}
8994

9095
// Type is the type of event

startup_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var _ = Describe("StartupEvent", func() {
5353
It("Should set the identity", func() {
5454
e := &StartupEvent{}
5555
e.SetIdentity("node.example")
56-
Expect(e.Identity).To(Equal("node.example"))
56+
Expect(e.Ident).To(Equal("node.example"))
5757
})
5858
})
5959

0 commit comments

Comments
 (0)