Comments (8)
I could make the binary works without env library (godotenv
) by adding ; <your command>
at the the bin
part
because my env is placed at .env
file, so in my case it would like this
[build]
bin = ";export $(grep -v '^#' .env | xargs); ./tmp/main"
cmd = "go build -o ./tmp/main ."
With your case, it might look like this. (full_bin
removed)
[build]
bin = ";MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug ./tmp/main"
cmd = "go build -o ./tmp/main ."
from air.
how can I load an env file to be used with the binary??
from air.
Please use full_bin
instead of cmd
, like:
full_bin = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"
from air.
It actually works well with full_bin
like:
[build]
cmd = "go build -o ./tmp/main ./cmd/myapp/"
full_bin = "DEBUG_ENABLED=true ./tmp/main"
I imagine if full_bin
is present then bin
is not taken into account, which is fine.
from air.
Please use
full_bin
instead ofcmd
, like:full_bin = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"
I try this, but in the code I can not get the environment MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug
, and then I have a failure with mongodb init error.
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"
[runner]
# Just plain old shell command. You could use `make` as well.
# cmd = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "MONGODB_HOST=127.0.0.1:27017 MONGODB_USER=test MONGODB_PASSWORD=test REDIS_ADDR=127.0.0.1 GIN_MODE=debug go run *.go"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"
[log]
# Show log time
time = false
[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
[misc]
# Delete tmp directory on exit
clean_on_exit = true
from air.
Another option is to use godotenv:
// This would automatically load/inject environment variables from a .env file
import _ "github.com/joho/godotenv/autoload"
from air.
I think this issue could be closed, the answer provided by @slaveofcode solves the problem.
from air.
This does not work for me
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
full_bin = "REDIS_PASSWORD=<redacted> go run ./..."
delay = 1000
exclude_dir = []
exclude_file = [".air.toml", ".gitignore"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
include_dir = []
include_ext = []
kill_delay = 2000
log = "build-errors.log"
send_interrupt = true
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
from air.
Related Issues (20)
- Implement graceful shutdown on Mac HOT 10
- Running on the root folder doesn't work HOT 2
- Feature Request: Specify Directories for Non-Rebuild Watch with Custom Command Execution
- Duplicate Processes; Port in use HOT 3
- include_file also needs include_ext to work HOT 2
- No such file or directory when project path has space HOT 3
- Continuous processes in cmd do not trigger subsequent builds
- Defaults to Windows PowerShell on Windows
- 可以监听 docker-compose 挂载的配置文件么?
- 变动构建失败 HOT 1
- 支持多个可执行文件 HOT 1
- Make pre_cmd background forkable HOT 3
- Air not being installed in zsh path on macOS HOT 4
- building memos not use docker in windows10
- i want to install the imported packages with air reloading
- Air always assumes that there is binary build target HOT 2
- zsh: permission denied:
- Hide logo or show custom text
- post_cmd on Windows with paths with spaces doesn't seem to work HOT 1
- pre_cmd fails HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from air.