Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
float-dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
tools
float-dashboard
Commits
d2ec2f90
Commit
d2ec2f90
authored
4 months ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Implement IntOrStr deserialization for YAML, not JSON
Oops.
parent
593ec9b5
No related branches found
No related tags found
No related merge requests found
Pipeline
#86266
passed
4 months ago
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
schema/float/ints.go
+14
-15
14 additions, 15 deletions
schema/float/ints.go
schema/float/ints_test.go
+3
-2
3 additions, 2 deletions
schema/float/ints_test.go
with
17 additions
and
17 deletions
schema/float/ints.go
+
14
−
15
View file @
d2ec2f90
package
floatschema
import
(
"encoding/json"
"strconv"
"gopkg.in/yaml.v3"
)
type
IntOrStr
int
func
(
i
*
IntOrStr
)
UnmarshalJSON
(
b
[]
byte
)
error
{
if
len
(
b
)
>
0
&&
b
[
0
]
==
'"'
{
var
tmp
string
if
err
:=
json
.
Unmarshal
(
b
,
&
tmp
);
err
!=
nil
{
func
(
i
*
IntOrStr
)
UnmarshalYAML
(
value
*
yaml
.
Node
)
error
{
var
tmpI
int
if
err
:=
value
.
Decode
(
&
tmpI
);
err
==
nil
{
*
i
=
IntOrStr
(
tmpI
)
return
nil
}
var
tmpS
string
if
err
:=
value
.
Decode
(
&
tmpS
);
err
!=
nil
{
return
err
}
ii
,
err
:=
strconv
.
Atoi
(
tmp
)
ii
,
err
:=
strconv
.
Atoi
(
tmp
S
)
if
err
!=
nil
{
return
err
}
*
i
=
IntOrStr
(
ii
)
return
nil
}
var
tmp
int
if
err
:=
json
.
Unmarshal
(
b
,
&
tmp
);
err
!=
nil
{
return
err
}
*
i
=
IntOrStr
(
tmp
)
return
nil
}
func
IntOrStrListToIntList
(
l
[]
IntOrStr
)
[]
int
{
o
:=
make
([]
int
,
0
,
len
(
l
))
...
...
This diff is collapsed.
Click to expand it.
schema/float/ints_test.go
+
3
−
2
View file @
d2ec2f90
package
floatschema
import
(
"encoding/json"
"testing"
"gopkg.in/yaml.v3"
)
func
TestIntOrStr
(
t
*
testing
.
T
)
{
...
...
@@ -17,7 +18,7 @@ func TestIntOrStr(t *testing.T) {
{
"
\"
foo
\"
"
,
false
,
0
},
}
{
var
i
IntOrStr
err
:=
json
.
Unmarshal
([]
byte
(
td
.
s
),
&
i
)
err
:=
yaml
.
Unmarshal
([]
byte
(
td
.
s
),
&
i
)
ok
:=
err
==
nil
if
ok
!=
td
.
ok
{
...
...
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