remote-challenge-sync-airbus: WIP
This commit is contained in:
parent
6d9fd1ff12
commit
367e686e8a
5 changed files with 270 additions and 51 deletions
50
remote/challenge-sync-airbus/timestamp.go
Normal file
50
remote/challenge-sync-airbus/timestamp.go
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func loadTS(tspath string) (timestamp *time.Time, err error) {
|
||||
if _, err = os.Stat(tspath); os.IsNotExist(err) {
|
||||
init := time.Unix(0, 0)
|
||||
timestamp = &init
|
||||
|
||||
err = saveTS(tspath, timestamp)
|
||||
return
|
||||
}
|
||||
|
||||
var fd *os.File
|
||||
fd, err = os.Open(tspath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
var init int64
|
||||
_, err = fmt.Fscanf(fd, "%d", &init)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
tmp := time.Unix(init, 0)
|
||||
timestamp = &tmp
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func saveTS(tspath string, ts *time.Time) error {
|
||||
fd, err := os.Create(tspath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
_, err = fmt.Fprintf(fd, "%d", ts.Unix())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in a new issue