Cuando use gin para crear un servicio, modifique el código en el entorno de desarrollo, debe cerrar el servicio y luego volver a abrir el código para que surta efecto.
La modificación y apertura frecuente es algo muy ineficiente. Por lo tanto, se necesita una herramienta que pueda iniciarse en caliente después de modificar el código.
Se puede hacer con aire .
Instalar
go install github.com/cosmtrek/air@latest
configuración
air
La ruta no se configurará automáticamente, necesitamos agregar
alias air='$(go env GOPATH)/bin/air'
Luego agregue un archivo de configuración de aire
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
Ejecutar una orden
air
poder
Modificar bash zsh
vim ~/.zshrc
# or we can
# vim ~/.bash_profile
# Add this in the file
alias air='$(go env GOPATH)/bin/air'
De esta forma, se podrán aplicar nuevas terminales que se abran en el futuro