Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-config
Commits
9949be66
Commit
9949be66
authored
Jun 16, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: panic on invalid priority/flag values
parent
7fbc0dff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
types.go
types.go
+18
-3
No files found.
types.go
View file @
9949be66
...
@@ -56,6 +56,8 @@ const (
...
@@ -56,6 +56,8 @@ const (
)
)
// WithDefault resolves the value of the flag given the provided default value.
// WithDefault resolves the value of the flag given the provided default value.
//
// Panics if Flag is an invalid value.
func
(
f
Flag
)
WithDefault
(
defaultValue
bool
)
bool
{
func
(
f
Flag
)
WithDefault
(
defaultValue
bool
)
bool
{
switch
f
{
switch
f
{
case
False
:
case
False
:
...
@@ -126,17 +128,30 @@ const (
...
@@ -126,17 +128,30 @@ const (
// WithDefault resolves the priority with the given default.
// WithDefault resolves the priority with the given default.
//
//
// If `defaultPriority` is Default/0, this function will return 0.
// If defaultPriority is Default/0, this function will return 0.
//
// Panics if the priority has an invalid value (e.g., not DefaultPriority,
// Disabled, or > 0).
func
(
p
Priority
)
WithDefault
(
defaultPriority
Priority
)
(
priority
int64
,
enabled
bool
)
{
func
(
p
Priority
)
WithDefault
(
defaultPriority
Priority
)
(
priority
int64
,
enabled
bool
)
{
switch
p
{
switch
p
{
case
Disabled
:
case
Disabled
:
return
0
,
false
return
0
,
false
case
DefaultPriority
:
case
DefaultPriority
:
if
defaultPriority
<
0
{
switch
defaultPriority
{
case
Disabled
:
return
0
,
false
return
0
,
false
case
DefaultPriority
:
return
0
,
true
default
:
if
defaultPriority
<=
0
{
panic
(
fmt
.
Sprintf
(
"invalid priority %d < 0"
,
int64
(
defaultPriority
)))
}
return
int64
(
defaultPriority
),
true
}
}
return
int64
(
defaultPriority
),
true
default
:
default
:
if
p
<=
0
{
panic
(
fmt
.
Sprintf
(
"invalid priority %d < 0"
,
int64
(
p
)))
}
return
int64
(
p
),
true
return
int64
(
p
),
true
}
}
}
}
...
...
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