Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
db8d7ffb
Unverified
Commit
db8d7ffb
authored
Jun 30, 2020
by
Carl Bergquist
Committed by
GitHub
Jun 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linting fixes for the provisioning package (#25690)
parent
891ae24f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
102 additions
and
78 deletions
+102
-78
.circleci/config.yml
+2
-0
Makefile
+2
-0
pkg/services/provisioning/notifiers/alert_notifications.go
+20
-24
pkg/services/provisioning/notifiers/config_reader.go
+11
-11
pkg/services/provisioning/notifiers/config_reader_test.go
+30
-30
pkg/services/provisioning/notifiers/types.go
+13
-13
pkg/services/provisioning/values/values.go
+24
-0
No files found.
.circleci/config.yml
View file @
db8d7ffb
...
...
@@ -835,6 +835,8 @@ jobs:
./pkg/services/alerting/... \
./pkg/services/provisioning/datasources/... \
./pkg/services/provisioning/dashboards/... \
./pkg/services/provisioning/notifiers/... \
./pkg/services/provisioning/values/... \
./pkg/plugins/backendplugin/...
test-frontend
:
...
...
Makefile
View file @
db8d7ffb
...
...
@@ -90,6 +90,8 @@ revive-strict: scripts/go/bin/revive
./pkg/services/alerting/...
\
./pkg/services/provisioning/datasources/...
\
./pkg/services/provisioning/dashboards/...
\
./pkg/services/provisioning/notifiers/...
\
./pkg/services/provisioning/values/...
\
./pkg/plugins/backendplugin/...
scripts/go/bin/golangci-lint
:
scripts/go/go.mod
...
...
pkg/services/provisioning/notifiers/alert_notifications.go
View file @
db8d7ffb
package
notifiers
import
(
"errors"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
var
(
ErrInvalidConfigTooManyDefault
=
errors
.
New
(
"Alert notification provisioning config is invalid. Only one alert notification can be marked as default"
)
)
// Provision alert notifiers
func
Provision
(
configDirectory
string
)
error
{
dc
:=
newNotificationProvisioner
(
log
.
New
(
"provisioning.notifiers"
))
return
dc
.
applyChanges
(
configDirectory
)
}
// NotificationProvisioner is responsible for provsioning alert notifiers
type
NotificationProvisioner
struct
{
log
log
.
Logger
cfgProvider
*
configReader
...
...
@@ -43,19 +39,19 @@ func (dc *NotificationProvisioner) apply(cfg *notificationsAsConfig) error {
func
(
dc
*
NotificationProvisioner
)
deleteNotifications
(
notificationToDelete
[]
*
deleteNotificationConfig
)
error
{
for
_
,
notification
:=
range
notificationToDelete
{
dc
.
log
.
Info
(
"Deleting alert notification"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
id
)
dc
.
log
.
Info
(
"Deleting alert notification"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
ID
)
if
notification
.
OrgI
d
==
0
&&
notification
.
OrgName
!=
""
{
if
notification
.
OrgI
D
==
0
&&
notification
.
OrgName
!=
""
{
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
return
err
}
notification
.
OrgI
d
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
d
<
0
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
D
<
0
{
notification
.
OrgI
D
=
1
}
getNotification
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
Uid
:
notification
.
U
id
,
OrgId
:
notification
.
OrgId
}
getNotification
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
Uid
:
notification
.
U
ID
,
OrgId
:
notification
.
OrgID
}
if
err
:=
bus
.
Dispatch
(
getNotification
);
err
!=
nil
{
return
err
...
...
@@ -75,31 +71,31 @@ func (dc *NotificationProvisioner) deleteNotifications(notificationToDelete []*d
func
(
dc
*
NotificationProvisioner
)
mergeNotifications
(
notificationToMerge
[]
*
notificationFromConfig
)
error
{
for
_
,
notification
:=
range
notificationToMerge
{
if
notification
.
OrgI
d
==
0
&&
notification
.
OrgName
!=
""
{
if
notification
.
OrgI
D
==
0
&&
notification
.
OrgName
!=
""
{
getOrg
:=
&
models
.
GetOrgByNameQuery
{
Name
:
notification
.
OrgName
}
if
err
:=
bus
.
Dispatch
(
getOrg
);
err
!=
nil
{
return
err
}
notification
.
OrgI
d
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
d
<
0
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
getOrg
.
Result
.
Id
}
else
if
notification
.
OrgI
D
<
0
{
notification
.
OrgI
D
=
1
}
cmd
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
OrgId
:
notification
.
OrgI
d
,
Uid
:
notification
.
Uid
}
cmd
:=
&
models
.
GetAlertNotificationsWithUidQuery
{
OrgId
:
notification
.
OrgI
D
,
Uid
:
notification
.
UID
}
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
{
return
err
}
if
cmd
.
Result
==
nil
{
dc
.
log
.
Debug
(
"inserting alert notification from configuration"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
id
)
dc
.
log
.
Debug
(
"inserting alert notification from configuration"
,
"name"
,
notification
.
Name
,
"uid"
,
notification
.
U
ID
)
insertCmd
:=
&
models
.
CreateAlertNotificationCommand
{
Uid
:
notification
.
U
id
,
Uid
:
notification
.
U
ID
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
Settings
:
notification
.
SettingsToJ
son
(),
OrgId
:
notification
.
OrgI
d
,
Settings
:
notification
.
SettingsToJ
SON
(),
OrgId
:
notification
.
OrgI
D
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
Frequency
:
notification
.
Frequency
,
SendReminder
:
notification
.
SendReminder
,
...
...
@@ -111,12 +107,12 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
}
else
{
dc
.
log
.
Debug
(
"updating alert notification from configuration"
,
"name"
,
notification
.
Name
)
updateCmd
:=
&
models
.
UpdateAlertNotificationWithUidCommand
{
Uid
:
notification
.
U
id
,
Uid
:
notification
.
U
ID
,
Name
:
notification
.
Name
,
Type
:
notification
.
Type
,
IsDefault
:
notification
.
IsDefault
,
Settings
:
notification
.
SettingsToJ
son
(),
OrgId
:
notification
.
OrgI
d
,
Settings
:
notification
.
SettingsToJ
SON
(),
OrgId
:
notification
.
OrgI
D
,
DisableResolveMessage
:
notification
.
DisableResolveMessage
,
Frequency
:
notification
.
Frequency
,
SendReminder
:
notification
.
SendReminder
,
...
...
pkg/services/provisioning/notifiers/config_reader.go
View file @
db8d7ffb
...
...
@@ -46,7 +46,7 @@ func (cr *configReader) readConfig(path string) ([]*notificationsAsConfig, error
return
nil
,
err
}
checkOrgI
d
AndOrgName
(
notifications
)
checkOrgI
D
AndOrgName
(
notifications
)
err
=
validateNotifications
(
notifications
)
if
err
!=
nil
{
...
...
@@ -72,24 +72,24 @@ func (cr *configReader) parseNotificationConfig(path string, file os.FileInfo) (
return
cfg
.
mapToNotificationFromConfig
(),
nil
}
func
checkOrgI
d
AndOrgName
(
notifications
[]
*
notificationsAsConfig
)
{
func
checkOrgI
D
AndOrgName
(
notifications
[]
*
notificationsAsConfig
)
{
for
i
:=
range
notifications
{
for
_
,
notification
:=
range
notifications
[
i
]
.
Notifications
{
if
notification
.
OrgI
d
<
1
{
if
notification
.
OrgI
D
<
1
{
if
notification
.
OrgName
==
""
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
else
{
notification
.
OrgI
d
=
0
notification
.
OrgI
D
=
0
}
}
}
for
_
,
notification
:=
range
notifications
[
i
]
.
DeleteNotifications
{
if
notification
.
OrgI
d
<
1
{
if
notification
.
OrgI
D
<
1
{
if
notification
.
OrgName
==
""
{
notification
.
OrgI
d
=
1
notification
.
OrgI
D
=
1
}
else
{
notification
.
OrgI
d
=
0
notification
.
OrgI
D
=
0
}
}
}
...
...
@@ -107,7 +107,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
)
}
if
notification
.
U
id
==
""
{
if
notification
.
U
ID
==
""
{
errStrings
=
append
(
errStrings
,
fmt
.
Sprintf
(
"Added alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
...
...
@@ -123,7 +123,7 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
)
}
if
notification
.
U
id
==
""
{
if
notification
.
U
ID
==
""
{
errStrings
=
append
(
errStrings
,
fmt
.
Sprintf
(
"Deleted alert notification item %d in configuration doesn't contain required field uid"
,
index
+
1
),
...
...
@@ -149,7 +149,7 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
for
_
,
notification
:=
range
notifications
[
i
]
.
Notifications
{
_
,
err
:=
alerting
.
InitNotifier
(
&
models
.
AlertNotification
{
Name
:
notification
.
Name
,
Settings
:
notification
.
SettingsToJ
son
(),
Settings
:
notification
.
SettingsToJ
SON
(),
Type
:
notification
.
Type
,
})
...
...
pkg/services/provisioning/notifiers/config_reader_test.go
View file @
db8d7ffb
...
...
@@ -13,16 +13,16 @@ import (
)
var
(
correct
_properties
=
"./testdata/test-configs/correct-properties"
incorrect
_settings
=
"./testdata/test-configs/incorrect-settings"
no
_required_fields
=
"./testdata/test-configs/no-required-fields"
correct
_properties_with_o
rgName
=
"./testdata/test-configs/correct-properties-with-orgName"
brokenYaml
=
"./testdata/test-configs/broken-yaml"
doubleNotificationsConfig
=
"./testdata/test-configs/double-default"
emptyFolder
=
"./testdata/test-configs/empty_folder"
emptyFile
=
"./testdata/test-configs/empty"
twoNotificationsConfig
=
"./testdata/test-configs/two-notifications"
unknownNotifier
=
"./testdata/test-configs/unknown-notifier"
correct
Properties
=
"./testdata/test-configs/correct-properties"
incorrect
Settings
=
"./testdata/test-configs/incorrect-settings"
no
RequiredFields
=
"./testdata/test-configs/no-required-fields"
correct
PropertiesWithO
rgName
=
"./testdata/test-configs/correct-properties-with-orgName"
brokenYaml
=
"./testdata/test-configs/broken-yaml"
doubleNotificationsConfig
=
"./testdata/test-configs/double-default"
emptyFolder
=
"./testdata/test-configs/empty_folder"
emptyFile
=
"./testdata/test-configs/empty"
twoNotificationsConfig
=
"./testdata/test-configs/two-notifications"
unknownNotifier
=
"./testdata/test-configs/unknown-notifier"
)
func
TestNotificationAsConfig
(
t
*
testing
.
T
)
{
...
...
@@ -46,7 +46,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Can read correct properties"
,
func
()
{
_
=
os
.
Setenv
(
"TEST_VAR"
,
"default"
)
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
cfg
,
err
:=
cfgProvider
.
readConfig
(
correct
_p
roperties
)
cfg
,
err
:=
cfgProvider
.
readConfig
(
correct
P
roperties
)
_
=
os
.
Unsetenv
(
"TEST_VAR"
)
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
...
...
@@ -60,8 +60,8 @@ func TestNotificationAsConfig(t *testing.T) {
nt
:=
nts
[
0
]
So
(
nt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier1"
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
2
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier1"
)
So
(
nt
.
IsDefault
,
ShouldBeTrue
)
So
(
nt
.
Settings
,
ShouldResemble
,
map
[
string
]
interface
{}{
"recipient"
:
"XXX"
,
"token"
:
"xoxb"
,
"uploadImage"
:
true
,
"url"
:
"https://slack.com"
,
...
...
@@ -72,45 +72,45 @@ func TestNotificationAsConfig(t *testing.T) {
nt
=
nts
[
1
]
So
(
nt
.
Name
,
ShouldEqual
,
"another-not-default-notification"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier2"
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier2"
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
nt
=
nts
[
2
]
So
(
nt
.
Name
,
ShouldEqual
,
"check-unset-is_default-is-false"
)
So
(
nt
.
Type
,
ShouldEqual
,
"slack"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier3"
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier3"
)
So
(
nt
.
IsDefault
,
ShouldBeFalse
)
nt
=
nts
[
3
]
So
(
nt
.
Name
,
ShouldEqual
,
"Added notification with whitespaces in name"
)
So
(
nt
.
Type
,
ShouldEqual
,
"email"
)
So
(
nt
.
U
id
,
ShouldEqual
,
"notifier4"
)
So
(
nt
.
OrgI
d
,
ShouldEqual
,
3
)
So
(
nt
.
U
ID
,
ShouldEqual
,
"notifier4"
)
So
(
nt
.
OrgI
D
,
ShouldEqual
,
3
)
deleteNts
:=
ntCfg
.
DeleteNotifications
So
(
len
(
deleteNts
),
ShouldEqual
,
4
)
deleteNt
:=
deleteNts
[
0
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"default-slack-notification"
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier1"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier1"
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
2
)
deleteNt
=
deleteNts
[
1
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-without-orgId"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier2"
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier2"
)
deleteNt
=
deleteNts
[
2
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"deleted-notification-with-0-orgId"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier3"
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier3"
)
deleteNt
=
deleteNts
[
3
]
So
(
deleteNt
.
Name
,
ShouldEqual
,
"Deleted notification with whitespaces in name"
)
So
(
deleteNt
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
id
,
ShouldEqual
,
"notifier4"
)
So
(
deleteNt
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
deleteNt
.
U
ID
,
ShouldEqual
,
"notifier4"
)
})
Convey
(
"One configured notification"
,
func
()
{
...
...
@@ -243,7 +243,7 @@ func TestNotificationAsConfig(t *testing.T) {
So
(
err
,
ShouldBeNil
)
dc
:=
newNotificationProvisioner
(
logger
)
err
=
dc
.
applyChanges
(
correct
_properties_with_o
rgName
)
err
=
dc
.
applyChanges
(
correct
PropertiesWithO
rgName
)
if
err
!=
nil
{
t
.
Fatalf
(
"applyChanges return an error %v"
,
err
)
}
...
...
@@ -262,7 +262,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Config doesn't contain required field"
,
func
()
{
dc
:=
newNotificationProvisioner
(
logger
)
err
:=
dc
.
applyChanges
(
no
_required_f
ields
)
err
:=
dc
.
applyChanges
(
no
RequiredF
ields
)
So
(
err
,
ShouldNotBeNil
)
errString
:=
err
.
Error
()
...
...
@@ -310,7 +310,7 @@ func TestNotificationAsConfig(t *testing.T) {
Convey
(
"Read incorrect properties"
,
func
()
{
cfgProvider
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
_
,
err
:=
cfgProvider
.
readConfig
(
incorrect
_s
ettings
)
_
,
err
:=
cfgProvider
.
readConfig
(
incorrect
S
ettings
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
.
Error
(),
ShouldEqual
,
"Alert validation error: Could not find url property in settings"
)
})
...
...
pkg/services/provisioning/notifiers/types.go
View file @
db8d7ffb
...
...
@@ -13,15 +13,15 @@ type notificationsAsConfig struct {
}
type
deleteNotificationConfig
struct
{
U
id
string
U
ID
string
Name
string
OrgI
d
int64
OrgI
D
int64
OrgName
string
}
type
notificationFromConfig
struct
{
U
id
string
OrgI
d
int64
U
ID
string
OrgI
D
int64
OrgName
string
Name
string
Type
string
...
...
@@ -39,15 +39,15 @@ type notificationsAsConfigV0 struct {
}
type
deleteNotificationConfigV0
struct
{
U
id
values
.
StringValue
`json:"uid" yaml:"uid"`
U
ID
values
.
StringValue
`json:"uid" yaml:"uid"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
OrgI
d
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
OrgI
D
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
OrgName
values
.
StringValue
`json:"org_name" yaml:"org_name"`
}
type
notificationFromConfigV0
struct
{
U
id
values
.
StringValue
`json:"uid" yaml:"uid"`
OrgI
d
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
U
ID
values
.
StringValue
`json:"uid" yaml:"uid"`
OrgI
D
values
.
Int64Value
`json:"org_id" yaml:"org_id"`
OrgName
values
.
StringValue
`json:"org_name" yaml:"org_name"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
Type
values
.
StringValue
`json:"type" yaml:"type"`
...
...
@@ -58,7 +58,7 @@ type notificationFromConfigV0 struct {
Settings
values
.
JSONValue
`json:"settings" yaml:"settings"`
}
func
(
notification
notificationFromConfig
)
SettingsToJ
son
()
*
simplejson
.
Json
{
func
(
notification
notificationFromConfig
)
SettingsToJ
SON
()
*
simplejson
.
Json
{
settings
:=
simplejson
.
New
()
if
len
(
notification
.
Settings
)
>
0
{
for
k
,
v
:=
range
notification
.
Settings
{
...
...
@@ -78,8 +78,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for
_
,
notification
:=
range
cfg
.
Notifications
{
r
.
Notifications
=
append
(
r
.
Notifications
,
&
notificationFromConfig
{
U
id
:
notification
.
Uid
.
Value
(),
OrgI
d
:
notification
.
OrgId
.
Value
(),
U
ID
:
notification
.
UID
.
Value
(),
OrgI
D
:
notification
.
OrgID
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
Type
:
notification
.
Type
.
Value
(),
...
...
@@ -93,8 +93,8 @@ func (cfg *notificationsAsConfigV0) mapToNotificationFromConfig() *notifications
for
_
,
notification
:=
range
cfg
.
DeleteNotifications
{
r
.
DeleteNotifications
=
append
(
r
.
DeleteNotifications
,
&
deleteNotificationConfig
{
U
id
:
notification
.
Uid
.
Value
(),
OrgI
d
:
notification
.
OrgId
.
Value
(),
U
ID
:
notification
.
UID
.
Value
(),
OrgI
D
:
notification
.
OrgID
.
Value
(),
OrgName
:
notification
.
OrgName
.
Value
(),
Name
:
notification
.
Name
.
Value
(),
})
...
...
pkg/services/provisioning/values/values.go
View file @
db8d7ffb
...
...
@@ -22,11 +22,14 @@ import (
"github.com/grafana/grafana/pkg/util/errutil"
)
// IntValue represents a string value in a YAML
// config that can be overridden by environment variables
type
IntValue
struct
{
value
int
Raw
string
}
// UnmarshalYAML converts YAML into an *IntValue
func
(
val
*
IntValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
...
...
@@ -41,15 +44,19 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
errutil
.
Wrap
(
"cannot convert value int"
,
err
)
}
// Value returns the wrapped int value
func
(
val
*
IntValue
)
Value
()
int
{
return
val
.
value
}
// Int64Value represents a string value in a YAML
// config that can be overridden by environment variables
type
Int64Value
struct
{
value
int64
Raw
string
}
// UnmarshalYAML converts YAML into an *Int64Value
func
(
val
*
Int64Value
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
...
...
@@ -64,15 +71,19 @@ func (val *Int64Value) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
}
// Value returns the wrapped int64 value
func
(
val
*
Int64Value
)
Value
()
int64
{
return
val
.
value
}
// StringValue represents a string value in a YAML
// config that can be overridden by environment variables
type
StringValue
struct
{
value
string
Raw
string
}
// UnmarshalYAML converts YAML into an *StringValue
func
(
val
*
StringValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
...
...
@@ -83,15 +94,19 @@ func (val *StringValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
}
// Value returns the wrapped string value
func
(
val
*
StringValue
)
Value
()
string
{
return
val
.
value
}
// BoolValue represents a string value in a YAML
// config that can be overridden by environment variables
type
BoolValue
struct
{
value
bool
Raw
string
}
// UnmarshalYAML converts YAML into an *BoolValue
func
(
val
*
BoolValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
interpolated
,
err
:=
getInterpolated
(
unmarshal
)
if
err
!=
nil
{
...
...
@@ -102,15 +117,19 @@ func (val *BoolValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
}
// Value returns the wrapped bool value
func
(
val
*
BoolValue
)
Value
()
bool
{
return
val
.
value
}
// JSONValue represents a string value in a YAML
// config that can be overridden by environment variables
type
JSONValue
struct
{
value
map
[
string
]
interface
{}
Raw
map
[
string
]
interface
{}
}
// UnmarshalYAML converts YAML into an *JSONValue
func
(
val
*
JSONValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
unmarshaled
:=
make
(
map
[
string
]
interface
{})
err
:=
unmarshal
(
unmarshaled
)
...
...
@@ -131,15 +150,19 @@ func (val *JSONValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
return
err
}
// Value returns the wrapped JSON value as map[string]interface{}
func
(
val
*
JSONValue
)
Value
()
map
[
string
]
interface
{}
{
return
val
.
value
}
// StringMapValue represents a string value in a YAML
// config that can be overridden by environment variables
type
StringMapValue
struct
{
value
map
[
string
]
string
Raw
map
[
string
]
string
}
// UnmarshalYAML converts YAML into an *StringMapValue
func
(
val
*
StringMapValue
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
unmarshaled
:=
make
(
map
[
string
]
string
)
err
:=
unmarshal
(
unmarshaled
)
...
...
@@ -159,6 +182,7 @@ func (val *StringMapValue) UnmarshalYAML(unmarshal func(interface{}) error) erro
return
err
}
// Value returns the wrapped map[string]string value
func
(
val
*
StringMapValue
)
Value
()
map
[
string
]
string
{
return
val
.
value
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment