11 Commits

Author SHA1 Message Date
cf8aea5115 Update README.md 2023-03-06 21:34:12 -06:00
c510646c84 Make username text placeholder instead of value 2023-03-06 21:27:05 -06:00
a4366c7395 Add more to .gitignore 2023-03-06 21:23:56 -06:00
073dfafb28 Change log message 2023-03-06 21:10:09 -06:00
3fa5cf46d2 Update experimental crypto library 2023-03-06 21:08:56 -06:00
bd8b015f44 Update README.md 2023-03-06 21:02:41 -06:00
5a1cd77676 Update README.md 2023-03-06 13:10:50 -06:00
012906eee2 Update README.md 2023-03-06 13:00:11 -06:00
2a705483d9 Add README.md 2023-03-06 12:58:58 -06:00
be2c3ae178 Add default theme and apply to pages 2023-03-06 12:44:20 -06:00
f32223f12c Fix static file handling for the embedded filesystem 2023-03-06 12:43:54 -06:00
9 changed files with 198 additions and 26 deletions

22
.gitignore vendored
View File

@ -1,4 +1,26 @@
# GoWeb specific
env.json env.json
logs/ logs/
*.log *.log
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories
vendor/
# Go workspace file
go.work
# IDE files
/.idea /.idea

59
README.md Normal file
View File

