Initial Commit

This commit is contained in:
Jagrit Thapar 2024-09-06 17:35:42 +05:30
parent fe14539e92
commit 237ad4da95
6 changed files with 105 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

9
.idea/go-simple-app.iml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/go-simple-app.iml" filepath="$PROJECT_DIR$/.idea/go-simple-app.iml" />
</modules>
</component>
</project>

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module go-simple-app
go 1.23.0

40
main.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"html/template"
"net/http"
"os"
)
func homePage(w http.ResponseWriter, r *http.Request) {
hostname, err := os.Hostname()
if err != nil {
http.Error(w, "Unable to get hostname", http.StatusInternalServerError)
return
}
tmpl, err := template.ParseFiles("static/home.html")
if err != nil {
http.Error(w, "Unable to parse template", http.StatusInternalServerError)
return
}
data := struct {
Hostname string
}{
Hostname: hostname,
}
err = tmpl.Execute(w, data)
if err != nil {
http.Error(w, "Unable to execute template", http.StatusInternalServerError)
}
}
func main() {
http.HandleFunc("/", homePage)
err := http.ListenAndServe(":8080", nil)
if err != nil {
return
}
}

37
static/home.html Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
text-align: center;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
}
p {
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to My Simple Go Web App!</h1>
<p>This page is served from the hostname: <strong>{{.Hostname}}</strong></p>
</div>
</body>
</html>