53 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			53 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package cmdpacks | ||
|  | 
 | ||
|  | import ( | ||
|  | 	"context" | ||
|  | 	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types" | ||
|  | 	"ucl.lmika.dev/ucl" | ||
|  | ) | ||
|  | 
 | ||
|  | type avModule struct { | ||
|  | } | ||
|  | 
 | ||
|  | func (avModule) avTrue(ctx context.Context, args ucl.CallArgs) (_ any, err error) { | ||
|  | 	return attributeValueProxy{value: &types.AttributeValueMemberBOOL{Value: true}}, nil | ||
|  | } | ||
|  | 
 | ||
|  | func (avModule) avFalse(ctx context.Context, args ucl.CallArgs) (_ any, err error) { | ||
|  | 	return attributeValueProxy{value: &types.AttributeValueMemberBOOL{Value: false}}, nil | ||
|  | } | ||
|  | 
 | ||
|  | func (avModule) avNull(ctx context.Context, args ucl.CallArgs) (_ any, err error) { | ||
|  | 	return attributeValueProxy{value: &types.AttributeValueMemberNULL{Value: true}}, nil | ||
|  | } | ||
|  | 
 | ||
|  | func (avModule) avStringSet(ctx context.Context, args ucl.CallArgs) (_ any, err error) { | ||
|  | 	var listable ucl.Listable | ||
|  | 
 | ||
|  | 	if err := args.Bind(&listable); err != nil { | ||
|  | 		return nil, err | ||
|  | 	} | ||
|  | 
 | ||
|  | 	ss := make([]string, listable.Len()) | ||
|  | 	for i := 0; i < listable.Len(); i++ { | ||
|  | 		item := listable.Index(i) | ||
|  | 		ss[i] = item.String() | ||
|  | 	} | ||
|  | 
 | ||
|  | 	return attributeValueProxy{value: &types.AttributeValueMemberSS{Value: ss}}, nil | ||
|  | } | ||
|  | 
 | ||
|  | func moduleAttrValue() ucl.Module { | ||
|  | 	m := avModule{} | ||
|  | 
 | ||
|  | 	return ucl.Module{ | ||
|  | 		Name: "av", | ||
|  | 		Builtins: map[string]ucl.BuiltinHandler{ | ||
|  | 			"true":       m.avTrue, | ||
|  | 			"false":      m.avFalse, | ||
|  | 			"null":       m.avNull, | ||
|  | 			"string-set": m.avStringSet, | ||
|  | 		}, | ||
|  | 	} | ||
|  | } |