-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhcl.go
More file actions
31 lines (25 loc) · 744 Bytes
/
Copy pathhcl.go
File metadata and controls
31 lines (25 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (c) bwplotka/mimic Authors
// Licensed under the Apache License 2.0.
package encoding
import (
"bytes"
"fmt"
"io"
"github.com/rodaine/hclencoder"
)
// hclEncoder implements the Encoder interface.
type hclEncoder struct {
io.Reader
}
// EncodeComment returns byte slice that represents a HCL comment (same as YAML).
// We split `lines` by '\n' and encode as a single/multi line comment.
func (hclEncoder) EncodeComment(lines string) []byte {
return YAML().EncodeComment(lines)
}
func HCL(in interface{}) hclEncoder {
b, err := hclencoder.Encode(in)
if err != nil {
return hclEncoder{Reader: errReader{err: fmt.Errorf("unable to marshal to HCL: %v: %w", in, err)}}
}
return hclEncoder{Reader: bytes.NewBuffer(b)}
}