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) {
|
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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user