package host import ( "time" ) type IPayload interface { updateState(*State) } type postKpowerPayload struct { OpType OperationType `json:"type" binding:"required,oneof=REBOOT SHUTDOWN"` Opts Options `json:"options"` RequestID string } func (payload *postKpowerPayload) updateState(hostState *State) { hostState.Kpower.Op.OpType = payload.OpType hostState.Kpower.Op.Opts = payload.Opts hostState.Kpower.Op.RequestID = payload.RequestID } type putKpowerPayload struct { Status PowerStatus `json:"status" binding:"required,oneof=RUNNING CORDONED DRAINED TERMINATED"` Op Operation `json:"operation"` Timestamp time.Time `json:"timestamp,omitempty" time_format:"2006-01-02T15:04:05Z"` } func (payload *putKpowerPayload) updateState(hostState *State) { timestamp := payload.Timestamp if timestamp.IsZero() { timestamp = time.Now() } hostState.Kpower.Status = payload.Status hostState.Kpower.Timestamp = timestamp.Format(time.RFC3339) }