Skip to content

Commit f8b7d36

Browse files
randomnoiseafrittoli
authored andcommitted
fix: correct event generator shell script
1 parent 4fae45c commit f8b7d36

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

hack/add-event.sh

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ import (
4848
4949
const (
5050
// ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL} event
51-
${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1 CDEventType = "dev.cdevents.${SUBJECT_LOWER}.${PREDICATE_LOWER}.v1"
51+
${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1 CDEventType = "dev.cdevents.${SUBJECT_LOWER}.${PREDICATE_LOWER}.v1"
52+
${SUBJECT_LOWER_CAMEL}${PREDICATE_UPPER_CAMEL}SchemaFile string = "${SUBJECT_LOWER}${PREDICATE_LOWER}"
5253
)
5354
54-
type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}SubjectContent struct {}
55+
type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}SubjectContent struct{}
5556
5657
type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject struct {
5758
SubjectBase
@@ -69,6 +70,7 @@ func (sc ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject) GetSubjectType()
6970
type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event struct {
7071
Context Context \`json:"context"\`
7172
Subject ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject \`json:"subject"\`
73+
CDEventCustomData
7274
}
7375
7476
// CDEventsReader implementation
@@ -105,6 +107,22 @@ func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSubject() Subjec
105107
return e.Subject
106108
}
107109
110+
func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetCustomData() (interface{}, error) {
111+
return getCustomData(e.CustomDataContentType, e.CustomData)
112+
}
113+
114+
func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetCustomDataAs(receiver interface{}) error {
115+
return getCustomDataAs(e, receiver)
116+
}
117+
118+
func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetCustomDataRaw() ([]byte, error) {
119+
return getCustomDataRaw(e.CustomDataContentType, e.CustomData)
120+
}
121+
122+
func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetCustomDataContentType() string {
123+
return e.CustomDataContentType
124+
}
125+
108126
// CDEventsWriter implementation
109127
110128
func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetId(id string) {
@@ -131,14 +149,37 @@ func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetSubjectSource(s
131149
e.Subject.Source = subjectSource
132150
}
133151
134-
func new${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event() CDEvent {
135-
return &${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event{
152+
func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetCustomData(contentType string, data interface{}) error {
153+
err := checkCustomData(contentType, data)
154+
if err != nil {
155+
return err
156+
}
157+
e.CustomData = data
158+
e.CustomDataContentType = contentType
159+
return nil
160+
}
161+
162+
func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSchema() string {
163+
return ${SUBJECT_LOWER_CAMEL}${PREDICATE_UPPER_CAMEL}SchemaFile
164+
}
165+
166+
func New${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event() (*${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event, error) {
167+
e := &${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event{
136168
Context: Context{
137169
Type: ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1,
138170
Version: CDEventsSpecVersion,
139171
},
140-
Subject: ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject{},
172+
Subject: ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject{
173+
SubjectBase: SubjectBase{
174+
Type: ${SUBJECT_UPPER_CAMEL}SubjectType,
175+
},
176+
},
177+
}
178+
_, err := initCDEvent(e)
179+
if err != nil {
180+
return nil, err
141181
}
182+
return e, nil
142183
}
143184
EOF
144185

0 commit comments

Comments
 (0)