Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
647a90c0f2 | ||
|
92469f11b2 | ||
a75aeeb8f9 | |||
|
d4f2624635 | ||
|
2259d3ed6b |
2
.drone.yml
Normal file
2
.drone.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
kind: template
|
||||
load: docker-multiarch.yaml
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM golang:1.21 as build
|
||||
|
||||
WORKDIR /godoor
|
||||
|
||||
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download && go mod verify
|
||||
|
||||
|
||||
COPY . .
|
||||
RUN make build
|
||||
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
COPY --from=build /godoor/godoor /godoor
|
||||
|
||||
ENTRYPOINT ["/godoor"]
|
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@
|
||||
|
||||
all: build
|
||||
|
||||
GOBUILDLDFLAGS="-X main.Version=`git describe --dirty`"
|
||||
GOBUILDLDFLAGS="-X main.Version=`git describe --always --dirty`"
|
||||
#GOBUILDLDFLAGS="-X main.Version=`git describe --dirty` -linkmode 'external' -extldflags '-static'"
|
||||
|
||||
build:
|
||||
|
51
godoor.go
51
godoor.go
@@ -195,27 +195,6 @@ func setup() {
|
||||
|
||||
http.DefaultClient.Timeout = 120 * time.Second
|
||||
|
||||
go func() {
|
||||
for {
|
||||
err := waitEvents()
|
||||
if err != nil {
|
||||
apiFailuresCount.WithLabelValues("longpoll", config.api.longpoll).Inc()
|
||||
log.Printf("LongPoll for events failed: %v", err)
|
||||
log.Println("Will try to LongPoll again in 120 seconds")
|
||||
time.Sleep(120 * time.Second)
|
||||
go func() {
|
||||
err := reloadTokens()
|
||||
if err != nil {
|
||||
apiFailuresCount.WithLabelValues("allowed", config.api.allowed).Inc()
|
||||
}
|
||||
}()
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Println("Initialized longpoll event loop")
|
||||
|
||||
for {
|
||||
log.Println("Start initial token population")
|
||||
err := reloadTokens()
|
||||
@@ -230,6 +209,27 @@ func setup() {
|
||||
|
||||
log.Println("Initial token population success")
|
||||
|
||||
go func() {
|
||||
for {
|
||||
err := waitEvents()
|
||||
if err != nil {
|
||||
apiFailuresCount.WithLabelValues("longpoll", config.api.longpoll).Inc()
|
||||
log.Printf("LongPoll for events failed: %v", err)
|
||||
log.Println("Will try to LongPoll again soon")
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
go func() {
|
||||
err := reloadTokens()
|
||||
if err != nil {
|
||||
log.Printf("ReloadTokens failed: %q", err)
|
||||
apiFailuresCount.WithLabelValues("allowed", config.api.allowed).Inc()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
log.Println("Initialized longpoll event loop")
|
||||
|
||||
go cardRunner(wiegand)
|
||||
|
||||
log.Println("Setup completed")
|
||||
@@ -290,7 +290,7 @@ func cardRunner(w Wiegand) {
|
||||
continue
|
||||
}
|
||||
|
||||
printCardId(card)
|
||||
//printCardId(card)
|
||||
hashedHex := hash.HashCardUid(card)
|
||||
log.Println(hashedHex)
|
||||
|
||||
@@ -464,11 +464,11 @@ func handleKeepDoorOpenCloseCleanup() {
|
||||
}
|
||||
|
||||
func sendSwipeEvent(cardUidHash string, success bool) error {
|
||||
swipeEvent := map[string]string{
|
||||
swipeEvent := map[string]any{
|
||||
"uid_hash": cardUidHash,
|
||||
"door": config.door,
|
||||
"timestamp": time.Now().Format(time.DateTime),
|
||||
"success": fmt.Sprint(success),
|
||||
"timestamp": time.Now().Format(time.RFC3339),
|
||||
"success": success,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(swipeEvent)
|
||||
@@ -481,6 +481,7 @@ func sendSwipeEvent(cardUidHash string, success bool) error {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("KEY", config.api.key)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -113,14 +113,14 @@ func WiegandSetup(a int, b int, bitTimeout time.Duration, solenoid int) *Wiegand
|
||||
}
|
||||
|
||||
wa, err := gpiod.RequestLine("gpiochip0", a, gpiod.AsInput,
|
||||
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegand.wiegandAEvent))
|
||||
gpiod.WithFallingEdge, gpiod.LineBiasPullUp, gpiod.WithEventHandler(wiegand.wiegandAEvent))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
wiegand.aLine = wa
|
||||
|
||||
wb, err := gpiod.RequestLine("gpiochip0", b, gpiod.AsInput,
|
||||
gpiod.WithFallingEdge, gpiod.WithEventHandler(wiegand.wiegandBEvent))
|
||||
gpiod.WithFallingEdge, gpiod.LineBiasPullUp, gpiod.WithEventHandler(wiegand.wiegandBEvent))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user