diff --git a/.gitignore b/.gitignore index ebe43b9..5c3b10b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,10 @@ go.work.sum # Editor/IDE # .idea/ -# .vscode/ +.vscode/ + +# Hot reload +*.toml +/tmp + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..54c64ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# ------------------------------------------------------ +# 1. Build Stage +# ------------------------------------------------------ +FROM golang:1.25-alpine AS builder + +# Install necessary build tools for SQLite (CGO) +RUN apk add --no-cache gcc musl-dev sqlite-dev + +WORKDIR /app + +# Cache dependencies +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source files +COPY . . + +# Build with CGO enabled for SQLite +RUN CGO_ENABLED=1 GOOS=linux go build -o server main.go + +# ------------------------------------------------------ +# 2. Runtime Stage +# ------------------------------------------------------ +FROM alpine:3.20 + +# Install SQLite (if your app interacts directly with .db file) +RUN apk add --no-cache sqlite + +WORKDIR /app + +# Copy binary and required files +COPY --from=builder /app/server . +COPY --from=builder /app/css ./css +COPY --from=builder /app/views ./views +COPY --from=builder /app/my_website.db ./ + +EXPOSE 8080 + +CMD ["./server"] diff --git a/go.mod b/go.mod index 6598b8f..7e3f7c7 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module duhweb -go 1.24.5 +go 1.25.3 require github.com/go-chi/chi/v5 v5.2.3 -require github.com/mattn/go-sqlite3 v1.14.32 // indirect +require github.com/mattn/go-sqlite3 v1.14.32 diff --git a/internal/api/project_handler.go b/internal/api/project_handler.go index 767cd2a..0dff92e 100644 --- a/internal/api/project_handler.go +++ b/internal/api/project_handler.go @@ -8,7 +8,7 @@ import ( ) type ProjectHandler struct { - Templates *template.Template + Templates *template.Template ProjectStore *store.SQLiteProjectStore } @@ -21,7 +21,7 @@ func (h *ProjectHandler) Render(w http.ResponseWriter, tmpl string, data interfa func NewProjectHandler(db *sql.DB) *ProjectHandler { return &ProjectHandler{ - Templates: template.Must(template.ParseGlob("views/*.html")), + Templates: template.Must(template.ParseGlob("views/*.html")), ProjectStore: store.NewSQLiteProjectStore(db), } } @@ -41,4 +41,4 @@ func (h *ProjectHandler) ProjectsPage(w http.ResponseWriter, r *http.Request) { return } h.Render(w, "projects", projects) -} \ No newline at end of file +} diff --git a/internal/store/database.go b/internal/store/database.go index f463a40..ee83af9 100644 --- a/internal/store/database.go +++ b/internal/store/database.go @@ -8,7 +8,7 @@ import ( ) func Open() (*sql.DB, error) { - db, err := sql.Open("sqlite3", "C:/Users/dilan/Documents/Go/my_website_db.db") + db, err := sql.Open("sqlite3", "./my_website.db") if err != nil { return nil, fmt.Errorf("db open: %w", err) } @@ -19,4 +19,4 @@ func Open() (*sql.DB, error) { fmt.Println("Connected to Database...") return db, nil -} \ No newline at end of file +} diff --git a/my_website.db b/my_website.db new file mode 100644 index 0000000..57a3f81 Binary files /dev/null and b/my_website.db differ diff --git a/views/index.html b/views/index.html index 5baff0d..57182e0 100644 --- a/views/index.html +++ b/views/index.html @@ -1,120 +1,161 @@ {{ block "index" . }} - - - - My CV Website - - - - - + + + + My CV Website + + + + - -
- -
+ + +
+ +
- - - -
- {{ template "about" . }} -
- - - - - - - - + +
{{ template "about" . }}
+ + + + + + -{{ end }} - -{{ block "about" . }} +{{ end }} {{ block "about" . }} -
-

Hi, I'm Your Name

-

- A [Your Role] who loves building [something about what you do]. -

-
- View Projects - Contact Me -
-
+
+

+ Hi, I'm Your Name +

+

+ A [Your Role] who loves building + [something about what you do]. +

+
+ View Projects + Contact Me +
+
- -
-

About Me

-

- I’m a [Your Profession] with experience in [key skills]. I enjoy solving problems, learning new technologies, and building applications that make an impact. - Currently exploring Go, htmx, and modern web tools. -

-
- {{ end }} - -{{ block "projects" . }} -

Projects

- {{ range . }} - {{ template "project" . }} - {{ end}} + +
+

About Me

+

+ I’m a [Your Profession] with experience in [key skills]. I enjoy solving + problems, learning new technologies, and building applications that make an + impact. Currently exploring + Go, + htmx, and modern web tools. +

+
+{{ end }} {{ block "projects" . }} +

Projects

+{{ range . }} {{ template "project" . }} {{ end}} {{ end }} {{ block "project" . +}} +
+ {{ .Title }} - + {{ .Description }} +
{{ end }} - -{{ block "project" . }} -
- {{ .Title }} - {{ .Description }} -
-{{ end }} - - - \ No newline at end of file diff --git a/views/test.html b/views/test.html index 924e5bf..5515c99 100644 --- a/views/test.html +++ b/views/test.html @@ -1,4 +1,4 @@ -{{ block "index" . }} +{{ block "test" . }}