Skip to content

Commit 5af04b3

Browse files
committed
Added code for our initial template for frontend and backed services using go for both
1 parent 2d9bf30 commit 5af04b3

File tree

8 files changed

+115
-2
lines changed

8 files changed

+115
-2
lines changed

markdown-note-taking-app/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ To avoid using a framework, we will use HTML, CSS and JS.
3131
- CSS
3232
- JS
3333

34+
35+
36+
## How to run the app
37+
38+
39+
- Backend: `go run main.go`
40+
- Frontend: `task frontend-serve` or use Live Server extension in VSCode
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3'
2+
silent: true
3+
tasks:
4+
hello:
5+
cmds:
6+
- echo "Hello, World!"
7+
frontend-serve-py:
8+
cmds:
9+
- cd frontend && python3 -m http.server 8000
10+
start-all:
11+
cmds:
12+
- go run main.go
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// An example of how to use fetch to create a note
2+
document.addEventListener('DOMContentLoaded', () => {
3+
const createNoteForm = document.getElementById('create-note');
4+
createNoteForm.addEventListener('submit', (e) => {
5+
e.preventDefault();
6+
const title = document.getElementById('title').value;
7+
const content = document.getElementById('content').value;
8+
fetch('http://localhost:8080/notes', {
9+
method: 'POST',
10+
headers: {
11+
'Content-Type': 'application/json',
12+
},
13+
body: JSON.stringify({ title, content }),
14+
})
15+
.then((response) => response.json())
16+
.then((data) => {
17+
console.log(data);
18+
createNoteForm.reset();
19+
})
20+
.catch((error) => console.error('Error creating note:', error));
21+
});
22+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Create note</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<header>
11+
<h1>Create note</h1>
12+
</header>
13+
<main>
14+
<form id="create-note">
15+
<label for="title">Title:</label>
16+
<input type="text" id="title" name="title" required>
17+
<label for="content">Content:</label>
18+
<textarea id="content" name="content" required></textarea>
19+
<button type="submit">Create note</button>
20+
</form>
21+
</main>
22+
<footer>
23+
<p>&copy; 2025 Notes</p>
24+
</footer>
25+
<script src="app.js"></script>
26+
</body>
27+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>List of notes</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<header>
11+
<h1>Notes</h1>
12+
</header>
13+
<main>
14+
<ul id="notes">
15+
<li><a href="create.html">Create note</a></li>
16+
</ul>
17+
</main>
18+
<footer>
19+
<p>&copy; 2025 Notes</p>
20+
</footer>
21+
<script src="app.js"></script>
22+
</body>
23+
</html>

markdown-note-taking-app/frontend/note.html

Whitespace-only changes.

markdown-note-taking-app/frontend/styles.css

Whitespace-only changes.

markdown-note-taking-app/main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
)
8+
9+
10+
func apiHandler(w http.ResponseWriter, r *http.Request) {
11+
fmt.Fprint(w, "Hello, World!")
12+
}
13+
14+
func startFrontendServer() {
15+
fs := http.FileServer(http.Dir("frontend"))
16+
http.Handle("/", fs)
17+
log.Fatal(http.ListenAndServe(":80", nil))
18+
}
19+
20+
func startBackendServer() {
21+
http.HandleFunc("/api", apiHandler)
22+
log.Fatal(http.ListenAndServe(":8080", nil))
23+
24+
}
425

526
func main() {
6-
fmt.Println("Hello World")
27+
go startFrontendServer()
28+
startBackendServer()
729
}

0 commit comments

Comments
 (0)