Stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Kekskurse 2022-01-14 21:57:07 +01:00
parent 522d0396fe
commit 9a2f7f6dd2
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4
5 changed files with 36 additions and 3 deletions

17
.drone.yml Normal file
View 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
View 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
View file

@ -0,0 +1,2 @@
build:
CGO_ENABLED=0 GOOS=linux go build ./

BIN
eventTimeTracking Executable file

Binary file not shown.

14
main.go
View file

@ -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)
}