This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mongo | |
import ( | |
"fmt" | |
"go.mongodb.org/mongo-driver/bson" | |
"go.mongodb.org/mongo-driver/mongo/options" | |
"log" | |
) | |
// GetEvents executes a Find query with query parameters that don't include operations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mongo | |
import ( | |
"context" | |
mgo "go.mongodb.org/mongo-driver/mongo" | |
) | |
// ExecuteParams defines the necessary values to execute a | |
// mongo query | |
type ExecuteParams struct { | |
Context context.Context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mongo | |
import ( | |
"go.mongodb.org/mongo-driver/bson" | |
"go.mongodb.org/mongo-driver/bson/primitive" | |
) | |
const ( | |
eventVersionKey = "event.version" | |
eventTimestampKey = "event.timestamp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connection tests the mongodb connection health | |
var Health = func(w http.ResponseWriter, r *http.Request) { | |
(w).Header().Set("Content-Type", "application/json") | |
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | |
defer cancel() | |
client, err := mongo.Connect(ctx) | |
if err != nil { | |
writeStatus(&w, http.StatusBadRequest, err.Error()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect returns a successfully connected mongo client | |
func Connect(ctx context.Context) (*mongo.Client, error) { | |
url := "mongodb://admin:admin@localhost:27017" | |
log.Printf("connect to mongodb at: %v", url) | |
opts := options.Client() | |
opts.ApplyURI(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
mongo: | |
image: mongo | |
restart: always | |
ports: | |
- 27017:27017 | |
environment: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package services | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
type status struct { | |
Message string `json:"message"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// create anew http router | |
rtr := mux.NewRouter() | |
// health endpoint | |
rtr.HandleFunc("/health", services.Health).Methods(get) | |
// use go routinue to serve endpoint | |
ctx := context.Background() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getList = async (key) => { | |
// perform specific action here | |
return new Promise(resolve => { | |
client.lrange(key, 0, -1, (err, res) => { | |
if (err) console.error(err); | |
resolve(res) | |
}) | |
}) | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('express')(); | |
const bodyParser = require('body-parser'); | |
// parse to json | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
// store integration | |
const { get, set } = require('./store'); |