uuid err = srvcliLookupNetworkByUUIDbytereqUUId if err != nil loggerErrorerrError return false err 报错:UUID must be exactly 16 bytes in size
The error message suggests that the UUID provided in req.UUId is not 16 bytes in size. A UUID (Universally Unique Identifier) is a 128-bit value typically represented as a string of 32 hexadecimal digits separated by hyphens.
To fix this error, you need to ensure that the UUID provided in req.UUId is a valid UUID and has a length of exactly 16 bytes. You can use a library or function to convert the UUID string to bytes before passing it to LookupNetworkByUUID function. Here's an example using the github.com/google/uuid library:
import (
"github.com/google/uuid"
)
// ...
// Convert UUID string to bytes
uuidBytes, err := uuid.Parse(req.UUId)
if err != nil {
logger.Error(err.Error())
return false, err
}
// Lookup network by UUID
network, err := srv.cli.LookupNetworkByUUID(uuidBytes[:])
if err != nil {
logger.Error(err.Error())
return false, err
}
// Use the network variable as needed
In this example, the uuid.Parse function is used to convert the UUID string to bytes. The [:16] slice notation is used to extract the first 16 bytes from the UUID byte slice. Make sure to import the github.com/google/uuid package before using it.
原文地址: https://www.cveoy.top/t/topic/iD48 著作权归作者所有。请勿转载和采集!