github.com/aavshr/aws-sdk-go@v1.41.3/service/dynamodb/dynamodbattribute/tag.go (about)

     1  package dynamodbattribute
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  )
     7  
     8  type tag struct {
     9  	Name                         string
    10  	Ignore                       bool
    11  	OmitEmpty                    bool
    12  	OmitEmptyElem                bool
    13  	AsString                     bool
    14  	AsBinSet, AsNumSet, AsStrSet bool
    15  	AsUnixTime                   bool
    16  }
    17  
    18  func (t *tag) parseAVTag(structTag reflect.StructTag) {
    19  	tagStr := structTag.Get("dynamodbav")
    20  	if len(tagStr) == 0 {
    21  		return
    22  	}
    23  
    24  	t.parseTagStr(tagStr)
    25  }
    26  
    27  func (t *tag) parseStructTag(tag string, structTag reflect.StructTag) {
    28  	tagStr := structTag.Get(tag)
    29  	if len(tagStr) == 0 {
    30  		return
    31  	}
    32  
    33  	t.parseTagStr(tagStr)
    34  }
    35  
    36  func (t *tag) parseTagStr(tagStr string) {
    37  	parts := strings.Split(tagStr, ",")
    38  	if len(parts) == 0 {
    39  		return
    40  	}
    41  
    42  	if name := parts[0]; name == "-" {
    43  		t.Name = ""
    44  		t.Ignore = true
    45  	} else {
    46  		t.Name = name
    47  		t.Ignore = false
    48  	}
    49  
    50  	for _, opt := range parts[1:] {
    51  		switch opt {
    52  		case "omitempty":
    53  			t.OmitEmpty = true
    54  		case "omitemptyelem":
    55  			t.OmitEmptyElem = true
    56  		case "string":
    57  			t.AsString = true
    58  		case "binaryset":
    59  			t.AsBinSet = true
    60  		case "numberset":
    61  			t.AsNumSet = true
    62  		case "stringset":
    63  			t.AsStrSet = true
    64  		case "unixtime":
    65  			t.AsUnixTime = true
    66  		}
    67  	}
    68  }