summaryrefslogtreecommitdiffstats
path: root/msb2pilot
diff options
context:
space:
mode:
Diffstat (limited to 'msb2pilot')
-rw-r--r--msb2pilot/src/msb2pilot/Gopkg.lock8
-rw-r--r--msb2pilot/src/msb2pilot/util/yaml.go43
2 files changed, 50 insertions, 1 deletions
diff --git a/msb2pilot/src/msb2pilot/Gopkg.lock b/msb2pilot/src/msb2pilot/Gopkg.lock
index f4320f4..9a704e7 100644
--- a/msb2pilot/src/msb2pilot/Gopkg.lock
+++ b/msb2pilot/src/msb2pilot/Gopkg.lock
@@ -31,9 +31,15 @@
revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857"
version = "1.6.3"
+[[projects]]
+ name = "gopkg.in/yaml.v2"
+ packages = ["."]
+ revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
+ version = "v2.2.1"
+
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "9e242ef2da883faa526d0301106c1de8202a8b14eecebf2470863a2e60ea195b"
+ inputs-digest = "fa4cfc44b5a6fe6939a41f6fd3f2efca1f840f04854eee11cfd79b975074e048"
solver-name = "gps-cdcl"
solver-version = 1
diff --git a/msb2pilot/src/msb2pilot/util/yaml.go b/msb2pilot/src/msb2pilot/util/yaml.go
new file mode 100644
index 0000000..6de09a5
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/util/yaml.go
@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial Project
+ */
+package util
+
+import (
+ "gopkg.in/yaml.v2"
+)
+
+/**
+* type T struct {
+* F int `yaml:"a, omitempty"`
+* B int
+* }
+* var t T
+* yaml.Marshal(&T{B:2}) /// returns "b: 2 \n"
+* yaml.Marshal(&T{F:1}) // returns "a: 1 \nb: 0\n"
+ */
+func MarshalYaml(in interface{}) (string, error) {
+ b, err := yaml.Marshal(in)
+ if err != nil {
+ return "", err
+ } else {
+ return string(b), nil
+ }
+}
+
+/**
+* var t T
+* yaml.Unmarshal([]byte("a: 1\nb: 2"), &t)
+*
+ */
+func UnmarshalYaml(str string, out interface{}) error {
+ return yaml.Unmarshal([]byte(str), out)
+}