added htmx, picocss postgres

This commit is contained in:
2025-03-12 16:01:07 +03:00
parent f8472a0308
commit 74af30ef57
8 changed files with 151 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
# Dockerfile
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Copy go.mod and go.sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy the source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o url-shortener .
# Use a smaller image for the final build
FROM alpine:latest
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /app/url-shortener .
# Copy templates and static files
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/static ./static
# Expose the port
EXPOSE 8080
# Run the binary
CMD ["./url-shortener"]
+13
View File
@@ -0,0 +1,13 @@
CREATE DATABASE urlshortener;
\c urlshortener
CREATE TABLE IF NOT EXISTS urls(
id SERIAL PRIMARY KEY,
original_url TEXT NOT NULL,
short_code VARCHAR(10) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
visits INTEGER DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_short_code ON urls(short_code)
+34
View File
@@ -0,0 +1,34 @@
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
depends_on:
- db
environment:
- DB_HOST=db
- DB_PORT=5432
- DB_USER=postgres
- DB_PASSWORD=postgres
- DB_NAME=urlshortener
restart: always
db:
image: postgres:17
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=urlshortener
ports:
- "5432:5432"
restart: always
volumes:
postgres_data:
+6 -1
View File
@@ -1,3 +1,8 @@
module github.com/andwati/url-shortener
go 1.22.4
go 1.24.0
require (
github.com/gorilla/mux v1.8.1 // indirect
github.com/lib/pq v1.10.9 // indirect
)
+4
View File
@@ -0,0 +1,4 @@
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
+1
View File
File diff suppressed because one or more lines are too long
+4
View File
File diff suppressed because one or more lines are too long
+55
View File
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="pico.min.css">
<script src="htmx.min.js"></script>
<title>URL shortener</title>
</head>
<body>
<main class="container-fluid">
<nav>
<ul><li><strong>Link shortener</strong></li></ul>
<ul>
<li>
<details class="dropdown">
<summary>
Account
</summary>
<ul dir="rtl">
<li><a href="">Profile</a></li>
<li><a href="">Settings</a></li>
<li><a href="">Security</a></li>
<li><a href="">Logout</a></li>
</ul>
</details>
</li>
</ul>
</nav>
<section class="container">
<form action="">
<fieldset role="group">
<input type="text" name="" id="">
<button type="submit">Shorten</button>
</fieldset>
</form>
<div>
<input type="text">
<button>copy</button>
</div>
</section>
</main>
<footer class="container-fluid">
<small>footer</small>
</footer>
</body>
</html>