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