Jesse Walton
Jesse Walton

Reputation: 147

Go SQL Scan/Value Interface Issue

I am attempting to add a scan/value interface for automatic conversion for my custom structs. I was also able to implement both Value() and Scan() on a bool type, but when trying to implement it on something with a gocql.UUID field, I can't get the Scan() to work.

Any suggestions would be very much appreciated!

Short Example:

type Uid struct {
    gocql.UUID
}

func (u *Uid) Scan(value interface{}) error {
    ...
    if sv, err := driver.String.ConvertValue(value); err == nil {
    if v, ok := sv.(string); ok { // <---  THIS DOESN'T WORK
        parsedUUID, _ := gocql.ParseUUID(v)
        ...
    }
}

Full code: https://play.golang.org/p/ndCZTJZ5rb

Upvotes: 0

Views: 520

Answers (1)

Jesse Walton
Jesse Walton

Reputation: 147

The value was already structured as a byte array, so the solution ended up being:

fmt.Sprintf("%s", sv) 

Upvotes: 1

Related Questions