Melkeydev / go-blueprint

Go-blueprint allows users to spin up a quick Go project using a popular framework
https://docs.go-blueprint.dev/
MIT License
5.96k stars 336 forks source link

Current `make watch` target fails to find `air` even after successful installation #74

Closed andrerocco closed 1 year ago

andrerocco commented 1 year ago

Description

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.

Environment

Additional Information

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
smantic commented 1 year ago

$GOPATH itself is not deprecated, what this was doing was fine. https://blog.smantic.dev/posts/gopath-is-not-deprecated/

What is deprecated is using $GOPATH as the workspace for go projects. This was typically where you developed go codebases before go modules.

read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
    go install github.com/cosmtrek/air@latest; 
    \air;\
echo "Watching...";\

This assumes that the user has added $GOBIN ($GOPATH/bin) to the user's path. This isnt a thing that happens automatically. The previous implementation did not assume that the user had $GOBIN in their path.

andrerocco commented 1 year ago

Yess @smantic, the description of the issue is indeed wrong, thanks for pointing it out.

My experience (and from issue #111 apparently) was that the previous implementation ran on every run of make watch. So it would install air on the system but not detect the installation afterward. Then I think neither the previous implementation should be relied upon.

I'm currious to see if people will have issues with the new implementation as you said that. I will take look into what could solution could be taken to make this as more generalized (work on more machines) as possible.

PratikDev commented 2 weeks ago

Hi @andrerocco I'm using the latest versions of both go and go-blueprint. but i'm still facing this problem of air: not found. Below is the watch target:

# Live Reload
watch:
    @if command -v air > /dev/null; then \
        air; \
        echo "Watching...";\
    else \
        read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
        if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
            go install github.com/air-verse/air@latest; \
            air; \
            echo "Watching...";\
        else \
            echo "You chose not to install air. Exiting..."; \
            exit 1; \
        fi; \
    fi

i also tried this:

watch:
  @echo "Watching..."
  @air -v

but that also didn't do any help. any idea what i'm doing wrong here?

note: i can successfully access the air command from terminal directly. this problem only occurs when i do it using the makefile image