Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9d43b3566
|
|||
308ca8caab
|
|||
1b3429184a
|
|||
a7262d99cc
|
|||
6be68d4dee
|
|||
54eeb17e9b
|
|||
4a56fea33b
|
@ -26,7 +26,45 @@ spec:
|
||||
value: mqtt://emqx01-anonymous-cluster-internal.broker.svc.cluster.local:1883
|
||||
- name: MQTT_TOPIC
|
||||
value: locative/event
|
||||
- name: GIN_MODE
|
||||
value: release
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
protocol: TCP
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: locative
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: locsrv
|
||||
ports:
|
||||
- name: http
|
||||
targetPort: 8080
|
||||
port: 80
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: locative
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: letsencrypt-production-http
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- locative.hottis.de
|
||||
secretName: locative-cert
|
||||
rules:
|
||||
- host: locative.hottis.de
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: locative
|
||||
port:
|
||||
number: 80
|
||||
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
@ -30,6 +31,7 @@ type locativeEvent struct {
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
Person string `json:"person"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +48,7 @@ func main() {
|
||||
person, err := dbh.GetPersonById(event.Device)
|
||||
event.Person = person
|
||||
event.Location = event.Id
|
||||
event.Timestamp = time.Now().Format("2006-01-02 15:04:05 MST")
|
||||
event.Id = ""
|
||||
if err != nil {
|
||||
log.Printf("Person unknown: %v", err)
|
||||
@ -65,11 +68,13 @@ func main() {
|
||||
}()
|
||||
|
||||
router.POST("/location", func(c *gin.Context) {
|
||||
var body locativeEvent
|
||||
err, data := c.GetRawData()
|
||||
log.Printf("raw: %v, %s", err, string(data))
|
||||
|
||||
err := c.ShouldBindJSON(&body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H { "error": err.Error() })
|
||||
var body locativeEvent
|
||||
err1 := c.ShouldBindJSON(&body)
|
||||
if err1 != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H { "error": err1.Error() })
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ func (self *MqttHandle) Publish(topicPost string, message string) error {
|
||||
}
|
||||
|
||||
topic := fmt.Sprintf("%s/%s", self.pubTopic, topicPost)
|
||||
token := self.client.Publish(topic, 0, false, message)
|
||||
token := self.client.Publish(topic, 0, true, message)
|
||||
token.Wait()
|
||||
if token.Error() != nil {
|
||||
return fmt.Errorf("MQTT publish failed: %v", token.Error())
|
||||
|
Reference in New Issue
Block a user