Skip to content

Commit

Permalink
feat: use air (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Mar 19, 2024
1 parent f6e80e0 commit bdc7b2d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
.vscode
.trunk
.env.dev
tmp/
45 changes: 9 additions & 36 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
- [Node.js](https://nodejs.org/en/)
- [Yarn](https://yarnpkg.com/)
- [Go](https://golang.org/)
> Do not install through brew, use the official website
- Do not install through brew, use the official website
- [Docker](https://www.docker.com/)
- [PostgreSQL](https://www.postgresql.org/)
- Install through brew: `brew install postgresql@15`
- It requires you to add all the exports to path so read the end of the installation carefully!
- [Trunk](https://marketplace.visualstudio.com/items?itemName=Trunk.io) (Recommended!)
- Visual Studio Code extension for linting/formatting
- [Air](https://github.com/cosmtrek/air?tab=readme-ov-file#installation)
- Live reload for Go apps
- [gofumpt](https://github.com/mvdan/gofumpt)
- A stricter gofmt
- [golangci-lint](https://golangci-lint.run/welcome/install/)
- A Go linters aggregator

# Setup

Expand Down Expand Up @@ -121,45 +127,14 @@
```console
go run main.go // run server
go test ./... // run tests
go fmt ./... // format code
go vet ./... // lint code
gofumpt -l -w . // format code
golangci-lint run --fix // lint code
```

### SAC CLI

To install use `./install.sh` and then run `sac-cli` to see all commands.

```console
NAME:
sac-cli - CLI for SAC

USAGE:
sac-cli [global options] command [command options]

COMMANDS:
swagger, swag Updates the swagger documentation
test, t Runs tests
help, h Shows a list of commands or help for one command
CI:
format, f Runs formatting tools
lint, l Runs linting tools
* can use --fix to fix linting errors for frontend
Database Operations:
clean, c Remove databases used for testing
migrate, m Migrate the database, creating tables and relationships
reset, r Resets the database, dropping all tables, clearing data, and re-running migrations
* can use --data to just reset data and not drop tables
insert, i Inserts mock data into the database
drop, d Drop data with a migration or drops the entire database
* can use --data to just drop data and not drop tables

Development:
be Run the backend
fe Run the frontend

GLOBAL OPTIONS:
--help, -h show help
```
# Git Flow

1. **Create a new branch**
Expand All @@ -179,8 +154,6 @@

- We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages. (READ!)

<!-- - We especially recommend [Trunk](https://marketplace.visualstudio.com/items?itemName=Trunk.io) for linting -->

3. **Push changes to GitHub**

```console
Expand Down
43 changes: 43 additions & 0 deletions backend/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
root = "."
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main main.go"
delay = 0
exclude_dir = ["tmp"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = ["src"]
include_ext = ["go"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = true

[screen]
clear_on_rebuild = false
keep_scroll = true
8 changes: 4 additions & 4 deletions cli/commands/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

func BackendCommand() *cli.Command {
command := &cli.Command{
Name: "backend",
Usage: "Starts the backend server",
Aliases: []string{"be"},
Name: "be",
Usage: "Run the backend",
Category: "Development",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "use-dev-dot-env",
Expand All @@ -35,7 +35,7 @@ func BackendCommand() *cli.Command {
}

func RunBackend() error {
cmd := exec.Command("go", "run", "main.go")
cmd := exec.Command("air")
cmd.Dir = BACKEND_SRC_DIR
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func LintFrontend(target string, fix bool) error {
func LintBackend() error {
fmt.Println("Linting backend")

cmd := exec.Command("go", "vet", "./...")
cmd := exec.Command("golangci-lint", "run", "--fix")
cmd.Dir = BACKEND_DIR

err := cmd.Run()
Expand Down

0 comments on commit bdc7b2d

Please sign in to comment.