whatcanGOwrong

This commit is contained in:
2024-09-19 21:38:24 -04:00
commit d0ae4d841d
17908 changed files with 4096831 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"fmt"
"net/http"
"os"
"time"
)
// 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)
return
}
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)
}
// Serve the current time as plain text
func serveTime(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, time.Now().Format(time.RFC1123))
}
func main() {
// Serve the HTML file on the root URL
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Serve the current time on the /time endpoint
http.HandleFunc("/time", serveTime)
// Start the server on port 8085
http.ListenAndServe(":8085", nil)
}
Executable
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
module App
go 1.22.7
+17
View File
@@ -0,0 +1,17 @@
<!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>
<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>
</div>
<script src="script.js"></script>
</body>
</html>
+37
View File
@@ -0,0 +1,37 @@
const jokeEl = document.getElementById('joke')
const jokeBtn = document.getElementById('jokeBtn')
jokeBtn.addEventListener('click', generateJoke)
generateJoke()
// USING ASYNC/AWAIT
async function generateJoke() {
const config = {
headers: {
Accept: 'application/json',
},
}
const res = await fetch('https://icanhazdadjoke.com', config)
const data = await res.json()
jokeEl.innerHTML = data.joke
}
// USING .then()
// function generateJoke() {
// const config = {
// headers: {
// Accept: 'application/json',
// },
// }
// fetch('https://icanhazdadjoke.com', config)
// .then((res) => res.json())
// .then((data) => {
// jokeEl.innerHTML = data.joke
// })
// }
+62
View File
@@ -0,0 +1,62 @@
@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;
}
.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;
}
h3 {
margin: 0;
opacity: 0.5;
letter-spacing: 2px;
}
.joke {
font-size: 30px;
letter-spacing: 1px;
line-height: 40px;
margin: 50px auto;
max-width: 600px;
}
.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;
}