File tree Expand file tree Collapse file tree 2 files changed +48
-25
lines changed Expand file tree Collapse file tree 2 files changed +48
-25
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2020 The Compose Specification Authors.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ package types
18
+
19
+ import (
20
+ "fmt"
21
+ "strconv"
22
+ )
23
+
24
+ type NanoCPUs float32
25
+
26
+ func (n * NanoCPUs ) DecodeMapstructure (a any ) error {
27
+ switch v := a .(type ) {
28
+ case string :
29
+ f , err := strconv .ParseFloat (v , 64 )
30
+ if err != nil {
31
+ return err
32
+ }
33
+ * n = NanoCPUs (f )
34
+ case int :
35
+ * n = NanoCPUs (v )
36
+ case float32 :
37
+ * n = NanoCPUs (v )
38
+ case float64 :
39
+ * n = NanoCPUs (v )
40
+ default :
41
+ return fmt .Errorf ("unexpected value type %T for cpus" , v )
42
+ }
43
+ return nil
44
+ }
45
+
46
+ func (n * NanoCPUs ) Value () float32 {
47
+ return float32 (* n )
48
+ }
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ import (
20
20
"encoding/json"
21
21
"fmt"
22
22
"sort"
23
- "strconv"
24
23
"strings"
25
24
26
25
"github.com/docker/go-connections/nat"
@@ -391,30 +390,6 @@ type Resource struct {
391
390
Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
392
391
}
393
392
394
- type NanoCPUs float32
395
-
396
- func (n * NanoCPUs ) DecodeMapstructure (a any ) error {
397
- switch v := a .(type ) {
398
- case string :
399
- f , err := strconv .ParseFloat (v , 64 )
400
- if err != nil {
401
- return err
402
- }
403
- * n = NanoCPUs (f )
404
- case float32 :
405
- * n = NanoCPUs (v )
406
- case float64 :
407
- * n = NanoCPUs (v )
408
- default :
409
- return fmt .Errorf ("unexpected value type %T for cpus" , v )
410
- }
411
- return nil
412
- }
413
-
414
- func (n * NanoCPUs ) Value () float32 {
415
- return float32 (* n )
416
- }
417
-
418
393
// GenericResource represents a "user defined" resource which can
419
394
// only be an integer (e.g: SSD=3) for a service
420
395
type GenericResource struct {
You can’t perform that action at this time.
0 commit comments