Giter Club home page Giter Club logo

Comments (8)

slaveofcode avatar slaveofcode commented on May 13, 2024 18

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.

andodeki avatar andodeki commented on May 13, 2024 6

how can I load an env file to be used with the binary??

from air.

cosmtrek avatar cosmtrek commented on May 13, 2024 4

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.

rwngallego avatar rwngallego commented on May 13, 2024 2

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.

shmilyoo avatar shmilyoo commented on May 13, 2024

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"

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.

Dids avatar Dids commented on May 13, 2024

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.

Evertonesc avatar Evertonesc commented on May 13, 2024

I think this issue could be closed, the answer provided by @slaveofcode solves the problem.

from air.

frankgreco avatar frankgreco commented on May 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.