Skip to content

Commit

Permalink
feat: v3.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: Mauran <thomas.mauran@etu.umontpellier.fr>
  • Loading branch information
thomas-mauran committed Jun 18, 2024
1 parent 4044504 commit f3c5695
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 65 deletions.
36 changes: 17 additions & 19 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package main

import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/do3-2023/thomas-kube/dbHelper"
person "github.com/do3-2023/thomas-kube/struct"
"github.com/do3-2023/thomas-kube/utils"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
Expand Down Expand Up @@ -185,25 +183,25 @@ func main() {
// })

// Person POST
r.Post("/person", func(w http.ResponseWriter, r *http.Request) {
var Obj person.Person
err := json.NewDecoder(r.Body).Decode(&Obj)
if err != nil {
log.Println("Error decoding JSON:", err)
utils.Response(w, r, http.StatusInternalServerError, "Internal Server Error")
return
}
// r.Post("/person", func(w http.ResponseWriter, r *http.Request) {
// var Obj person.Person
// err := json.NewDecoder(r.Body).Decode(&Obj)
// if err != nil {
// log.Println("Error decoding JSON:", err)
// utils.Response(w, r, http.StatusInternalServerError, "Internal Server Error")
// return
// }

sqlStatement := `INSERT INTO person (last_name, phone_number, location) VALUES ($1, $2, $3)`
_, errQuery := db.Exec(sqlStatement, Obj.LastName, Obj.PhoneNumber, Obj.Location)
if errQuery != nil {
log.Println("Error executing SQL query:", errQuery)
utils.Response(w, r, http.StatusInternalServerError, "Internal Server Error")
return
}
// sqlStatement := `INSERT INTO person (last_name, phone_number, location) VALUES ($1, $2, $3)`
// _, errQuery := db.Exec(sqlStatement, Obj.LastName, Obj.PhoneNumber, Obj.Location)
// if errQuery != nil {
// log.Println("Error executing SQL query:", errQuery)
// utils.Response(w, r, http.StatusInternalServerError, "Internal Server Error")
// return
// }

utils.Response(w, r, http.StatusCreated, "Posted!")
})
// utils.Response(w, r, http.StatusCreated, "Posted!")
// })

errServ := http.ListenAndServe(":" + APIPort, r)
if errServ != nil {
Expand Down
62 changes: 31 additions & 31 deletions kube/web/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: webapp
name: webapp
namespace: frontend
spec:
replicas: 1
selector:
matchLabels:
app: webapp
strategy: {}
template:
metadata:
labels:
app: webapp
spec:
containers:
- image: ghcr.io/do3-2023/thomas-kube-web:latest
name: thomas-kube-frontend
resources:
limits: {}
requests:
memory: 500Mi
cpu: 250m
initContainers:
- name: init-frontend
image: busybox
command: ['sh', '-c', 'until nc -zv backend-service.backend.svc.cluster.local 80; do echo waiting for API; sleep 2; done;']
status: {}
# apiVersion: apps/v1
# kind: Deployment
# metadata:
# labels:
# app: webapp
# name: webapp
# namespace: frontend
# spec:
# replicas: 1
# selector:
# matchLabels:
# app: webapp
# strategy: {}
# template:
# metadata:
# labels:
# app: webapp
# spec:
# containers:
# - image: ghcr.io/do3-2023/thomas-kube-web:latest
# name: thomas-kube-frontend
# resources:
# limits: {}
# requests:
# memory: 500Mi
# cpu: 250m
# initContainers:
# - name: init-frontend
# image: busybox
# command: ['sh', '-c', 'until nc -zv backend-service.backend.svc.cluster.local 80; do echo waiting for API; sleep 2; done;']
# status: {}
30 changes: 15 additions & 15 deletions kube/web/service.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: webapp
namespace: frontend
# apiVersion: v1
# kind: Service
# metadata:
# name: webapp
# namespace: frontend

spec:
selector:
app: webapp
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
nodePort: 30080
type: NodePort
# spec:
# selector:
# app: webapp
# ports:
# - name: http
# port: 80
# protocol: TCP
# targetPort: 3000
# nodePort: 30080
# type: NodePort

0 comments on commit f3c5695

Please # to comment.