Skip to content

Commit

Permalink
feat: move gitignore to embed files and updates to make and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mimatache committed Nov 12, 2023
1 parent 03cf71d commit 01ba983
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 121 deletions.
5 changes: 5 additions & 0 deletions cmd/template/files/README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ run the application
make run
```

live reload the application
```bash
make watch
```

run the test suite
```bash
make test
Expand Down
23 changes: 23 additions & 0 deletions cmd/template/files/gitignore.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
tmp/

# IDE specific files
.vscode
.idea
16 changes: 14 additions & 2 deletions cmd/template/files/makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ clean:

# Live Reload
watch:
@echo "Watching..."
@air
@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

.PHONY: all build run test clean
2 changes: 1 addition & 1 deletion cmd/template/files/routes/chi.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func (s *Server) helloWorldHandler(w http.ResponseWriter, r *http.Request) {
log.Fatalf("error handling JSON marshal. Err: %v", err)
}

w.Write(jsonResp)
_, _ = w.Write(jsonResp)
}
2 changes: 1 addition & 1 deletion cmd/template/files/routes/gorilla.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func (s *Server) helloWorldHandler(w http.ResponseWriter, r *http.Request) {
log.Fatalf("error handling JSON marshal. Err: %v", err)
}

w.Write(jsonResp)
_, _ = w.Write(jsonResp)
}
2 changes: 1 addition & 1 deletion cmd/template/files/routes/http_router.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ func (s *Server) helloWorldHandler(w http.ResponseWriter, r *http.Request) {
log.Fatalf("error handling JSON marshal. Err: %v", err)
}

w.Write(jsonResp)
_, _ = w.Write(jsonResp)
}
2 changes: 1 addition & 1 deletion cmd/template/files/routes/standard_library.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
log.Fatalf("error handling JSON marshal. Err: %v", err)
}

w.Write(jsonResp)
_, _ = w.Write(jsonResp)
}
121 changes: 6 additions & 115 deletions cmd/template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,134 +18,25 @@ var readmeTemplate []byte
//go:embed files/makefile.tmpl
var makeTemplate []byte

//go:embed files/gitignore.tmpl
var gitIgnoreTemplate []byte

// MakeTemplate returns a byte slice that represents
// the default Makefile template.
func MakeTemplate() []byte {
return []byte(
`
# Simple Makefile for a Go project
# Build the application
all: build
build:
@echo "Building..."
@go build -o main cmd/api/main.go
# Run the application
run:
@go run cmd/api/main.go
# Test the application
test:
@echo "Testing..."
@go test ./...
# Clean the binary
clean:
@echo "Cleaning..."
@rm -f main
# Live Reload
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
.PHONY: all build run test clean
`)
return makeTemplate
}


func GitIgnoreTemplate() []byte {
return []byte(
`
# 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 (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
tmp/
# IDE specific files
.vscode
.idea
`)
return gitIgnoreTemplate
}

func AirTomlTemplate() []byte {
return airTomlTemplate
}


// ReadmeTemplate returns a byte slice that represents
// the default README.md file template.
func ReadmeTemplate() []byte {
return []byte(
`
# Project {{.ProjectName}}
One Paragraph of project description goes here
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
## MakeFile
run all make commands with clean tests
` + "```bash" + `
make all build
` + "```" + `
build the application
` + "```bash" + `
make build
` + "```" + `
run the application
` + "```bash" + `
make run
` + "```" + `
live reload the application
` + "```bash" + `
make watch
` + "```" + `
run the test suite
` + "```bash" + `
make test
` + "```" + `
clean up binary from the last build
` + "```bash" + `
make clean
` + "```" + `
`)

return readmeTemplate
}

0 comments on commit 01ba983

Please sign in to comment.