This commit is contained in:
parent
522d0396fe
commit
9a2f7f6dd2
5 changed files with 36 additions and 3 deletions
17
.drone.yml
Normal file
17
.drone.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: kekskurse/ett
|
||||
username: kekskurse
|
||||
password:
|
||||
from_secret: docker_password
|
6
Dockerfile
Normal file
6
Dockerfile
Normal file
|
@ -0,0 +1,6 @@
|
|||
FROM scratch
|
||||
COPY ./eventTimeTracking /ett
|
||||
#RUN ls -lah /
|
||||
#RUN chmod uog+rwx /ett
|
||||
#RUN /ett
|
||||
CMD ["/ett"]
|
2
Makefile
Normal file
2
Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
build:
|
||||
CGO_ENABLED=0 GOOS=linux go build ./
|
BIN
eventTimeTracking
Executable file
BIN
eventTimeTracking
Executable file
Binary file not shown.
14
main.go
14
main.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"github.com/rs/zerolog/log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -16,12 +17,19 @@ type Event struct {
|
|||
eventTimestamp time.Time
|
||||
}
|
||||
|
||||
var eventlog string
|
||||
|
||||
//Current State
|
||||
var lastEvent Event
|
||||
var currentState map[string]map[string]int64 //Per Name per Day in Secounds
|
||||
|
||||
|
||||
func main() {
|
||||
eventlogPath := flag.String("eventlog", "/var/ett/eventlog", "Where to store the eventlog file")
|
||||
|
||||
flag.Parse()
|
||||
eventlog = *eventlogPath
|
||||
|
||||
log.Info().Msg("Start Time Tracking Service")
|
||||
currentState = make(map[string]map[string]int64)
|
||||
|
||||
|
@ -120,9 +128,9 @@ func runHttpServer() {
|
|||
}
|
||||
|
||||
func readStateFromFile() {
|
||||
if _, err := os.Stat("eventlog"); err == nil {
|
||||
if _, err := os.Stat(eventlog); err == nil {
|
||||
// path/to/whatever exists
|
||||
file, err := os.Open("eventlog")
|
||||
file, err := os.Open(eventlog)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Cant open file")
|
||||
|
@ -151,7 +159,7 @@ func readStateFromFile() {
|
|||
func saveEvent(e Event) {
|
||||
var line string
|
||||
line = e.eventTimestamp.Format(time.RFC3339)+";"+e.name+"\r\n"
|
||||
f, err := os.OpenFile("eventlog", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
f, err := os.OpenFile(eventlog, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue