fix imports and lint v2

pull/71/head
Lukas Rist 2022-11-09 17:44:13 +01:00
parent 2757c5a280
commit 232d5bb5a3
8 changed files with 30 additions and 39 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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)")
}
}

View File

@ -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")
}
}

View File

@ -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)

View File

@ -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

View File

@ -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")
}

View File

@ -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)
}
}