Skip to content

Commit

Permalink
Update README and refactor MongoDB connection to use configurable URI
Browse files Browse the repository at this point in the history
  • Loading branch information
abaldeweg authored Jan 30, 2025
1 parent 9f17184 commit d08e1d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ Mount data volume to `/usr/src/app/data/`.

The module processes logs and returns them by request.

Mount data volumes to `/usr/src/app/data/auth/`, `/usr/src/app/data/db/` and `/usr/src/app/data/source/`.
Mount data volumes to `/usr/src/app/data/auth/` and `/usr/src/app/data/source/`.

|Var |Description
|-----------------------|-----------
|MONGODB_URI |MongoDB connection string

## Release

Expand Down
3 changes: 2 additions & 1 deletion logs_import/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

"github.com/abaldeweg/warehouse-server/logs_import/entity"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -18,7 +19,7 @@ type DBHandler struct {

// NewDBHandler creates a new DBHandler.
func NewDBHandler() (*DBHandler, error) {
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
clientOptions := options.Client().ApplyURI(viper.Get("MONGODB_URI").(string))
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions logs_import/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package main
import (
"time"

"github.com/abaldeweg/warehouse-server/framework/config"
"github.com/abaldeweg/warehouse-server/logs_import/cmd"
"github.com/spf13/viper"
)

func main() {
config.LoadAppConfig()

viper.SetDefault("MONGODB_URI", "mongodb://localhost:27017")

go cmd.Execute()

for {
Expand Down
5 changes: 3 additions & 2 deletions logs_web/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ import (
"time"

"github.com/abaldeweg/warehouse-server/logs_web/entity"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

// DBHandler handles database operations for logs.
type DBHandler struct {
client *mongo.Client
client *mongo.Client
collection *mongo.Collection
}

// NewDBHandler creates a new DBHandler.
func NewDBHandler() (*DBHandler, error) {
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
clientOptions := options.Client().ApplyURI(viper.Get("MONGODB_URI").(string))
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions logs_web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package main
import (
"log"

"github.com/abaldeweg/warehouse-server/framework/config"
"github.com/abaldeweg/warehouse-server/logs_web/router"
"github.com/spf13/viper"
)

func main() {
config.LoadAppConfig()

viper.SetDefault("MONGODB_URI", "mongodb://localhost:27017")

r := router.Routes()
log.Fatal(r.Run(":8080"))
}

0 comments on commit d08e1d8

Please sign in to comment.