Skip to content

Commit 8d8277a

Browse files
committed
inline single-method interfaces
1 parent 93f1e0f commit 8d8277a

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

internal/provider/cached_image_resource.go

+6-19
Original file line numberDiff line numberDiff line change
@@ -632,34 +632,21 @@ func extractEnvbuilderFromImage(ctx context.Context, imgRef, destPath string) er
632632
return fmt.Errorf("extract envbuilder binary from image %q: %w", imgRef, os.ErrNotExist)
633633
}
634634

635-
// The below interfaces are to handle converting Terraform types can be converted to a string.
636-
// The String() method on an attr.Value creates a 'human-readable' version of the type, which
637-
// leads to quotes, escaped characters, and other assorted sadness.
638-
type valuestringer interface {
639-
ValueString() string
640-
}
641-
642-
type valuebooler interface {
643-
ValueBool() bool
644-
}
645-
646-
type valueint64er interface {
647-
ValueInt64() int64
648-
}
649-
650635
// tfValueToString converts an attr.Value to its string representation
651-
// based on its implementation of the above interfaces.
636+
// based on its Terraform type. This is needed because the String()
637+
// method on an attr.Value creates a 'human-readable' version of the type, which
638+
// leads to quotes, escaped characters, and other assorted sadness.
652639
func tfValueToString(val attr.Value) string {
653640
if val.IsUnknown() || val.IsNull() {
654641
return ""
655642
}
656-
if vs, ok := val.(valuestringer); ok {
643+
if vs, ok := val.(interface{ ValueString() string }); ok {
657644
return vs.ValueString()
658645
}
659-
if vb, ok := val.(valuebooler); ok {
646+
if vb, ok := val.(interface{ ValueBool() bool }); ok {
660647
return fmt.Sprintf("%t", vb.ValueBool())
661648
}
662-
if vi, ok := val.(valueint64er); ok {
649+
if vi, ok := val.(interface{ ValueInt64() int64 }); ok {
663650
return fmt.Sprintf("%d", vi.ValueInt64())
664651
}
665652
panic(fmt.Errorf("tfValueToString: value %T is not a supported type", val))

0 commit comments

Comments
 (0)