github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/sqlx/presets/operate_time.go (about)

     1  package presets
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/artisanhe/tools/timelib"
     7  )
     8  
     9  type OperateTime struct {
    10  	CreateTime timelib.MySQLTimestamp `db:"F_create_time" sql:"bigint(64) NOT NULL DEFAULT '0'" json:"createTime"`
    11  	UpdateTime timelib.MySQLTimestamp `db:"F_update_time" sql:"bigint(64) NOT NULL DEFAULT '0'" json:"updateTime"`
    12  }
    13  
    14  func (t *OperateTime) BeforeUpdate() {
    15  	t.UpdateTime = timelib.MySQLTimestamp(time.Now())
    16  }
    17  
    18  func (t *OperateTime) BeforeInsert() {
    19  	t.CreateTime = timelib.MySQLTimestamp(time.Now())
    20  	t.UpdateTime = t.CreateTime
    21  }