【cue语言系列学习】base64编解码
release author: ningan123
release time: -08-14
在线运行
工具
三种不同的输出方式,输出的结果是不一样的
本地模拟
base64.cue
[root@master base64]# cat base64.cueimport "encoding/base64"t1: base64.Encode(null, "foo")t2: base64.Decode(null, base64.Encode(null, "foo"))
[root@master cuePractice]# cue versioncue version v0.4.3 linux/amd64[root@master cuePractice]# [root@master cuePractice]# cue export base64/base64.cue{"t1": "Zm9v","t2": "Zm9v"}[root@master cuePractice]# cue export base64/base64.cue --out json{"t1": "Zm9v","t2": "Zm9v"}[root@master cuePractice]# cue export base64/base64.cue --out yamlt1: Zm9vt2: !!binary Zm9v[root@master cuePractice]#
[root@master cuePractice]# go run base64/base64.goscheme: {t1: "Zm9v"t2: 'foo'}
// base64.gopackage mainimport ("errors""fmt""os""path/filepath""/go/cue""/go/cue/cuecontext"cueerror "/go/cue/errors")func main() {ctx := cuecontext.New()clusterVal := ctx.NewList()confPath := "/root/cuePractice/base64"fileData, err := os.ReadFile(filepath.Join(confPath, "base64.cue"))if err != nil {fmt.Println(err.Error())}scheme := pileBytes(fileData, cue.Scope(clusterVal))if scheme.Err() != nil {msg := cueerror.Details(scheme.Err(), nil)fmt.Println(errors.New(msg))}fmt.Printf("scheme: \n%s\n", scheme)}