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"
|
version: "3.1"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
backend:
|
||||||
|
build: ./src
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "3333:3333"
|
||||||
|
environment:
|
||||||
|
- MONGO_URL=mongodb://root:root12345@mongo:27017/
|
||||||
|
depends_on:
|
||||||
|
mongo:
|
||||||
|
condition: service_started
|
||||||
mongo:
|
mongo:
|
||||||
image: mongo
|
image: mongo
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
|
||||||
- 27017:27017
|
|
||||||
environment:
|
environment:
|
||||||
MONGO_INITDB_ROOT_USERNAME: root
|
MONGO_INITDB_ROOT_USERNAME: root
|
||||||
MONGO_INITDB_ROOT_PASSWORD: root12345
|
MONGO_INITDB_ROOT_PASSWORD: root12345
|
||||||
|
@ -15,7 +23,7 @@ services:
|
||||||
image: mongo-express
|
image: mongo-express
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 8081:8081
|
- "8081:8081"
|
||||||
environment:
|
environment:
|
||||||
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||||
ME_CONFIG_MONGODB_ADMINPASSWORD: root12345
|
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"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,12 +15,15 @@ func main() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
var err error
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
defer util.Client.Disconnect(ctx)
|
||||||
//util.InsertRandomData(client)
|
|
||||||
r := GetRouter()
|
r := GetRouter()
|
||||||
|
|
||||||
err = http.ListenAndServe(":3333", r)
|
err = http.ListenAndServe(":3333", r)
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gibb165lb2/router"
|
"gibb165lb2/router"
|
||||||
|
"gibb165lb2/util"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,5 +20,6 @@ func GetRouter() *mux.Router {
|
||||||
r.HandleFunc("/debts", router.GetAllDebts).Methods("GET")
|
r.HandleFunc("/debts", router.GetAllDebts).Methods("GET")
|
||||||
r.HandleFunc("/debts/{id}", router.GetDebt).Methods("GET")
|
r.HandleFunc("/debts/{id}", router.GetDebt).Methods("GET")
|
||||||
r.HandleFunc("/debts/{id}", router.UpdateDebt).Methods("PUT")
|
r.HandleFunc("/debts/{id}", router.UpdateDebt).Methods("PUT")
|
||||||
|
r.HandleFunc("/init", util.Init).Methods("GET")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"time"
|
"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