2019-05-30 23:11:13 +01:00
|
|
|
package hcl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/hashicorp/hcl"
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/config/encoder"
|
2019-05-30 23:11:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type hclEncoder struct{}
|
|
|
|
|
|
|
|
func (h hclEncoder) Encode(v interface{}) ([]byte, error) {
|
|
|
|
return json.Marshal(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h hclEncoder) Decode(d []byte, v interface{}) error {
|
|
|
|
return hcl.Unmarshal(d, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h hclEncoder) String() string {
|
|
|
|
return "hcl"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewEncoder() encoder.Encoder {
|
|
|
|
return hclEncoder{}
|
|
|
|
}
|