I think what was meant was to define Service as:

type Service struct {
ID       string `json:"id,omitempty" db:"id"`
Name     string `json:"name" db:"name"`
Contract json.RawMessage `json:"contract" db:"contract"`
}

This assumes you don't need to access the contents of Service.Contract and 
they are meant to be stored in the db as a JSON-encoded blob (and that the 
db driver recognises json.RawMessage as something to store in a blob).

If one or more of these assumptions is not true, you will need separate 
structs for dealing with JSON and the db. For example:

type ServiceJSON struct {
ID       string `json:"id,omitempty"`
Name     string `json:"name"`
Contract struct {
Ha          string `json:"ha"`
ServiceTime int    `json:"service_time"`
Region      string `json:"region"`
} `json:"contract"`
}

and

type ServiceDB struct {
ID       string `db:"id"`
Name     string `db:"name"`
Contract []byte `db:"contract"`
}

and convert between them as needed.

Hope this helps,
Nathan

On Friday, November 17, 2017 at 8:31:19 AM UTC+1, mail...@gmail.com wrote:
>
> Tamas,
>
>     Can u explain ?
>
> On Thursday, November 16, 2017 at 11:47:03 PM UTC+5:30, Tamás Gulácsi 
> wrote:
>>
>> json.RawMessage
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to