英文:
Is it possible to set the system proxy from golang app in macOS or Linux distributes?
问题
你好!你想在你的golang应用程序中创建一个代理服务器,并且希望能够将其设置为系统代理。这是可能的吗?如何实现呢?
英文:
I'm creating golang app with a proxy server as a pet project, and I want to have the possibility to set himself as a system proxy. Is it possible? And how?
答案1
得分: 2
代理通常通过HTTP_PROXY
、HTTPS_PROXY
和NO_PROXY
环境变量进行配置。在类Unix操作系统中,这些变量会从父进程继承给其子进程。
话虽如此:
- 您的程序可以修改自己的环境并启动其他进程作为子进程(传递
_PROXY
变量)。 - 您的程序可以修改shell启动脚本(如
.bashrc
、.cshrc
),新启动的shell将获取这些值并将它们传递给新启动的进程。
但我不知道修改其他(活动的)进程的环境是否可行。
英文:
Proxies are often configured through the HTTP_PROXY
, HTTPS_PROXY
and NO_PROXY
environment variables. In Unix-style operating systems, these variables are inherited from the parent process to its child processes.
This being said:
- your program can modify its own environment and start other processes as child processes (passing in the
_PROXY
variables). - your program may modify the shell startup scripts (like
.bashrc
,.cshrc
), and a newly started shell will pick the values up and pass them to newly started processes.
But I am not aware that modifying the environment of other (active) processes is possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论