FAQ
Hello,

I'm trying to implement database/sql Scanner for my custom type that embeds
time.Time but I can't figure out how to properly do it without errors from
compiler.

type MyTime struct {
     time.Time
}

func (t MyTime) Scan(src interface{}) error {
     tt := src.(time.Time)
    // Now having time.Time I would like to cast it to my MyType
    return nil
}

I have tried few ways to do it but I always get an error. I appreciate any
help.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ralph Zajac at Apr 6, 2014 at 11:39 pm
    Ok I feel stupid :) Not sure why I did not see it before :)

    func (t MyTime) Scan(src interface{}) error {
         t.Time = src.(time.Time)
        return nil
    }
    On Monday, April 7, 2014 1:02:52 AM UTC+2, Ralph Zajac wrote:

    Hello,

    I'm trying to implement database/sql Scanner for my custom type that
    embeds time.Time but I can't figure out how to properly do it without
    errors from compiler.

    type MyTime struct {
    time.Time
    }

    func (t MyTime) Scan(src interface{}) error {
    tt := src.(time.Time)
    // Now having time.Time I would like to cast it to my MyType
    return nil
    }

    I have tried few ways to do it but I always get an error. I appreciate any
    help.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael boke at Apr 7, 2014 at 8:15 am
    Happens to me all the time ;)

    Op maandag 7 april 2014 01:39:22 UTC+2 schreef Ralph Zajac:
    Ok I feel stupid :) Not sure why I did not see it before :)

    func (t MyTime) Scan(src interface{}) error {
    t.Time = src.(time.Time)
    return nil
    }
    On Monday, April 7, 2014 1:02:52 AM UTC+2, Ralph Zajac wrote:

    Hello,

    I'm trying to implement database/sql Scanner for my custom type that
    embeds time.Time but I can't figure out how to properly do it without
    errors from compiler.

    type MyTime struct {
    time.Time
    }

    func (t MyTime) Scan(src interface{}) error {
    tt := src.(time.Time)
    // Now having time.Time I would like to cast it to my MyType
    return nil
    }

    I have tried few ways to do it but I always get an error. I appreciate
    any help.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 6, '14 at 11:02p
activeApr 7, '14 at 8:15a
posts3
users2
websitegolang.org

2 users in discussion

Ralph Zajac: 2 posts Michael boke: 1 post

People

Translate

site design / logo © 2022 Grokbase