Files
sealos/pkg/utils/json/json.go
T
Mercurio 0b91bdeb5e ci: multiple improvements on CI workflow (#1270)
* ci: multiple improvements on CI workflow

Signed-off-by: Mercurio <signormercurio@gmail.com>

* attempt to fix lint actions error

Signed-off-by: Mercurio <signormercurio@gmail.com>

* delete fossa actions

Signed-off-by: Mercurio <signormercurio@gmail.com>

* attempt to solve lint error

Signed-off-by: Mercurio <signormercurio@gmail.com>

* format code

Signed-off-by: Mercurio <signormercurio@gmail.com>

* attempt to fix lint error

Signed-off-by: Mercurio <signormercurio@gmail.com>

* fix lint error

Signed-off-by: Mercurio <signormercurio@gmail.com>

* fix nolint syntax error

Signed-off-by: Mercurio <signormercurio@gmail.com>

* completely fix lint error

Signed-off-by: Mercurio <signormercurio@gmail.com>
2022-07-08 21:54:48 +08:00

47 lines
1.2 KiB
Go

/*
Copyright 2022 cuisongliu@qq.com.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package json
import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/json"
"github.com/labring/sealos/pkg/utils/file"
)
func Unmarshal(path string) (map[string]interface{}, error) {
metadata, err := file.ReadAll(path)
if err != nil {
return nil, err
}
var data map[string]interface{}
err = json.Unmarshal(metadata, &data)
if err != nil {
return nil, err
}
return data, nil
}
func Convert(from interface{}, to interface{}) error {
var data []byte
var err error
if data, err = json.Marshal(from); err != nil {
return errors.WithStack(err)
}
return errors.WithStack(json.Unmarshal(data, to))
}