Add mongo to docker and test logger
This commit is contained in:
parent
523f7f8280
commit
d670e87908
@ -13,7 +13,11 @@ type JSONPayload struct {
|
||||
func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
|
||||
// read json into var
|
||||
var requestPayload JSONPayload
|
||||
app.readJSON(w, r, &requestPayload)
|
||||
err := app.readJSON(w, r, &requestPayload)
|
||||
if err != nil {
|
||||
app.errorJSON(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// insert data
|
||||
event := data.LogEntry{
|
||||
@ -21,7 +25,7 @@ func (app *Config) WriteLog(w http.ResponseWriter, r *http.Request) {
|
||||
Data: requestPayload.Data,
|
||||
}
|
||||
|
||||
err := app.Models.LogEntry.Insert(event)
|
||||
err = app.Models.LogEntry.Insert(event)
|
||||
if err != nil {
|
||||
app.errorJSON(w, err)
|
||||
return
|
||||
|
@ -47,7 +47,8 @@ func main() {
|
||||
}
|
||||
|
||||
// start web server
|
||||
go app.serve()
|
||||
log.Println("Starting service on port", webPort)
|
||||
app.serve()
|
||||
}
|
||||
|
||||
func (app *Config) serve() {
|
||||
@ -74,5 +75,7 @@ func connectToMongo() (*mongo.Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Println("Connected to Mongo")
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
@ -37,6 +37,17 @@ services:
|
||||
volumes:
|
||||
- ./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:
|
||||
image: adminer
|
||||
restart: always
|
||||
|
Loading…
Reference in New Issue
Block a user