FAQ
I'm using this library(https://github.com/jinzhu/gorm) to retrieve a record
from a mysql database. I retrieve the record without a problem here is the
struct below.

type Reseller struct {
Id int64
Name sql.NullString
AppDomain sql.NullString
Installed sql.NullInt64
MarketingType sql.NullString
Bundleurl sql.NullString
Bundlename sql.NullString
BundleType sql.NullString
}


I wanted to write a simple test and I saw that I couldn't access the struct
field directly and I'm curious why? The function below would return "Box
Report for {Dr. XYZ true}" instead of "Box Report for Dr.XYZ"
I played around changed the function to what is below. I'm curious when
does one know to use this syntax?

//Report reports on monthly usage
func (b *Box) Report() string {
var report string
report = fmt.Sprintf("Box Report for %v", b.Reseller.Name.String)

return report
}


Thanks in advanced



--
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

  • Ibrahim M. Ghazal at Jul 24, 2014 at 2:36 pm
    Because sql.NullString is itself a struct, so %v prints both values inside
    it (the string and the bool).

    --
    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.
  • Alex Casanova at Jul 25, 2014 at 4:14 am
    Thanks Ibrahim, makes sense now!
    On Thursday, July 24, 2014 10:36:27 AM UTC-4, Ibrahim M. Ghazal wrote:

    Because sql.NullString is itself a struct, so %v prints both values inside
    it (the string and the bool).
    --
    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
postedJul 24, '14 at 2:12p
activeJul 25, '14 at 4:14a
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase