summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuabing Zhao <zhaohuabing@gmail.com>2018-07-31 07:20:01 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-31 07:20:01 +0000
commit2401f9f8f855c55c30c7b8aadd57fda518df5f2c (patch)
tree930b43983f06fac13add5b72a865824163c7d629
parentb09fcc065eeb2bd8f79e8de98f02b94af502d512 (diff)
parent9d46f1ab7add9e257f6d0ac7442bed0b901e1aa5 (diff)
Merge "add yaml convertor"
-rw-r--r--.gitignore1
-rw-r--r--msb2pilot/src/msb2pilot/Gopkg.lock8
-rw-r--r--msb2pilot/src/msb2pilot/util/yaml.go43
3 files changed, 51 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 7b9b626..5e84c66 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
*.so
*.log
config
+msb2pilot.exe
# Folders
_obj
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)
+}