update 04.03.24
This commit is contained in:
parent
eab7fea353
commit
5b26df3e4c
10 changed files with 35 additions and 6 deletions
|
@ -2,11 +2,19 @@
|
|||
version: "3.1"
|
||||
|
||||
services:
|
||||
backend:
|
||||
build: ./src
|
||||
restart: always
|
||||
ports:
|
||||
- "3333:3333"
|
||||
environment:
|
||||
- MONGO_URL=mongodb://root:root12345@mongo:27017/
|
||||
depends_on:
|
||||
mongo:
|
||||
condition: service_started
|
||||
mongo:
|
||||
image: mongo
|
||||
restart: always
|
||||
ports:
|
||||
- 27017:27017
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: root
|
||||
MONGO_INITDB_ROOT_PASSWORD: root12345
|
||||
|
@ -15,7 +23,7 @@ services:
|
|||
image: mongo-express
|
||||
restart: always
|
||||
ports:
|
||||
- 8081:8081
|
||||
- "8081:8081"
|
||||
environment:
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: root12345
|
||||
|
|
9
src/Dockerfile
Normal file
9
src/Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
|||
FROM golang:1.22
|
||||
LABEL authors="ZennDev1337"
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY ./ ./
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /gibb165lb2
|
||||
|
||||
CMD ["/gibb165lb2"]
|
|
@ -7,6 +7,7 @@ import (
|
|||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -14,12 +15,15 @@ func main() {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
var err error
|
||||
util.Client, err = mongo.Connect(ctx, options.Client().ApplyURI("mongodb://root:root12345@localhost:27017"))
|
||||
var con_uri = os.Getenv("MONGO_URL")
|
||||
if con_uri == "" {
|
||||
con_uri = "mongodb://root:root12345@localhost:27017"
|
||||
}
|
||||
util.Client, err = mongo.Connect(ctx, options.Client().ApplyURI(con_uri))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//util.InsertRandomData(client)
|
||||
defer util.Client.Disconnect(ctx)
|
||||
r := GetRouter()
|
||||
|
||||
err = http.ListenAndServe(":3333", r)
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"gibb165lb2/router"
|
||||
"gibb165lb2/util"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
@ -19,5 +20,6 @@ func GetRouter() *mux.Router {
|
|||
r.HandleFunc("/debts", router.GetAllDebts).Methods("GET")
|
||||
r.HandleFunc("/debts/{id}", router.GetDebt).Methods("GET")
|
||||
r.HandleFunc("/debts/{id}", router.UpdateDebt).Methods("PUT")
|
||||
r.HandleFunc("/init", util.Init).Methods("GET")
|
||||
return r
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -75,3 +76,8 @@ func InsertRandomData(client *mongo.Client) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Init(w http.ResponseWriter, r *http.Request) {
|
||||
InsertRandomData(Client)
|
||||
w.Write([]byte("Init"))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue