This project is a template for gonew and is used for setting up a webserver using echo framework.
- Go never changes
- It is a nice way to start out a webserver without doing much
- It is in pure Go so faster build times and since Go never changes it will always compile.
- No need for npm with assets because it concatenates and optimizes them (with min command)
- Provides code for bare basic security
- Allows for sending emails
- Database setup (sqlite)
- Has middleware support
- Is scaffolding for apis, crud, security
- Made a video on it here
Project is created with:
- modernc.org/sqlite - database
- viper - build cli commands
- echo - web framework to shorten code
- sprig - template functions
- imagecompression - image compression
- minify - assets optimization
- gomail - email accessibility
- jwt - JWT authentication
- validator - Validation
- GOW - for live reloading
- Bootstrap - Bootstrap
- jQuery - jQeury
- Materialize - Materialize
- go 1.21 for gonew
Just use the new gonew
go install golang.org/x/tools/cmd/gonew@latest
gonew github.com/golangast/goservershell example.com/myserver
go mod vendor
REMEMBER TO RUN 'go mod tidy' and 'go mod vendor' after to pull down dependencies
//to run the program
go run . st
//to optimize assets. It optimizes whats in assets/build and then adds them to assets/optimized
go run . min
If you are familiar with https://github.com/bokwoon95/wgo then you can use the following to have live reloading. -xdir means dont watch that dir -dir means watch that directory -verbose means print out the watching directory
wgo run -file .html -xdir vendor -xdir internal -xdir src -dir assets/templates -verbose main.go st
REMEMBER! that your assets like js/css are in the assets/build folder and they are linked in the html from the assets/optimized folder. You can always change this in the ./optimize config folder if you want. But the reloading will not pull new assets by default because it expects you to build them first so that they are linked all in one file.
├── cmd
├── internal (services)[just a simple database example]
│ ├── dbsql
│ │ ├── dbconn (holds the database.db)
│ │ └── user
│ ├── email (to send codes)
│ └── security (left to the user to configure)
│ ├── cookies
│ ├── crypt
│ ├── jwt
│ ├── tokens
│ └── validate
├── optimize (to optimize assets and !remember to set assets paths here)[funcs for cantenating and minifying assets and images]
├── src (app)[meat and bones of the application]
│ ├── funcmaps (functation for templates)
│ ├── handler
│ ├── get
│ │ ├── home (form to start)
│ │ └── loginemail (logging in with email)
│ └── post
│ └── createuser (post request to create a user)
│ ├── routes
│ └── server
-
- That this is a work in progress so things may not be 100% correct.
-
- That the asset path to the html by default are linked to assets/optimized folder
-
- That the js/css optimizations are not making function names single letter and do not like comments and may not like imports. (work around might be copy past from cdn).
-
- That templates folder is in assets folder
-
- That you do need to configure the email with your credentials so that it actually works with the form.
-
- That this is just for learning and testing and of course needs to be refined on your end.
-
- That you still need to bring along templates and assets for the binary because I didnt want to have to build it every live reload.
-
- So yes, there is a lot that needs to be done before you just make a it a binary.