Skip to content

Commit 95b6b87

Browse files
Added some pages, added routes, added handlers. Added some basic css.
1 parent a826140 commit 95b6b87

File tree

15 files changed

+281
-8
lines changed

15 files changed

+281
-8
lines changed

controllers/auth.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func LoginHandler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "<h1>Blast Beats and Code :: Login</h1>"+
10+
"<p>The strange endeavors of a nerdy developer who also likes really bad music.</p>")
11+
}

controllers/blog.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func BlogHandler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "<h1>Blast Beats and Code :: Blog</h1>"+
10+
"<p>The strange endeavors of a nerdy developer who also likes really bad music.</p>")
11+
}

controllers/contact.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func ContactHandler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "<h1>Blast Beats and Code :: Contact</h1>"+
10+
"<p>The strange endeavors of a nerdy developer who also likes really bad music.</p>")
11+
}

controllers/home.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import (
4+
"html/template"
5+
"net/http"
6+
)
7+
8+
func HomeHandler(w http.ResponseWriter, r *http.Request) {
9+
tmpl := template.Must(template.ParseFiles("templates/index.gohtml"))
10+
tmpl.Execute(w, nil)
11+
}

controllers/projects.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package controllers
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
func ProjectsHandler(w http.ResponseWriter, r *http.Request) {
9+
fmt.Fprintf(w, "<h1>Blast Beats and Code :: Projects</h1>"+
10+
"<p>The strange endeavors of a nerdy developer who also likes really bad music.</p>")
11+
}

main.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ import (
44
"fmt"
55
"log"
66
"net/http"
7-
)
7+
"time"
88

9-
func handler(w http.ResponseWriter, r *http.Request) {
10-
fmt.Fprintf(w, "<h1>Blast Beats and Code</h1>"+
11-
"<p>The strange endeavors of a nerdy computer scientist who also likes really bad music.</p>")
12-
}
9+
"github.com/blastbeatsandcode/blastbeatsandcode-website/routes"
10+
)
1311

1412
func main() {
1513

1614
// Register and handle home
17-
http.HandleFunc("/", handler)
15+
r := routes.Routes()
16+
1817
fmt.Println("Starting Server...")
1918

20-
// Serve Project
21-
log.Fatal(http.ListenAndServe(":80", nil))
19+
// Connect to database and serve project
20+
srv := &http.Server{
21+
Handler: r,
22+
Addr: ":8080",
23+
WriteTimeout: 60 * time.Second,
24+
ReadTimeout: 60 * time.Second,
25+
}
26+
log.Fatal(srv.ListenAndServe())
2227
}

models/models.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package models

public/css/base.css

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Custom CSS */
2+
3+
a {
4+
color: rgb(166, 126, 13);
5+
}
6+
7+
a:hover {
8+
text-decoration: none;
9+
color: rgb(105, 101, 37);
10+
}
11+
12+
.banner {
13+
background-color: rgb(168, 187, 185);
14+
padding-top: 15px;
15+
padding-bottom: 15px;
16+
}
17+
18+
19+
.banner h1, h1 a, h1 a:hover {
20+
font-family: 'Abel', serif;
21+
color: black;
22+
}
23+
24+
body {
25+
font-family: 'Arvo', serif;
26+
}
27+
28+
.jumbotron {
29+
background-color: slategray;
30+
}
31+
32+
footer {
33+
background-color: #272727;
34+
text-align: center;
35+
padding: 25px;
36+
color: gray;
37+
}
38+
39+
footer a {
40+
color: white;
41+
}
42+
43+
h1, h2, h3 {
44+
font-family: 'Abel', serif;
45+
}
46+
47+
nav {
48+
background-color: rgb(44, 93, 97);
49+
padding: 25px;
50+
}
51+
52+
.social, .social h2 {
53+
width: 100%;
54+
text-align: center;
55+
}
56+
57+
.social i {
58+
padding: 5rem;
59+
}
60+
61+
.social a {
62+
color: black;
63+
}
64+
65+
.social a:hover {
66+
color: inherit;
67+
}

