Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created April 11, 2012 20:57
Show Gist options
  • Select an option

  • Save jordanorelli/2362527 to your computer and use it in GitHub Desktop.

Select an option

Save jordanorelli/2362527 to your computer and use it in GitHub Desktop.
type Timestamp int
func (t *Timestamp) UnmarshalJSON(b []byte) error {
if len(b) < 2 { // empty string
*t = Timestamp(0)
return nil
}
i, err := strconv.Atoi(string(b[1 : len(b)-1]))
if err != nil {
return err
}
*t = Timestamp(i)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment