initial commit

This commit is contained in:
hook-lord 2024-12-06 22:57:47 +01:00
commit f193b395f3
5 changed files with 100 additions and 0 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM golang:1.23 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 GOOS=linux go build -o job-api
FROM alpine:3.18
WORKDIR /app
COPY --from=builder /app/job-api .
CMD ["./job-api"]

View File

@ -0,0 +1,31 @@
name: Build and Push Docker Image
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.USER }}
password: ${{ secrets.TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.REGISTRY }}/rannes.dev/sw-jobs-api:latest

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitea.rannes.dev/rannes.dev/sw-jobs-api
go 1.23.3

52
main.go Normal file
View File

@ -0,0 +1,52 @@
package main
import (
"log"
"net/http"
)
const PORT = "8080"
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/thehub", func(w http.ResponseWriter, r *http.Request) {
if !setHeader(w, r){
return
}
http.ServeFile(w, r, "/app/data/thehub.json")
})
mux.HandleFunc("/itjobbank", func(w http.ResponseWriter, r *http.Request) {
if !setHeader(w, r) {
return
}
http.ServeFile(w, r, "/app/data/itjobbank.json")
})
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
return
})
server := &http.Server{
Addr: ":" + PORT,
Handler: mux,
}
log.Printf("Server starting on port %s", PORT)
log.Fatal(server.ListenAndServe())
}
func setHeader(w http.ResponseWriter, r *http.Request) bool {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Content-Type", "application/json")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return false
}
return true
}

3
thehub.json Normal file
View File

@ -0,0 +1,3 @@
{
"message": "skibidi working!"
}