跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

template.go

44 行 · 1.1 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package limatmpl
5
6import (
7 "strings"
8
9 "github.com/lima-vm/lima/v2/pkg/limatype"
10 "github.com/lima-vm/lima/v2/pkg/limayaml"
11)
12
13type Template struct {
14 Locator string // template locator (absolute path or URL)
15 Bytes []byte // file contents
16
17 // The following fields are only used when the template represents a YAML config file.
18 Name string // instance name, may be inferred from locator
19 Config *limatype.LimaYAML
20
21 expr strings.Builder // yq expression to update template
22}
23
24func (tmpl *Template) ClearOnError(err error) error {
25 if err != nil {
26 tmpl.Bytes = nil
27 tmpl.Config = nil
28 tmpl.expr.Reset()
29 }
30 return err
31}
32
33// Unmarshal makes sure the tmpl.Config field is set. Any operation that modified
34// tmpl.Bytes is expected to set tmpl.Config back to nil.
35func (tmpl *Template) Unmarshal() error {
36 if tmpl.Config == nil {
37 tmpl.Config = &limatype.LimaYAML{}
38 if err := limayaml.Unmarshal(tmpl.Bytes, tmpl.Config, tmpl.Locator); err != nil {
39 tmpl.Config = nil
40 return err
41 }
42 }
43 return nil
44}