Add mongo to docker and test logger

This commit is contained in:
vinchent 2024-08-29 13:48:47 +02:00
parent 523f7f8280
commit d670e87908
3 changed files with 21 additions and 3 deletions

View File

@ -13,7 +13,11 @@ type JSONPayload struct {
func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) { func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
// read json into var // read json into var
var requestPayload JSONPayload var requestPayload JSONPayload
app.readJSON(w, r, &requestPayload) err := app.readJSON(w, r, &requestPayload)
if err != nil {
app.errorJSON(w, err)
return
}
// insert data // insert data
event := data.LogEntry{ event := data.LogEntry{
@ -21,7 +25,7 @@ func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
Data: requestPayload.Data, Data: requestPayload.Data,
} }
err := app.Models.LogEntry.Insert(event) err = app.Models.LogEntry.Insert(event)
if err != nil { if err != nil {
app.errorJSON(w, err) app.errorJSON(w, err)
return return

View File

@ -47,7 +47,8 @@ func main() {
} }
// start web server // start web server
go app.serve() log.Println("Starting service on port", webPort)
app.serve()
} }
func (app *Config) serve() { func (app *Config) serve() {
@ -74,5 +75,7 @@ func connectToMongo() (*mongo.Client, error) {
return nil, err return nil, err
} }
log.Println("Connected to Mongo")
return client, nil return client, nil
} }

View File

@ -37,6 +37,17 @@ services:
volumes: volumes:
- ./db-data/postgres:/var/lib/postgresql/data - ./db-data/postgres:/var/lib/postgresql/data
mongo:
image: mongo
ports:
- "27017:27017"
environment:
MONGO_INITDB_DATABASE: logs
MONGO_INITDB_USERNAME: admin
MONGO_INITDB_PASSWORD: password
volumes:
- ./db-data/mongo:/data/db
adminer: adminer:
image: adminer image: adminer
restart: always restart: always