melkeydev / go-blueprint Goto Github PK
View Code? Open in Web Editor NEWGo-blueprint allows users to spin up a quick Go project using a popular framework
Home Page: https://docs.go-blueprint.dev/
License: MIT License
Go-blueprint allows users to spin up a quick Go project using a popular framework
Home Page: https://docs.go-blueprint.dev/
License: MIT License
Could be useful to be able to use own templates for projects or files.
Can we squash all the previous commits on the main branch?
adding github templates for issues and PRs to make issues and PRs easy to breeze through
After completing the last step of the interactive CLI, the user should be able to easily copy and paste the equivalent shorter non-interactive go-blueprint command with the proper flags and program arguments set.
For example, after the user selects Gin in the interactive UI, the output at the end could be something like this:
Tip: Repeat the equivalent Blueprint with the following non-interactive command
go-blueprint create --name my-project --framework gin
Currently, this is not terribly useful, BUT as we add more steps it could save a lot of time.
Add builds for darwin architectures and windows.
Consider to use Goreleaser.
As go-blueprint adds more features and expands into DB layers, I am going to make the decision to not include an ORM.
The reason being:
create
cobra command. See https://nayaktapan37.medium.com/testing-cobra-commands-in-golang-ca1fe4ad6657 for an example.go test
to GitHub Actions suite.Setting up a database and connecting to it in Go projects is a trivial task most of the time, but, similar to creating an HTTP server, it becomes repetitive. My proposal is to introduce an opt-in database setup.
Would a ping pong web socket endpoint example add a lot of value? The way I imagine it, it would add a dependency to the generated project, this dependency does get linked to by the docs.
I think gorilla has their own websocket implementation but I haven't worked with that one yet.
naive example implementation
handler(w http.ResponseWriter, req *http.Request) {
socket, _ := websocket.Accept(w, req, nil)
ctx := req.Context()
for {
_, socketBytes, _ := socket.Read(ctx)
if string(socketBytes) == "PING" {
_ = socket.Write(ctx, websocket.MessageText, "PONG")
} else {
_ = socket.Write(ctx, websocket.MessageText, "HUH?")
}
}
}
We should add https://github.com/cosmtrek/air
to the app so that we get hot reloading
It would be nice to have the option to start a project with echo as well. I could give it a try if you don't mind.
Add support for opinionated HTTP framework gofr (https://github.com/gofr-dev/gofr) which has out of the box support for lot of features required to build a production grade microservice.
I could be wrong on this one but I would think the default next action for someone after creating a new project would be to cd into it. It could improve the user experience to do this for them.
For those times when the user doesn't need to cd into the project straight away a new flag could be added to stop the changing of the directory.
For example: go-blueprint create --name new-project --no-cd
or something more fitting.
Right now if someone creates a new issue there is no template for it even though we have a file in the .github
Currently if you append a space to the end of the project name go-blueprint
can't cd into the directory. I think a space at the end of a name is always a mistake since it will always create a weird name that has to be escaped in the terminal.
It would be nice if go-blueprint
would strip this white space automatically so the dir gets generated properly.
This is a proposal to move the template strings from the template directory to separate files outside of the execution code, especially for the full files.
We can use the go embed functionality to ship them with the binaries and make the templates be easier to view, manage and format independently of the execution code.
For naming proposal we could have the files be named with the generated file name and with a .tmpl
extension at the end, something like main.go.tmpl
.
As the project grows and adds new files and functionality it will become increasingly difficult to manage the template strings directly as multi line strings in the go files.
Example:
Directory proposal
package main
import (
"{{.ProjectName}}/internal/server"
)
func main() {
server := server.NewServer()
err := server.ListenAndServe()
if err != nil {
panic("cannot start server")
}
}
main.go.tmpl
contents
// Package template provides utility functions that
// help with the templating of created files.
package template
import (
_"embed"
)
//go:embed resources/main/main.go.tmpl
var mainTemplate []byte
// MakeHTTPRoutes returns a byte slice that represents
// the default cmd/api/main.go file template.
func MainTemplate() []byte {
return mainTemplate
}
Changes in the
main.go
file in templates.
This will be doubly helpful for the README.md
and '.air.toml` files, as they will simply be the files.
We could also use the resources
(or whatever else we decide to call it) as a mirror of what we want the final project to look like and use the embed.FS
to walk the files.
While writing CLI tools with Cobra and Viper is pretty easy, it would great if this supported setting up that boilerplate and stuff. I'd be happy to work on that contribution, but I wanted to put an issue first to gauge interest. Lmk what you think! :)
Btw great work on this dude, this is sick!
It would be nice if the completion
command would also generate completion for the --framework
flag. It will help with feature discovery for new users.
when go-blueprint version is written the output is just Go Blueprint CLI version
instead of printing the proper output Go Blueprint CLI version 0.3.0
The application currently creates a new project directory and files based on the provided project name, even if a directory with the same name already exists. This behavior is problematic as it could lead to unintended overwriting of existing project data. The application should instead abort creation when a project with the same name already exists.
Run go-blueprint create
in a directory with a sub directory called the same as the name of the project.
When attempting to create a project with a name matching an existing project, the application should provide an error message and abort the creation process to avoid overwriting the existing project.
It would be super interesting to see if we can include a gRPC implementation.
If someone does this, I want to use Twirp package.
Bash command to auto populate docker-compose.yml or .env DB connection values in both directions.
First to run automatically on project setup.
Second use it in console with flags to specify in which direction to copy the values to.
This is related to MohammadAlhallaq:adding-database-support
Homebrew keeps breaking and we can just delete it
bruh
etc
look at GHA and all the broken homebrew builds
Melkey does not like this
To make it easier to generate different types of go projects, CLI, HTTP servers, and TCP/UDP servers.
Each framework should have its templates instead of sharing files.
This will increase the duplication of common files like README, .gitignore, and .air.toml.
But, it will increase the flexibility of the different types of frameworks that can be supported.
Maybe a structure like this Where each framework exposes its own embed.FS
.
The contents of cmd/template/chi/fs.go are the following.
package chi
import "embed"
//go:embed internal cmd all:*.tmpl
var FS embed.FS
I have a concept of this working.
Let me know if you are interested.
When using the make watch
command I get the response air is not installed. Do you want to install it now? (y/n)
Even though air is installed and is in my $GOPATH/bin
.
Machine type: darwin amd64 (206 macbook pro)
With my environment laid out as it is this command should run air the way it does when I use the air
command
Add a contributions file for everyone to append their name to list of contributors
When selecting the framework, moving up and down the list, then selecting with space marks that framework with a check. But if I move up or down from that framework, without marking any other framework with space, the framework that is focused (not checked) will be used when pressing 'y' to continue.
I am working on a function that can add similar features like Laravel Artisan for models, views, and controllers. I would also like to add authentication, but I need to determine the best approach. I am considering using JWT, OAuth2, or both. I am not sure if this will be something that people would find interesting, but I am making it for Gofiber because that is what I need. For now, I plan to generate the entire CRUD with HTMX for views, but there may be more options in the future.
Potential Ideas:
testify
for a better test assertion experience https://github.com/stretchr/testifySince we are adding .env.example we no longer need a .env file and additionally we should include this as one of the files to ignore
if we add go releaser:
https://goreleaser.com/quick-start/
We can remove some of the existing GHA flows that we have!
As we are adding DB opt-in support I thought (in this convo #22 (review)) that we can add a docker-compose file that can easily spin up a DB.
Users will literally have a working DB OOB
When I first used the tool, I found that the README referenced pq instead of the current postgres driver it installs when you select postgres, which is pgx. This is a minor change that led me to believe that the driver installed would be pq.
all
x86
Look at the README and click the postgres link.
No response
Instead of opening the TUI, could we add full on CLI support?
In just one command just make a new project:
go-blueprint --name name --framework Chi
Getting a bit meta with a template of a template, but as this project grows and new options get added like #11 it could be good to add ability to save a template of the project using the options selected.
Currently it's only name and framework but I saw there is an open issue (#11) for adding db setup too. If the db setup issue gets added then having a re-usable thing with only the name needing to be suppled would be useful.
example usage could be something like:
go-blueprint create --name test-project --framework gin --save-template new-template
or selected at the end if using the interactive version.
Then something like this to use the template
go-blueprint create --template new-template --name not-another-test-project
We should include a read me that explains the commands from the Makefile
If you have all of your projects in a specific directory, rather than needing to run the command in that directory, it could be useful to be able to run the command from anywhere and the project be created in your base/root project directory.
For example I could be in ~/some/random/path
and by running go-blueprint create --name new-project
would create the project in ~/dev/new-project
I used the project to build an HTMX server using Templ. Would we want there to be an option in the cli to setup? I know the project is meant to be minimalistic, so I wasn't going to add it unless people think it is a good idea.
My thought is that opting into this would add another folder for web ui stuff with a basic route to get the project started.
Let me know your thoughts.
When running make watch
after successfully installing air
, the Makefile still prompts "air is not installed. Do you want to install it now? (y/n)". This happens even though air
has been installed and is available in the PATH.
It seems like the GOPATH has been deprecated in Go 1.16 and should not be relied on.
Here is the watch
target in the Makefile:
watch:
@if [ -x "$(GOPATH)/bin/air" ]; then \
"$(GOPATH)/bin/air"; \
@echo "Watching...";\
else \
read -p "air is not installed. Do you want to install it now? (y/n) " choice; \
if [ "$$choice" = "y" ]; then \
go install github.com/cosmtrek/air@latest; \
"$(GOPATH)/bin/air"; \
@echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi
Generated code uses net/http package instead of echo
`
package server
import (
"fmt"
"net/http"
"time"
)
var port = 8080
type Server struct {
port int
}
func NewServer() *http.Server {
NewServer := &Server{
port: port,
}
// Declare Server config
server := &http.Server{
Addr: fmt.Sprintf(":%d", NewServer.port),
Handler: NewServer.RegisterRoutes(),
IdleTimeout: time.Minute,
ReadTimeout: 10 * time.Second,
WriteTimeout: 30 * time.Second,
}
return server
}`
Bug introduced in #59 (I messed up team).
Remind me not to code at 4am. Also we very much need unit tests.
create
in commandstandard library
framework option to be standard-library
instead.As blueprint gets bigger, I would really enjoy if someone volunteers to become an active core maintainer.
Preferably someone who has been already contributing as well.
Please comment here or ping me on Discord if you are interested!
PR #28 adds a workflow for linting the cli code but this does not lint the template code since that is just a string in the go code. Maybe it would be nice to have CI generate all templates to run the linter on those as well. That users don't have to manually check the generated code with the linter.
I want a hook to be added to the Discord (https://discord.gg/melkeydevhouse) channel #go-blueprint that will trigger every time there is a version release.
Looking at the README, it says that pq and mattn/sqlite3 are the supported database drivers, but I do not find these to be the best options for these databases.
For postgres:
For sqlite
A suggestion to the cli itself, wouldn't be cool if there were completion scripts for the program for bash, zsh and fish? I mean the program only has like 5 commands, but still :)
When using mattn/sqlite users are also bringing in CGO inherently. I think that when selecting the sqlite driver, it should bring in the modernc.org/sqlite driver, which does not use cgo into the project, leading to a safer project and ease of use with sqlite. The only negative is they would get a minor hit in performance with using this driver instead,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.