Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cloud Event Provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Meisel
Cloud Event Provider
Commits
419dae67
Commit
419dae67
authored
1 year ago
by
Tobias Meisel
Committed by
Steffen Schulze
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
envconfig
parent
0fcd3b58
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cloudeventprovider.go
+5
-0
5 additions, 0 deletions
cloudeventprovider.go
config.go
+24
-24
24 additions, 24 deletions
config.go
with
29 additions
and
24 deletions
cloudeventprovider.go
+
5
−
0
View file @
419dae67
...
...
@@ -25,10 +25,14 @@ type CloudEventProvider interface {
ReplyCtx
(
ctx
context
.
Context
,
responseFunc
func
(
ctx
context
.
Context
,
event
event
.
Event
)
(
*
event
.
Event
,
error
))
error
}
// New initializes a CloudEventProviderClient using the passed Config. In contrast to NewClient, it
// does not rely on a configuration other than the one provided.
func
New
(
conf
Config
,
conType
ConnectionType
,
topic
string
)
(
*
CloudEventProviderClient
,
error
)
{
return
newClient
(
conf
,
conType
,
topic
)
}
// NewClient initializes a CloudEventProviderClient. It uses viper.Viper as the config library and
// might make assumptions about your config.yaml
func
NewClient
(
connectionType
ConnectionType
,
topic
string
)
(
*
CloudEventProviderClient
,
error
)
{
cloudEventProviderViper
=
viper
.
New
()
...
...
@@ -40,6 +44,7 @@ func NewClient(connectionType ConnectionType, topic string) (*CloudEventProvider
return
newClient
(
*
config
,
connectionType
,
topic
)
}
// NewEvent initializes an event.Event ready to be submitted
func
NewEvent
(
eventSource
string
,
eventType
string
,
data
json
.
RawMessage
)
(
event
.
Event
,
error
)
{
newEvent
:=
cloudevents
.
NewEvent
()
newEvent
.
SetID
(
uuid
.
NewString
())
...
...
This diff is collapsed.
Click to expand it.
config.go
+
24
−
24
View file @
419dae67
...
...
@@ -22,9 +22,9 @@ type protocolConfig interface {
}
type
NatsConfig
struct
{
Url
string
`mapstructure:"url"`
QueueGroup
string
`mapstructure:"queueGroup,omitempty"`
TimeoutInSec
time
.
Duration
`mapstructure:"timeoutInSec,omitempty"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
QueueGroup
string
`mapstructure:"queueGroup,omitempty"
envconfig:"QUEUE_GROUP"
`
TimeoutInSec
time
.
Duration
`mapstructure:"timeoutInSec,omitempty"
envconfig:"REQUEST_TIMEOUT"
`
}
func
(
c
NatsConfig
)
validate
()
error
{
...
...
@@ -36,10 +36,10 @@ func (c NatsConfig) validate() error {
}
type
NatsJetstreamConfig
struct
{
Url
string
`mapstructure:"url"`
QueueGroup
string
`mapstructure:"queueGroup,omitempty"`
StreamType
string
`mapstructure:"streamType"`
TimeoutInSec
time
.
Duration
`mapstructure:"timeoutInSec,omitempty"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
QueueGroup
string
`mapstructure:"queueGroup,omitempty"
envconfig:"QUEUE_GROUP"
`
StreamType
string
`mapstructure:"streamType"
envconfig:"STREAM_TYPE"
`
TimeoutInSec
time
.
Duration
`mapstructure:"timeoutInSec,omitempty"
envconfig:"REQUEST_TIMEOUT"
`
}
func
(
c
NatsJetstreamConfig
)
validate
()
error
{
...
...
@@ -55,9 +55,9 @@ func (c NatsJetstreamConfig) validate() error {
}
type
KafkaConfig
struct
{
Url
string
`mapstructure:"url"`
GroupId
string
`mapstructure:"groupId,omitempty"`
ClientId
string
`mapstructure:"clientId"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
GroupId
string
`mapstructure:"groupId,omitempty"
envconfig:"GROUP_ID"
`
ClientId
string
`mapstructure:"clientId"
envconfig:"CLIENT_ID"
`
}
func
(
c
KafkaConfig
)
validate
()
error
{
...
...
@@ -73,8 +73,8 @@ func (c KafkaConfig) validate() error {
}
type
MqttConfig
struct
{
Url
string
`mapstructure:"url"`
ClientId
string
`mapstructure:"clientId"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
ClientId
string
`mapstructure:"clientId"
envconfig:"CLIENT_ID"
`
}
func
(
c
MqttConfig
)
validate
()
error
{
...
...
@@ -90,7 +90,7 @@ func (c MqttConfig) validate() error {
}
type
AmqpConfig
struct
{
Url
string
`mapstructure:"url"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
}
func
(
c
AmqpConfig
)
validate
()
error
{
...
...
@@ -102,9 +102,9 @@ func (c AmqpConfig) validate() error {
}
type
HttpConfig
struct
{
Url
string
`mapstructure:"url"`
Port
int
`mapstructure:"port"`
Path
string
`mapstructure:"path"`
Url
string
`mapstructure:"url"
envconfig:"URL" default:"127.0.0.1"
`
Port
int
`mapstructure:"port"
envconfig:"PORT" default:"8080"
`
Path
string
`mapstructure:"path"
envconfig:"PATH"
`
}
func
(
c
HttpConfig
)
validate
()
error
{
...
...
@@ -125,14 +125,14 @@ func (c HttpConfig) validate() error {
type
cloudEventProviderConfiguration
struct
{
Messaging
struct
{
Protocol
ProtocolType
`mapstructure:"protocol"`
Nats
NatsConfig
`mapstructure:"nats"`
NatsJetstream
NatsJetstreamConfig
`mapstructure:"natsJetstream"`
Kafka
KafkaConfig
`mapstructure:"kafka"`
Mqtt
MqttConfig
`mapstructure:"mqtt"`
Amqp
AmqpConfig
`mapstructure:"amqp"`
Http
HttpConfig
`mapstructure:"http"`
}
`mapstructure:"messaging"`
Protocol
ProtocolType
`mapstructure:"protocol"
envconfig:"PROTOCOL_TYPE"
`
Nats
NatsConfig
`mapstructure:"nats"
envconfig:"NATS"
`
NatsJetstream
NatsJetstreamConfig
`mapstructure:"natsJetstream"
envconfig:"JETSTREAM"
`
Kafka
KafkaConfig
`mapstructure:"kafka"
envconfig:"KAFKA"
`
Mqtt
MqttConfig
`mapstructure:"mqtt"
envconfig:"MQTT"
`
Amqp
AmqpConfig
`mapstructure:"amqp"
envconfig:"AMQP"
`
Http
HttpConfig
`mapstructure:"http"
envconfig:"HTTP"
`
}
`mapstructure:"messaging"
envconfig:"MESSAGING"
`
}
func
loadConfig
()
(
*
Config
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment