-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
551ae82
commit 15fb00e
Showing
6 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.8.5-jessie | ||
|
||
RUN mkdir /go-app | ||
|
||
# create a working directory | ||
WORKDIR /go-app | ||
|
||
# add source code | ||
ADD . /go-app | ||
|
||
# run main.go | ||
CMD ["go", "run", "app.go"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"html/template" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// func handler(w http.ResponseWriter, r *http.Request) { | ||
// fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) | ||
// } | ||
|
||
func main() { | ||
fs := http.FileServer(http.Dir("./static")) | ||
http.Handle("/static/", http.StripPrefix("/static/", fs)) | ||
|
||
http.HandleFunc("/", serveTemplate) | ||
|
||
log.Println("Listening on :8080...") | ||
err := http.ListenAndServe(":8080", nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func serveTemplate(w http.ResponseWriter, r *http.Request) { | ||
lp := filepath.Join("templates", "layout.html") | ||
fp := filepath.Join("templates", filepath.Clean(r.URL.Path)) | ||
|
||
info, err := os.Stat(fp) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
http.NotFound(w, r) | ||
return | ||
} | ||
} | ||
|
||
// Return a 404 if the request is for a directory | ||
if info.IsDir() { | ||
http.NotFound(w, r) | ||
return | ||
} | ||
|
||
tmpl, err := template.ParseFiles(lp, fp) | ||
if err != nil { | ||
// Log the detailed error | ||
log.Println(err.Error()) | ||
// Return a generic "Internal Server Error" message | ||
http.Error(w, http.StatusText(500), 500) | ||
return | ||
} | ||
|
||
err = tmpl.ExecuteTemplate(w, "layout", nil) | ||
if err != nil { | ||
log.Println(err.Error()) | ||
http.Error(w, http.StatusText(500), 500) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
body{ | ||
background-color:aliceblue; | ||
padding: 2rem; | ||
} | ||
|
||
/* DEMO-SPECIFIC STYLES */ | ||
.typewriter{ | ||
margin-bottom: 20px; | ||
} | ||
.typewriter h1 { | ||
color: #333; | ||
text-align: center; | ||
font-family: monospace; | ||
overflow: hidden; /* Ensures the content is not revealed until the animation */ | ||
white-space: nowrap; /* Keeps the content on a single line */ | ||
margin: 0 auto; /* Gives that scrolling effect as the typing happens */ | ||
letter-spacing: .15em; /* Adjust as needed */ | ||
animation: | ||
typing 3.5s steps(30, end), | ||
blink-caret .5s step-end infinite; | ||
} | ||
|
||
/* The typing effect */ | ||
@keyframes typing { | ||
from { width: 0 } | ||
to { width: 100% } | ||
} | ||
|
||
/* The typewriter cursor effect */ | ||
@keyframes blink-caret { | ||
from, to { border-color: transparent } | ||
50% { border-color: rgb(0, 217, 255) } | ||
} | ||
|
||
img{ | ||
display: block; | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 80%; | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{define "title"}}Go Web Template{{end}} | ||
|
||
{{define "body"}} | ||
<div class="typewriter"> | ||
<h1>Hello World! Welcome to the Go Application!</h1> | ||
</div> | ||
|
||
<img src="/static/images/hello_world.png" alt="Hello World"> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{define "layout"}} | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>GoWebTemplate</title> | ||
<link rel="stylesheet" href="/static/css/style.css"> | ||
</head> | ||
<body> | ||
<div class="typewriter"> | ||
<h1>Hello World! Welcome to the Go Application!</h1> | ||
</div> | ||
|
||
<img src="/static/images/hello_world.png" alt="Hello World"> | ||
</body> | ||
</html> | ||
{{end}} |