Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
licong committed Mar 15, 2022
1 parent ab0aaba commit 6790d76
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
with-proxy.exe
*.exe
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/hellojukay/with-proxy
module github.com/hellojukay/with-env

go 1.17

require github.com/joho/godotenv v1.4.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/joho/godotenv"
)

// first load env from ~/.env
// second load env from .env
func init() {
home, _ := os.UserHomeDir()
loadEnv(filepath.Join(home, ".env"), ".env")
}

func loadEnv(files ...string) {
for _, envfile := range files {
if _, err := os.Stat(envfile); !os.IsNotExist(err) {
_ = godotenv.Overload(envfile)
}
}

}
func main() {
c := exec.Command(os.Args[1], os.Args[2:]...)
c.Env = append(c.Env, os.Environ()...)
c.Env = append(c.Env, "https_proxy=http://127.0.0.1:7890")
c.Env = append(c.Env, "http_proxy=http://127.0.0.1:7890")
c.Env = append(c.Env, "HTTPS_PROXY=http://127.0.0.1:7890")
c.Env = append(c.Env, "HTTP_PROXY=http://127.0.0.1:7890")
c.Stderr = os.Stderr
c.Stdout = os.Stdout
if err := c.Run(); err != nil {
Expand Down

0 comments on commit 6790d76

Please sign in to comment.