Skip to content

Commit 7915811

Browse files
devtrondevtron
devtron
authored and
devtron
committed
adding initial commit
0 parents  commit 7915811

11 files changed

+193
-0
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sample-go-app.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
################################# Build Container ###############################
2+
3+
FROM golang:1.16 as builder
4+
5+
# Setup the working directory
6+
WORKDIR /app
7+
8+
# Add source code
9+
ADD . /app/
10+
11+
# Build the source
12+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main app.go
13+
14+
15+
################################# Prod Container #################################
16+
17+
# Use a minimal alpine image
18+
FROM alpine:3.7
19+
20+
# Add ca-certificates in case you need them
21+
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
22+
23+
# Set working directory
24+
WORKDIR /root
25+
26+
# Copy the binary from builder
27+
COPY --from=builder /app/. .
28+
29+
# Run the binary
30+
CMD ["./main"]
31+
32+
33+
34+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# demo-go-app

app.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"html/template"
5+
"log"
6+
"net/http"
7+
"os"
8+
"path/filepath"
9+
)
10+
11+
// func handler(w http.ResponseWriter, r *http.Request) {
12+
// fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
13+
// }
14+
15+
func main() {
16+
fs := http.FileServer(http.Dir("./static"))
17+
http.Handle("/static/", http.StripPrefix("/static/", fs))
18+
19+
http.HandleFunc("/", serveTemplate)
20+
21+
log.Println("Listening on :8080...")
22+
err := http.ListenAndServe(":8080", nil)
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
}
27+
28+
func serveTemplate(w http.ResponseWriter, r *http.Request) {
29+
lp := filepath.Join("templates", "layout.html")
30+
fp := filepath.Join("templates", filepath.Clean(r.URL.Path))
31+
32+
info, err := os.Stat(fp)
33+
if err != nil {
34+
if os.IsNotExist(err) {
35+
http.NotFound(w, r)
36+
return
37+
}
38+
}
39+
40+
// Return a 404 if the request is for a directory
41+
if info.IsDir() {
42+
http.NotFound(w, r)
43+
return
44+
}
45+
46+
tmpl, err := template.ParseFiles(lp, fp)
47+
if err != nil {
48+
// Log the detailed error
49+
log.Println(err.Error())
50+
// Return a generic "Internal Server Error" message
51+
http.Error(w, http.StatusText(500), 500)
52+
return
53+
}
54+
55+
err = tmpl.ExecuteTemplate(w, "layout", nil)
56+
if err != nil {
57+
log.Println(err.Error())
58+
http.Error(w, http.StatusText(500), 500)
59+
}
60+
}

static/css/style.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
body{
2+
background-color:aliceblue;
3+
padding: 2rem;
4+
}
5+
6+
/* DEMO-SPECIFIC STYLES */
7+
.typewriter{
8+
margin-bottom: 20px;
9+
}
10+
.typewriter h1 {
11+
color: #333;
12+
text-align: center;
13+
font-family: monospace;
14+
overflow: hidden; /* Ensures the content is not revealed until the animation */
15+
white-space: nowrap; /* Keeps the content on a single line */
16+
margin: 0 auto; /* Gives that scrolling effect as the typing happens */
17+
letter-spacing: .15em; /* Adjust as needed */
18+
animation:
19+
typing 3.5s steps(30, end),
20+
blink-caret .5s step-end infinite;
21+
}
22+
23+
/* The typing effect */
24+
@keyframes typing {
25+
from { width: 0 }
26+
to { width: 100% }
27+
}
28+
29+
/* The typewriter cursor effect */
30+
@keyframes blink-caret {
31+
from, to { border-color: transparent }
32+
50% { border-color: rgb(0, 218, 255) }
33+
}
34+
35+
img{
36+
display: block;
37+
margin-left: auto;
38+
margin-right: auto;
39+
width: 80%;
40+
}
41+

static/images/hello_world.png

22 KB
Loading

templates/index.html

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{define "title"}}Go Web Template{{end}}
2+
3+
{{define "body"}}
4+
<div class="typewriter">
5+
<h1>Hello World! Welcome to the Go Application!</h1>
6+
</div>
7+
8+
<img src="/static/images/hello_world.png" alt="Hello World">
9+
{{end}}

templates/layout.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{define "layout"}}
2+
<!doctype html>
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>GoWebTemplate</title>
7+
<link rel="stylesheet" href="/static/css/style.css">
8+
</head>
9+
<body>
10+
<div class="typewriter">
11+
<h1>Hello World! Welcome to the Go Application!</h1>
12+
</div>
13+
14+
<img src="/static/images/hello_world.png" alt="Hello World">
15+
</body>
16+
</html>
17+
{{end}}

0 commit comments

Comments
 (0)