gobeego

Run add .env, so we can use .env params in app.conf with brace?


how can I run and pack with .env file, use bee-cli?, so the app.conf can read .env params with brace, like this:

appname = ${APP_NAME}

In my VSCode launch.json,I set like this:

"configurations": [
    {
        "name": "Launch Package",
        "type": "go",
        "request": "launch",
        "mode": "auto",
        "envFile": "${workspaceFolder}/.env",
        "program": "${workspaceFolder}/main.go",
        "cwd": "${workspaceFolder}"
    }
]

so, I can debug with .env file.

---------0320--------------- I found A doc below the link. https://github.com/beego/beedoc/blob/master/en-US/module/config.md#how-to-obtain-environment-variables

but I use beego v1.12.3. How this version to obtain Environment Variables?

-------------------------update-----------------------

My project has an .env file:

ADMIN_PORT=17201

ADMIN_ADDR=127.0.0.1

DATABASE_URL=127.0.0.1

MONGODB_URI=mongodb://127.0.0.1:27017

and I want get values like this: /conf/app.conf

AdminAddr = ${ADMIN_ADDR}
AdminPort = ${ADMIN_PORT}

when I execute the command : bee run It throw an error, like this:

panic: prefix should has path

In my project it means, app.conf can not get .env vaules.


Solution

  • should import

    _ "github.com/joho/godotenv/autoload"
    

    import godotenv before all packages