diff --git a/v2/ifd_builder.go b/v2/ifd_builder.go index b2a962b..e3208c5 100644 --- a/v2/ifd_builder.go +++ b/v2/ifd_builder.go @@ -17,10 +17,6 @@ import ( log "github.com/dsoprea/go-logging" ) -var ( - ifdBuilderLogger = log.NewLogger("exif.ifd_builder") -) - var ( ErrTagEntryNotFound = errors.New("tag entry not found") ErrChildIbNotFound = errors.New("child IB not found") @@ -497,7 +493,7 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) { // TODO(dustin): !! Add a test for this function. - if data == nil || len(data) == 0 { + if len(data) == 0 { log.Panic("thumbnail is empty") } @@ -675,7 +671,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, tagId uin childPrefix := "" if prefix == "" { - childPrefix = fmt.Sprintf("%s", thisIb.IfdIdentity().UnindexedString()) + childPrefix = thisIb.IfdIdentity().UnindexedString() } else { childPrefix = fmt.Sprintf("%s->%s", prefix, thisIb.IfdIdentity().UnindexedString()) } @@ -1010,7 +1006,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl continue } - if excludeTagIds != nil && len(excludeTagIds) > 0 { + if len(excludeTagIds) > 0 { found := false for _, excludedTagId := range excludeTagIds { if excludedTagId == ite.TagId() { @@ -1023,7 +1019,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excl } } - if includeTagIds != nil && len(includeTagIds) > 0 { + if len(includeTagIds) > 0 { // Whether or not there was a list of excludes, if there is a list // of includes than the current tag has to be in it. diff --git a/v2/ifd_builder_encode.go b/v2/ifd_builder_encode.go index 9f21898..78f8a4a 100644 --- a/v2/ifd_builder_encode.go +++ b/v2/ifd_builder_encode.go @@ -235,7 +235,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw * len_ := len(valueBytes) unitCount := uint32(len_) / typeSize - if _, found := tagsWithoutAlignment[bt.tagId]; found { + if _, found := tagsWithoutAlignment[bt.tagId]; !found { remainder := uint32(len_) % typeSize if remainder > 0 { diff --git a/v2/ifd_builder_encode_test.go b/v2/ifd_builder_encode_test.go index 8f142a3..e0a9410 100644 --- a/v2/ifd_builder_encode_test.go +++ b/v2/ifd_builder_encode_test.go @@ -6,9 +6,9 @@ import ( "strings" "testing" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) func Test_ByteWriter_writeAsBytes_uint8(t *testing.T) { @@ -299,17 +299,17 @@ func Test_IfdByteEncoder_encodeTagToBytes_bytes_allocated(t *testing.T) { if childIfdBlock != nil { t.Fatalf("no child-IFDs were expected to be allocated (2)") - } else if bytes.Compare(b.Bytes(), []byte{ + } else if !bytes.Equal(b.Bytes(), []byte{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x34, // Tag 1 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x12, 0x39, // Tag 2 - }) != 0 { + }) { t.Fatalf("encoded tag-entry bytes not correct (2)") } else if ida.NextOffset() != addressableOffset+uint32(10) { t.Fatalf("allocation offset not expected (2)") - } else if bytes.Compare(ida.Bytes(), []byte{ + } else if !bytes.Equal(ida.Bytes(), []byte{ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xbc, 0xde, 0xf0, 0x12, 0x34, - }) != 0 { + }) { t.Fatalf("allocated data not correct (2)") } } diff --git a/v2/ifd_builder_test.go b/v2/ifd_builder_test.go index a8c24be..fc12e6e 100644 --- a/v2/ifd_builder_test.go +++ b/v2/ifd_builder_test.go @@ -9,9 +9,9 @@ import ( "testing" "time" - "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" - "github.com/dsoprea/go-logging" + exifcommon "github.com/dsoprea/go-exif/v2/common" + exifundefined "github.com/dsoprea/go-exif/v2/undefined" + log "github.com/dsoprea/go-logging" ) func TestIfdBuilder_Add(t *testing.T) { @@ -2144,9 +2144,9 @@ func TestNewStandardBuilderTag__TwoUnits(t *testing.T) { t.Fatalf("II in BuilderTag not correct") } else if bt.tagId != 0x8833 { t.Fatalf("tag-ID not correct") - } else if bytes.Compare(bt.value.Bytes(), []byte{ + } else if !bytes.Equal(bt.value.Bytes(), []byte{ 0x0, 0x0, 0x12, 0x34, - 0x0, 0x0, 0x56, 0x78}) != 0 { + 0x0, 0x0, 0x56, 0x78}) { t.Fatalf("value not correct") } } diff --git a/v2/ifd_enumerate.go b/v2/ifd_enumerate.go index 18ab6aa..72934c6 100644 --- a/v2/ifd_enumerate.go +++ b/v2/ifd_enumerate.go @@ -78,7 +78,6 @@ var ( type byteParser struct { byteOrder binary.ByteOrder addressableData []byte - ifdOffset uint32 currentOffset uint32 } @@ -320,7 +319,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat // they want to specifically manage these types of tags, they // can use more advanced functionality to specifically -handle // unknown tags. - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) in IFD [%s] is not recognized and "+ "will be ignored.", tagId, ii.String()) @@ -329,7 +328,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat ite.setTagName(it.Name) - utilityLogger.Warningf(nil, + utilityLogger.Warningf(context.TODO(), "Tag with ID (0x%04x) is not valid for IFD [%s], but it *is* "+ "valid as tag [%s] under IFD [%s] and has the same type "+ "[%s], so we will use that. This EXIF blob was probably "+ @@ -357,7 +356,7 @@ func (ie *IfdEnumerate) postparseTag(ite *IfdTagEntry, med *MiscellaneousExifDat // type and caused parsing/conversion woes. So, this is a quick fix // for those scenarios. if !it.DoesSupportType(tagType) { - ifdEnumerateLogger.Warningf(nil, + ifdEnumerateLogger.Warningf(context.TODO(), "Skipping tag [%s] (0x%04x) [%s] with an unexpected type: %v ∉ %v", ii.UnindexedString(), tagId, it.Name, tagType, it.SupportedTypes) @@ -550,7 +549,7 @@ func (ie *IfdEnumerate) scan(iiGeneral *exifcommon.IfdIdentity, ifdOffset uint32 bp, err := ie.getByteParser(ifdOffset) if err != nil { if err == ErrOffsetInvalid { - ifdEnumerateLogger.Errorf(nil, nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) + ifdEnumerateLogger.Errorf(context.TODO(), nil, "IFD [%s] at offset (0x%04x) is unreachable. Terminating scan.", iiSibling.String(), ifdOffset) break } @@ -804,7 +803,7 @@ func (ifd *Ifd) printTagTree(populateValues bool, index, level int, nextLink boo } else { // This will just add noise to the output (byte-tags are fully // dumped). - if ite.IsThumbnailOffset() == true || ite.IsThumbnailSize() { + if ite.IsThumbnailOffset() || ite.IsThumbnailSize() { continue } @@ -988,13 +987,13 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { hit := false for _, acceptedGpsVersion := range ValidGpsVersions { - if bytes.Compare(versionBytes, acceptedGpsVersion[:]) == 0 { + if bytes.Equal(versionBytes, acceptedGpsVersion[:]) { hit = true break } } - if hit != true { + if !hit { ifdEnumerateLogger.Warningf(context.TODO(), "GPS version not supported: %v", versionBytes) log.Panic(ErrNoGpsTags) } @@ -1055,7 +1054,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { altitudeTags, foundAltitude := ifd.EntriesByTagId[TagAltitudeId] altitudeRefTags, foundAltitudeRef := ifd.EntriesByTagId[TagAltitudeRefId] - if foundAltitude == true && foundAltitudeRef { + if foundAltitude && foundAltitudeRef { altitudePhrase, err := altitudeTags[0].Format() log.PanicIf(err) @@ -1089,7 +1088,7 @@ func (ifd *Ifd) GpsInfo() (gi *GpsInfo, err error) { timestampTags, foundTimestamp := ifd.EntriesByTagId[TagTimestampId] datestampTags, foundDatestamp := ifd.EntriesByTagId[TagDatestampId] - if foundTimestamp == true && foundDatestamp { + if foundTimestamp && foundDatestamp { datestampValue, err := datestampTags[0].Value() log.PanicIf(err) diff --git a/v2/ifd_tag_entry.go b/v2/ifd_tag_entry.go index f81bf76..3c5ddee 100644 --- a/v2/ifd_tag_entry.go +++ b/v2/ifd_tag_entry.go @@ -11,10 +11,6 @@ import ( exifundefined "github.com/dsoprea/go-exif/v2/undefined" ) -var ( - iteLogger = log.NewLogger("exif.ifd_tag_entry") -) - // IfdTagEntry refers to a tag in the loaded EXIF block. type IfdTagEntry struct { tagId uint16 diff --git a/v2/tags.go b/v2/tags.go index 0787c28..df01d38 100644 --- a/v2/tags.go +++ b/v2/tags.go @@ -144,9 +144,9 @@ func (it *IndexedTag) GetEncodingType(value interface{}) exifcommon.TagTypePrimi // We specifically check for the cases that we know to expect. - if supportsLong == true && supportsShort { + if supportsLong && supportsShort { return exifcommon.TypeLong - } else if supportsRational == true && supportsSignedRational { + } else if supportsRational && supportsSignedRational { if value == nil { log.Panicf("GetEncodingType: require value to be given") } diff --git a/v2/testing_common.go b/v2/testing_common.go index fe69df9..d6abdac 100644 --- a/v2/testing_common.go +++ b/v2/testing_common.go @@ -7,9 +7,9 @@ import ( "io/ioutil" - "github.com/dsoprea/go-logging" + log "github.com/dsoprea/go-logging" - "github.com/dsoprea/go-exif/v2/common" + exifcommon "github.com/dsoprea/go-exif/v2/common" ) var ( @@ -149,7 +149,7 @@ func validateExifSimpleTestIb(exifData []byte, t *testing.T) { value, err := ite.Value() log.PanicIf(err) - if reflect.DeepEqual(value, expected[i].value) != true { + if !reflect.DeepEqual(value, expected[i].value) { t.Fatalf("Value for entry (%d) not correct: [%v] != [%v]", i, value, expected[i].value) } }