Add envitron support
This commit is contained in:
parent
6643217fdb
commit
c6e735950f
12 changed files with 402 additions and 238 deletions
28
shared/type.go
Normal file
28
shared/type.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UnixTimestamp is a time.Time that can parse unix timestamps
|
||||
type UnixTimestamp time.Time
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler
|
||||
func (t *UnixTimestamp) UnmarshalText(b []byte) error {
|
||||
i, err := strconv.ParseInt(string(b), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = UnixTimestamp(time.Unix(i, 0))
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler
|
||||
func (t *UnixTimestamp) UnmarshalJSON(b []byte) error {
|
||||
return t.UnmarshalText(b)
|
||||
}
|
||||
|
||||
func (t UnixTimestamp) String() string {
|
||||
return time.Time(t).Format(`2006-01-02 15:04`)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue