Marshalling Time fields as Unix time
<p>I want to encode my <code>time.Time</code> fields as numeric Unix time and I would prefer not to implement custom MarshalJSON functions for each and every struct, since I have lots and lots of structs.</p>

<p>So, I tried defining a type alias as such:</p>

<p><code>type Timestamp time.Time</code></p>

<p>And implementing MarshalJSON on it like so:</p>

<pre><code>func (t Timestamp) MarshalJSON() ([]byte, error) {
    return []byte(strconv.FormatInt(t.Unix(), 10)), nil
}
</code></pre>

<p>But that gives me a <code>t.Unix undefined (type Timestamp has no field or method Unix)</code>, which doesn't make sense to me. Shouldn't <code>Timestamp</code> 'inherit' (I know that's probably the wrong term) all functions of <code>time.Time</code>?</p>

<p>I also tried using a type assertion like so:</p>

<pre><code>strconv.FormatInt(t.(time.Time).Unix(), 10)
</code></pre>

<p>But that also fails, complaining about an invalid type assertion: <code>invalid type assertion: t.(time.Time) (non-interface type Timestamp on left)</code></p>