Skip to content

Commit

Permalink
clean up python shit and get first go server working
Browse files Browse the repository at this point in the history
  • Loading branch information
linomp committed Aug 6, 2024
1 parent 24f08b5 commit b3acd18
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 134 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/build-test.yml

This file was deleted.

12 changes: 4 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
FROM python:3.11
FROM golang:bookworm

WORKDIR /code
WORKDIR /app

COPY ./requirements.txt /code/requirements.txt
RUN pip install --upgrade pip
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./src /app

COPY ./app /code/app

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"]
CMD ["go", "run", "main.go"]
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: '3.8'

services:
http:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- "8001:8001"
restart: always
restart: always
Empty file removed old_app/__init__.py
Empty file.
29 changes: 0 additions & 29 deletions old_app/main.py

This file was deleted.

8 changes: 0 additions & 8 deletions old_app/models/ServerMetrics.py

This file was deleted.

Empty file removed old_app/models/__init__.py
Empty file.
Empty file removed old_app/routers/__init__.py
Empty file.
21 changes: 0 additions & 21 deletions old_app/routers/healthcheck.py

This file was deleted.

Empty file removed old_app/services/__init__.py
Empty file.
16 changes: 0 additions & 16 deletions old_app/services/system.py

This file was deleted.

Empty file removed old_app/tests/__init__.py
Empty file.
19 changes: 0 additions & 19 deletions old_app/tests/test_controllers.py

This file was deleted.

Empty file removed old_app/utils/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"log"
"net/http"
)

type healthcheckHandler struct{}

func (h *healthcheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/plain")

switch {
case r.Method == http.MethodGet:
msg := []byte("hello there")
w.WriteHeader(http.StatusOK)
w.Write(msg)
return
default:
return
}
}

func main() {
mux := http.NewServeMux()
mux.Handle("/", &healthcheckHandler{})

log.Fatal(http.ListenAndServe("0.0.0.0:8001", mux))
}
16 changes: 15 additions & 1 deletion old_app/utils/html.py → src/old_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
from app.models.ServerMetrics import ServerMetrics
class ServerMetrics(BaseModel):
host: str
timestamp: str
cpu_usage: str
memory_usage: str


def get_status(request: Request) -> ServerMetrics:
time = datetime.datetime.now(datetime.timezone.utc).isoformat()

cpu_usage = psutil.cpu_percent()
memory_usage = psutil.virtual_memory().percent

return ServerMetrics(host=request.client.host, timestamp=time, cpu_usage=f"{cpu_usage} %",
memory_usage=f"{memory_usage} %")


def format_timestamp(timestamp):
Expand Down

0 comments on commit b3acd18

Please sign in to comment.