routes/routes.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package routes
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
7+
"github.com/blastbeatsandcode/blastbeatsandcode-website/controllers"
8+
"github.com/gorilla/mux"
9+
)
10+
11+
/* Routes returns the registered routes and handlers. */
12+
func Routes() *mux.Router {
13+
// Create the new router
14+
r := mux.NewRouter().StrictSlash(false)
15+
16+
// Create the subrouters and register controllers
17+
// We also will serve the public folders such as images, js, and css to each route
18+
19+
// Register the Not Found catchall
20+
r.NotFoundHandler = http.HandlerFunc(notFound)
21+
22+
// Register Home
23+
r.HandleFunc("/", controllers.HomeHandler)
24+
r.PathPrefix("/public/css/").Handler(http.StripPrefix("/public/css/", http.FileServer(http.Dir("./public/css/"))))
25+
r.PathPrefix("/public/js/").Handler(http.StripPrefix("/public/js/", http.FileServer(http.Dir("./public/js/"))))
26+
r.PathPrefix("/public/img/").Handler(http.StripPrefix("/public/img/", http.FileServer(http.Dir("./public/img/"))))
27+
28+
// Register Blog
29+
blogRoute := r.PathPrefix("/blog").Subrouter()
30+
blogRoute.HandleFunc("", controllers.BlogHandler)
31+
blogRoute.PathPrefix("/public/css/").Handler(http.StripPrefix("/public/css/", http.FileServer(http.Dir("./public/css/"))))
32+
blogRoute.PathPrefix("/public/img/").Handler(http.StripPrefix("/public/img/", http.FileServer(http.Dir("./public/img/"))))
33+
blogRoute.PathPrefix("/public/js/").Handler(http.StripPrefix("/public/js/", http.FileServer(http.Dir("./public/js/"))))
34+
35+
// Register Projects
36+
projectRoute := r.PathPrefix("/projects").Subrouter()
37+
projectRoute.HandleFunc("", controllers.ProjectsHandler)
38+
projectRoute.PathPrefix("/public/css/").Handler(http.StripPrefix("/public/css/", http.FileServer(http.Dir("./public/css/"))))
39+
projectRoute.PathPrefix("/public/img/").Handler(http.StripPrefix("/public/img/", http.FileServer(http.Dir("./public/img/"))))
40+
projectRoute.PathPrefix("/public/js/").Handler(http.StripPrefix("/public/js/", http.FileServer(http.Dir("./public/js/"))))
41+
42+
// Register Contact
43+
contactRoute := r.PathPrefix("/contact").Subrouter()
44+
contactRoute.HandleFunc("", controllers.ContactHandler)
45+
contactRoute.PathPrefix("/public/css/").Handler(http.StripPrefix("/public/css/", http.FileServer(http.Dir("./public/css/"))))
46+
contactRoute.PathPrefix("/public/img/").Handler(http.StripPrefix("/public/img/", http.FileServer(http.Dir("./public/img/"))))
47+
contactRoute.PathPrefix("/public/js/").Handler(http.StripPrefix("/public/js/", http.FileServer(http.Dir("./public/js/"))))
48+
49+
// Register Login
50+
loginRoute := r.PathPrefix("/login").Subrouter()
51+
loginRoute.HandleFunc("", controllers.LoginHandler)
52+
loginRoute.PathPrefix("/public/css/").Handler(http.StripPrefix("/public/css/", http.FileServer(http.Dir("./public/css/"))))
53+
loginRoute.PathPrefix("/public/img/").Handler(http.StripPrefix("/public/img/", http.FileServer(http.Dir("./public/img/"))))
54+
loginRoute.PathPrefix("/public/js/").Handler(http.StripPrefix("/public/js/", http.FileServer(http.Dir("./public/js/"))))
55+
56+
return r
57+
}
58+
59+
/* notFound is the catchall handler for the gorilla router */
60+
// TODO: create not found template and struct
61+
func notFound(w http.ResponseWriter, r *http.Request) {
62+
fmt.Fprintf(w, "<h1>Something broke!</h1>"+
63+
"<p>It looks like the page you were looking for has moved or never existed in the first place. :(</p>")
64+
}

templates/base.gohtml

Whitespace-only changes.

templates/blog.gohtml

Whitespace-only changes.

templates/contact.gohtml

Whitespace-only changes.

templates/index.gohtml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Blast Beats and Code - Developer Blog</title>
5+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
7+
<link rel="stylesheet" type="text/css" href="/public/css/base.css">
8+
<link href="https://fonts.googleapis.com/css?family=Abel|Arvo" rel="stylesheet">
9+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
10+
</head>
11+
<body>
12+
13+
<div class="banner">
14+
<div class="container">
15+
<a href="/">
16+
<h1>Blast Beats and Code // Home</h1>
17+
</a>
18+
19+
<p>The strange endeavors of a nerdy developer who also likes really bad music.</p>
20+
</div>
21+
</div>
22+
23+
<nav class="navbar navbar-expand-lg navbar-light">
24+
<div class="container">
25+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
26+
<span class="navbar-toggler-icon"></span>
27+
</button>
28+
29+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
30+
<ul class="navbar-nav mr-auto">
31+
<li class="nav-item">
32+
<a class="nav-link" href="#">Home</a>
33+
</li>
34+
<li class="nav-item">
35+
<a class="nav-link" href="#">Blog</a>
36+
</li>
37+
<li class="nav-item dropdown">
38+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
39+
Projects
40+
</a>
41+
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
42+
<a class="dropdown-item" href="#">Action</a>
43+
<a class="dropdown-item" href="#">Another action</a>
44+
<div class="dropdown-divider"></div>
45+
<a class="dropdown-item" href="#">Something else here</a>
46+
</div>
47+
</li>
48+
<li class="nav-item">
49+
<a class="nav-link" href="#">Contact</a>
50+
</li>
51+
</ul>
52+
<form class="form-inline my-2 my-lg-0">
53+
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
54+
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
55+
</form>
56+
</div>
57+
</div>
58+
</nav>
59+
60+
<content>
61+
<div class="container">
62+
<h2>Connect</h2>
63+
<p class="social">
64+
<a href="https://github.com/blastbeatsandcode" target="_blank"><i class="fab fa-github fa-7x"></i></a>
65+
<a href="https://twitter.com/blastbeatsncode" target="_blank"><i class="fab fa-twitter fa-7x"></i></a>
66+
<a href="https://www.discogs.com/user/blastbeatsandcode" target="_blank"><i class="fas fa-compact-disc fa-7x"></i></a>
67+
<a href="#"><i class="fab fa-steam fa-7x"></i></a>
68+
</p>
69+
</div>
70+
</content>
71+
72+
<footer>
73+
<div class="container">
74+
<p>This website is a work in progress. See the source code as I update it <a href="https://github.com/blastbeatsandcode/blastbeatsandcode-website">here</a>.</p>
75+
<p>Copyright &copy; 2018 Blast Beats and Code</p>
76+
</div>
77+
</footer>
78+
79+
80+
</body>
81+
</html>

templates/login.gohtml

Whitespace-only changes.

templates/projects.gohtml

Whitespace-only changes.

0 commit comments

Comments
 (0)