whatcanGOwrongagain
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
// Serve the index.html file
|
// Serve the index.html file
|
||||||
func serveHTML(w http.ResponseWriter, r *http.Request) {
|
func serveHTML(w http.ResponseWriter, r *http.Request) {
|
||||||
// Open the file
|
|
||||||
file, err := os.Open("index.html")
|
file, err := os.Open("index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "File not found", http.StatusNotFound)
|
http.Error(w, "File not found", http.StatusNotFound)
|
||||||
@@ -17,7 +16,6 @@ func serveHTML(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// Set the content type as HTML and send the file contents
|
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
http.ServeContent(w, r, "index.html", time.Now(), file)
|
http.ServeContent(w, r, "index.html", time.Now(), file)
|
||||||
}
|
}
|
||||||
@@ -28,12 +26,12 @@ func serveTime(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Serve the HTML file on the root URL
|
// Serve the static CSS file from the "static" directory
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
||||||
|
|
||||||
// Serve the current time on the /time endpoint
|
http.HandleFunc("/", serveHTML)
|
||||||
http.HandleFunc("/time", serveTime)
|
http.HandleFunc("/time", serveTime)
|
||||||
|
|
||||||
// Start the server on port 8085
|
fmt.Println("Starting server on :8085")
|
||||||
http.ListenAndServe(":8085", nil)
|
http.ListenAndServe(":8085", nil)
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-12
@@ -1,17 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<link rel="stylesheet" href="/home/ilyes/LearnGO/firstApp/style.css" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Dad Jokes</title>
|
<title>Go Server Hello</title>
|
||||||
</head>
|
|
||||||
<body>
|
<!-- Link to the external CSS file -->
|
||||||
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h3>Don't Laugh Challenge</h3>
|
<h1>Hello from Go Server</h1>
|
||||||
<div id="joke" class="joke">// Joke goes here</div>
|
<p>The current time is: <span id="time"></span></p>
|
||||||
<button id="jokeBtn" class="btn">Get Another Joke</button>
|
|
||||||
</div>
|
</div>
|
||||||
<script src="script.js"></script>
|
|
||||||
</body>
|
<script>
|
||||||
|
// Fetch current time from the /time endpoint
|
||||||
|
fetch('/time')
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(time => {
|
||||||
|
document.getElementById('time').textContent = time;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
+24
-50
@@ -1,62 +1,36 @@
|
|||||||
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: #686de0;
|
font-family: Arial, sans-serif;
|
||||||
font-family: 'Roboto', sans-serif;
|
background-color: #f4f4f9;
|
||||||
display: flex;
|
margin: 0;
|
||||||
flex-direction: column;
|
padding: 0;
|
||||||
align-items: center;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 100vh;
|
align-items: center;
|
||||||
overflow: hidden;
|
height: 100vh;
|
||||||
margin: 0;
|
color: #333;
|
||||||
padding: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
background-color: #fff;
|
text-align: center;
|
||||||
border-radius: 10px;
|
background-color: white;
|
||||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1), 0 6px 6px rgba(0, 0, 0, 0.1);
|
padding: 30px;
|
||||||
padding: 50px 20px;
|
border-radius: 10px;
|
||||||
text-align: center;
|
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
max-width: 100%;
|
|
||||||
width: 800px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
h1 {
|
||||||
margin: 0;
|
font-size: 2.5rem;
|
||||||
opacity: 0.5;
|
color: #4CAF50;
|
||||||
letter-spacing: 2px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.joke {
|
p {
|
||||||
font-size: 30px;
|
font-size: 1.2rem;
|
||||||
letter-spacing: 1px;
|
color: #555;
|
||||||
line-height: 40px;
|
|
||||||
margin: 50px auto;
|
|
||||||
max-width: 600px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
#time {
|
||||||
background-color: #9f68e0;
|
font-weight: bold;
|
||||||
color: #fff;
|
color: #FF5722;
|
||||||
border: 0;
|
|
||||||
border-radius: 10px;
|
|
||||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1), 0 6px 6px rgba(0, 0, 0, 0.1);
|
|
||||||
padding: 14px 40px;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn:active {
|
|
||||||
transform: scale(0.98);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn:focus {
|
|
||||||
outline: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user