Skip to content

Commit

Permalink
added X json.RawMessage to all Config structs, this can be used in …
Browse files Browse the repository at this point in the history
…the future for "addons", or those who extend patrol
  • Loading branch information
sabey committed Jul 25, 2018
1 parent 428fa57 commit 66260b3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ TriggerStopped func(
patrol *Patrol,
) `json:"-"`

// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
```


Expand Down Expand Up @@ -430,6 +432,9 @@ TriggerClosed func(
TriggerPinged func(
app *App,
) `json:"-"`

// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
```


Expand Down Expand Up @@ -525,6 +530,9 @@ TriggerClosed func(
service *Service,
history *History,
) `json:"-"`

// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
```


Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type Config struct {
TriggerStopped func(
patrol *Patrol,
) `json:"-"`
// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
// this is only used internally and checked once on creation
unittesting bool
}
Expand Down Expand Up @@ -159,6 +161,7 @@ func (self *Config) Clone() *Config {
TriggerStarted: self.TriggerStarted,
TriggerTick: self.TriggerTick,
TriggerStopped: self.TriggerStopped,
X: dereference(self.X),
}
for k, v := range self.Apps {
config.Apps[k] = v.Clone()
Expand Down
10 changes: 10 additions & 0 deletions config_api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package patrol

import (
"encoding/json"
)

type ConfigHTTP struct {
Listen string `json:"listen,omitempty"`
// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
// TODO: https?
}

Expand All @@ -17,12 +23,15 @@ func (self *ConfigHTTP) Clone() *ConfigHTTP {
}
config := &ConfigHTTP{
Listen: self.Listen,
X: dereference(self.X),
}
return config
}

type ConfigUDP struct {
Listen string `json:"listen,omitempty"`
// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
}

func (self *ConfigUDP) IsValid() bool {
Expand All @@ -37,6 +46,7 @@ func (self *ConfigUDP) Clone() *ConfigUDP {
}
config := &ConfigUDP{
Listen: self.Listen,
X: dereference(self.X),
}
return config
}
4 changes: 4 additions & 0 deletions config_app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package patrol

import (
"encoding/json"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -180,6 +181,8 @@ type ConfigApp struct {
TriggerPinged func(
app *App,
) `json:"-"`
// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
}

func (self *ConfigApp) IsValid() bool {
Expand Down Expand Up @@ -223,6 +226,7 @@ func (self *ConfigApp) Clone() *ConfigApp {
TriggerDisabled: self.TriggerDisabled,
TriggerClosed: self.TriggerClosed,
TriggerPinged: self.TriggerPinged,
X: dereference(self.X),
}
for k, v := range self.KeyValue {
o.KeyValue[k] = v
Expand Down
4 changes: 4 additions & 0 deletions config_service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package patrol

import (
"encoding/json"
"fmt"
)

Expand Down Expand Up @@ -94,6 +95,8 @@ type ConfigService struct {
service *Service,
history *History,
) `json:"-"`
// Extra Unstructured Data
X json.RawMessage `json:"x,omitempty"`
}

func (self *ConfigService) IsValid() bool {
Expand Down Expand Up @@ -132,6 +135,7 @@ func (self *ConfigService) Clone() *ConfigService {
TriggerRunning: self.TriggerRunning,
TriggerDisabled: self.TriggerDisabled,
TriggerClosed: self.TriggerClosed,
X: dereference(self.X),
}
for k, v := range self.KeyValue {
config.KeyValue[k] = v
Expand Down
7 changes: 7 additions & 0 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ func IsPathClean(path string) bool {
// does not match
return false
}
func dereference(
data []byte,
) []byte {
safe := make([]byte, len(data))
copy(safe, data)
return safe
}

0 comments on commit 66260b3

Please sign in to comment.