O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Note that the preceding code represents two approaches. The parseWithRawBytes function uses the preferred approach, but it is highly dependent on the driver implementation. It works the way that the slice of RawBytes, with the same length as the number of the columns in the result, is created. Because the Scan function requires pointers to values, we need to create the slice of pointers to the slice of RawBytes (slice of byte slices), then it can be passed to the Scan function.

After it is successfully extracted, we just remap the values. In the example code, we cast it to the string because the driver uses the string type to store the values if the RawBytes is the target. Beware that the form of stored values depends on driver ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required