Comparing md5.Sum to text from file
To clearly state our problem/task: We want to compare 2 checksums, one supplied as a text being the hexadecimal representation, and the other being an array of the "raw" bytes.

2 forms exist: a hexadecimal representation and raw bytes. To compare them, we need the same representation. So 2 possible paths:

1. Convert the second to hex representation

Let's see your proposed solution. If we want to handle leading/trailing spaces, and if the text input may contain lowercased and uppercased hex digits, your solution is as simple as it can be.

A variation may be to convert the text to lowercased, and then we can simply compare strings without strings.EqualFold(). The lowercase conversion can be done by calling strings.ToLower() or since we already have the input as []byte, by bytes.ToLower():

checkSum = bytes.ToLower(bytes.TrimSpace(checkSum))
argHash := makeHash(flag.Arg(0))
if fmt.Sprintf("%x", argHash) == string(checkSum) {
    // They match
} else {
    // They don't match
}


2. Convert the first to raw bytes

Compare slices ([]byte)

We may choose to convert the text checksum back to a []byte which holds the raw bytes of the checksum (NOT the bytes of the UTF-8 encoded hex representation).

We can parse the hex representation simply with hex.DecodeString(). Or even better: since we have the text checksum as a []byte, we can use hex.Decode() which takes input as a []byte.

As an extra gain, we don't even have to care about lower or upper case: hex.Decode() handles that for us.

And we can convert [16]byte to []byte by simply slicing it. Once we have 2 []byte, we can use bytes.Equal() to compare them (in Go slices are not comparable unlike arrays).

checkSum = bytes.TrimSpace(checkSum)
dst := make([]byte, 16)
if _, err := hex.Decode(dst, checkSum); err != nil {
    // Invalid input, not hex string or not 16 bytes!
} else {
    argHash := makeHash(flag.Arg(0))
    if bytes.Equal(argHash[:], dst) {
        // They match
    } else {
        // They don't match
    }
}


Compare arrays ([16]byte)

As a variation of the previous solution, we will use arrays to do the comparison as arrays are comparable.

Since makeHash() already returns an array [16]byte, we only need to get the raw bytes of the text checksum into an array. The simplest and fastest is to create an array [16]byte, and pass such a slice to hex.Decode() that shares its backing array with our new array. We can obtain such a slice by simply slicing the array:

checkSum = bytes.TrimSpace(checkSum)
dst := [16]byte{}
if _, err := hex.Decode(dst[:], checkSum); err != nil {
    // Invalid input, not hex string or not 16 bytes!
} else {
    if makeHash(flag.Arg(0)) == dst) {
        // They match
    } else {
        // They don't match
    }
}


Compare manually (byte-by-byte)

We can also do the comparison manually, it's relatively easy and straightforward.

But first to do it manually, let's create a simple helper function which tells if a hex digit (the text representation) equals to the raw data:

func match(hex, raw byte) bool {
    if raw &lt; 10 {
        return hex-'0' == raw
    }
    return hex-'a'+10 == raw || hex-'A'+10 == raw
}


And with this the solution:

checkSum = bytes.TrimSpace(checkSum)
argHash := makeHash(flag.Arg(0))
if len(checkSum) != 2*len(argHash) {
    // Quick check: length differ, they don't match!
} else {
    equal := true
    for i, v := range argHash {
        if !match(checkSum[i*2], v &gt;&gt; 4) || !match(checkSum[i*2+1], v &amp; 0x0f) {
            equal = false
            break
        }
    }
    // Now the variable "equal" tells if they are equal
}