From 9d46f1ab7add9e257f6d0ac7442bed0b901e1aa5 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Tue, 31 Jul 2018 15:00:20 +0800 Subject: [PATCH] add yaml convertor support yaml string convert Issue-ID: MSB-235 Change-Id: Iddce914d09b6bbe550d417506f1b24f652a8ce70 Signed-off-by: Lvbo163 --- .gitignore | 1 + msb2pilot/src/msb2pilot/Gopkg.lock | 8 ++++++- msb2pilot/src/msb2pilot/util/yaml.go | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 msb2pilot/src/msb2pilot/util/yaml.go 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) +} -- 2.16.6