Add envitron support

This commit is contained in:
Nise Void 2018-06-19 15:20:02 +02:00
parent 6643217fdb
commit c6e735950f
Signed by: NiseVoid
GPG key ID: FBA14AC83EA602F3
12 changed files with 402 additions and 238 deletions

28
shared/type.go Normal file
View 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`)
}