@ -0,0 +1,59 @@
# GoWeb 🌐
GoWeb is a simple Go web framework that aims to only use the standard library. The overall file structure and
development flow is inspired by larger frameworks like Laravel. It is partially ready for smaller projects if you are
fine with getting your hands dirty, but I plan on having it ready to go for more serious projects when it hits version
2.0.
<hr>
## Current features 🚀
- Routing/controllers
- Templating
- Simple database migration system
- CSRF protection
- Minimal user login/registration + sessions
- Config file handling
- Entire website compiles into a single binary (~10mb) (excluding env.json)
- Minimal dependencies (just standard library, postgres driver, and experimental package for bcrypt)
<hr>
## When to use 🙂
- You need to build a dynamic web application with persistent data
- You need to build a dynamic website using Go and need a good starting point
- You need to build an API in Go and don't know where to start
- Pretty much any use-case where you would use Laravel, Django, or Flask
## When not to use 🙃
- You need a static website (see [Hugo](https://gohugo.io/))
- You need a simple blog (see [Hugo](https://gohugo.io/))
- You need a simple site for your projects' documentation (see [Hugo](https://gohugo.io/))
## How to use 🤔
1. Clone
2. Run `go get` to install dependencies
3. Copy env_example.json to env.json and fill in the values
4. Run `go run main.go` to start the server
5. Start building your app!
## How to contribute 👨‍💻
- Open an issue on GitHub if you find a bug or have a feature request.
- [Email](mailto:contact@mpatterson.xyz) me a patch if you want to contribute code.
- Please include a good description of what the patch does and why it is needed, also include how you want to be
credited in the commit message.
<hr>
### License and disclaimer 😤
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
- You and you alone are responsible for the security and everything else regarding your application.
- It is not required, but I ask that when you use this project you give me credit by linking to this repository.
- I also ask that when releasing self-hosted or other end-user applications that you release it under
the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license. This too is not required, but I would appreciate it.

2
go.mod
View File

@ -4,5 +4,5 @@ go 1.20
require ( require (
github.com/lib/pq v1.10.7 github.com/lib/pq v1.10.7
golang.org/x/crypto v0.6.0 golang.org/x/crypto v0.7.0
) )

4
go.sum
View File

@ -1,4 +1,4 @@
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=

View File

@ -3,6 +3,7 @@ package routes
import ( import (
"GoWeb/app" "GoWeb/app"
"GoWeb/controllers" "GoWeb/controllers"
"io/fs"
"log" "log"
"net/http" "net/http"
) )
@ -15,8 +16,14 @@ func GetRoutes(app *app.App) {
} }
// Serve static files // Serve static files
http.Handle("/file/", http.FileServer(http.Dir("./static"))) staticFS, err := fs.Sub(app.Res, "static")
log.Println("Serving static files from: ./static") if err != nil {
log.Println(err)
return
}
staticHandler := http.FileServer(http.FS(staticFS))
http.Handle("/static/", http.StripPrefix("/static/", staticHandler))
log.Println("Serving static files from embedded file system /static")
// Pages // Pages
http.HandleFunc("/", getController.ShowHome) http.HandleFunc("/", getController.ShowHome)

75
static/css/style.css Normal file
View File

@ -0,0 +1,75 @@
body {
font-family: Arial, sans-serif;
background-color: lightblue;
color: #333;
margin: 0;
}
.container {
display: flex;
justify-content: center;
align-items: center;
width: 80%;
padding: 20px;
margin: 0 auto;
}
.footer-container {
display: flex;
justify-content: center;
align-items: center;
height: 80px;
background-color: lightblue;
}
footer {
color: #0077be;
font-size: 14px;
}
form label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
form input[type="text"],
form input[type="password"] {
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: none;
margin-bottom: 10px;
width: 100%;
box-sizing: border-box;
}
form input[type="submit"] {
display: inline-block;
padding: 10px 20px;
background-color: #0077be;
color: #fff;
border-radius: 5px;
text-decoration: none;
border: none;
cursor: pointer;
}
form input[type="submit"]:hover {
background-color: #005fa3;
}
h1, h2, h3, h4, h5, h6 {
font-weight: bold;
color: #333;
text-align: center;
}
a {
color: #0077be;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}

View File

@ -3,11 +3,14 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>SiteName - {{ template "pageTitle" }}</title> <title>SiteName - {{ template "pageTitle" }}</title>
<link rel="stylesheet" href="/static/css/style.css">
</head> </head>
<body> <body>
{{ template "content" . }} {{ template "content" . }}
<div class="footer-container">
<footer>
<p>SiteName - Powered by GoWeb!</p>
</footer>
</div>
</body> </body>
<footer>
<p>SiteName - Powered by Go!</p>
</footer>
</html> </html>

View File

@ -1,13 +1,16 @@
{{ define "pageTitle" }}Login{{ end }} {{ define "pageTitle" }}Login{{ end }}
{{ define "content" }} {{ define "content" }}
<form action="/login-handle" method="post"> <h1>Login</h1>
<input name="csrf_token" type="hidden" value="{{ .CsrfToken }}"> <div class="container">
<form action="/login-handle" method="post">
<input name="csrf_token" type="hidden" value="{{ .CsrfToken }}">
<label for="username">Username:</label><br> <label for="username">Username:</label><br>
<input id="username" name="username" type="text" value="John"><br><br> <input id="username" name="username" type="text" placeholder="John"><br><br>
<label for="password">Password:</label><br> <label for="password">Password:</label><br>
<input id="password" name="password" type="password"><br><br> <input id="password" name="password" type="password"><br><br>
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>
</div>
{{ end }} {{ end }}

View File

@ -1,13 +1,16 @@
{{ define "pageTitle" }}Register{{ end }} {{ define "pageTitle" }}Register{{ end }}
{{ define "content" }} {{ define "content" }}
<form action="/register-handle" method="post"> <h1>Register</h1>
<input name="csrf_token" type="hidden" value="{{ .CsrfToken }}"> <div class="container">
<form action="/register-handle" method="post">
<input name="csrf_token" type="hidden" value="{{ .CsrfToken }}">
<label for="username">Username:</label><br> <label for="username">Username:</label><br>
<input id="username" name="username" type="text" value="John"><br><br> <input id="username" name="username" type="text" placeholder="John"><br><br>
<label for="password">Password:</label><br> <label for="password">Password:</label><br>
<input id="password" name="password" type="password"><br><br> <input id="password" name="password" type="password"><br><br>
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>
</div>
{{ end }} {{ end }}