Author SHA1 Message Date
aziis98 ede84bec24 a very simple theme 2023-03-02 13:25:42 +01:00
aziis98 6e98443bb9 finished project 2023-03-01 18:08:58 +01:00
aziis98 f6575b32b1 first go demo with only /api/status 2023-03-01 18:03:17 +01:00
4 changed files with 167 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>GDG Talk Counter</title>
<link rel="stylesheet" href="/src/style.css">
</head>
<body>
<h1>GDG Counter Website</h1>
+91
View File
@@ -0,0 +1,91 @@
package main
import (
"encoding/json"
"log"
"net/http"
)
func main() {
mux := http.NewServeMux()
setupRoutes(mux)
server := http.Server{
Addr: ":4000",
Handler: mux,
}
log.Printf("Starting server on port 4000...")
log.Fatal(server.ListenAndServe())
}
func setupRoutes(mux *http.ServeMux) {
counter := 0
// API Routes
mux.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode("ok")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
mux.HandleFunc("/api/value", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(counter)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
mux.HandleFunc("/api/increment", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
counter++
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(counter)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
mux.HandleFunc("/api/decrement", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
counter--
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(counter)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
// Static Files
mux.Handle("/", http.FileServer(http.Dir("./dist/")))
}
+72
View File
@@ -0,0 +1,72 @@
*,
*::before,
*::after {
font-family: inherit;
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Open Sans', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
text-align: center;
font-weight: 700;
}
.app {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.5rem;
}
#counter-value {
grid-column: span 2;
place-self: center;
font-weight: 200;
font-size: 32px;
padding: 1rem 0;
}
button {
/* box-shadow: 0 0 4px 0 #00000018, 0 0 32px 0 #00000010; */
border: 1px solid #d4d4d4;
background: linear-gradient(to bottom, #f8f8f8 0%, #f0f0f0 50%, #d8d8d8 100%);
color: #333;
font-size: 15px;
font-weight: 400;
border-radius: 0.5rem;
height: 2rem;
padding: 0 1rem;
cursor: pointer;
transition: all 250ms ease-in-out;
}
button:hover {
/* box-shadow: 0 0 4px 0 #00000018, 0 0 24px 4px #00000018; */
border: 1px solid #d0d0d0;
background: linear-gradient(to bottom, #fdfdfd 0%, #ededed 40%, #ededed 60%, #d0d0d0 100%);
}
button:active {
/* box-shadow: 0 0 4px 0 #00000018, 0 0 24px 4px #00000018; */
border: 1px solid #c8c8c8;
background: linear-gradient(to bottom, #fdfdfd 0%, #e4e4e4 50%, #c8c8c8 100%);
}
+3
View File
@@ -3,5 +3,8 @@ import { defineConfig } from 'vite'
export default defineConfig({
server: {
port: 3000,
proxy: {
'/api': 'http://localhost:4000/',
},
},
})