英文:
Automatically start godoc localhost server in OS X?
问题
在Go语言中,你可以启动HTTP服务器,然后通过指定的端口浏览Go文档。例如,如果你在终端中输入godoc -http=:3333
,本地服务器就会在3333端口上开始工作,然后你就可以查看官方的Go文档。
然而,我想让它在我登录到OS X系统时自动启动,因为即使在没有Wi-Fi连接的情况下,使用Go代码编写非常强大和方便。所以在OS X中使用这样的守护进程可行吗?
我已经在MongoDB中实现并利用了类似的功能,可以参考这个示例,我想实现的就是这种类型的服务...
英文:
In Go, you can start HTTP server and then browse through the Go document via the specific port. For example, if you type in godoc -http=:3333
in Terminal, the localhost server starts working on port 3333 and you can then view the official Go document.
However, I would like to make it start automatically whenever I log in to the OS X system, since it is so powerful and convenient to write in Go code with even when I'm off the Wi-Fi connection. So is it feasible to use such daemon in OS X?
I have implemented and utilized the exact functionality in MongoDB from an example here, and it's exactly this kind of service that I want to achieve...
答案1
得分: 5
将此内容放入文件夹~/Library/LaunchAgents
中,并将文件命名为org.golang.doc.example.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.golang.doc.example</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/go/bin/godoc</string>
<string>-http=:6060</string>
</array>
<key>KeepAlive</key>
<true />
</dict>
</plist>
你可能需要自己创建文件夹。
下次登录你的账户时,godoc
应该会自动在6060端口启动。
(我没有进行过详细测试,欢迎提供反馈!)
英文:
Put this in the folder ~/Library/LaunchAgents
with a file name like org.golang.doc.example.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.golang.doc.example</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/go/bin/godoc</string>
<string>-http=:6060</string>
</array>
<key>KeepAlive</key>
<true />
</dict>
</plist>
You may have to create the folder yourself.
The next time you log into your account, godoc
should automatically start on port 6060.
(I have not tested it very well though. Feedback welcome!)
答案2
得分: 0
-
打开
终端
并输入:cd /Applications/
echo "godoc -http=:3333" > start_go_doc
chmod u+x start_go_doc
-
打开
系统偏好设置
,用户与群组
,选择当前用户,登录项
,+
,选择/Applications/start_go_doc
,添加
。
完成。
英文:
-
Open
Terminal
and type:cd /Applications/
echo "godoc -http=:3333" > start_go_doc
chmod u+x start_go_doc
-
Open
System Preferences
,Users & Groups
, YOUR CURRENT USER,Login Items
,+
, Select /Application/star_go_doc,Add
.
DONE.
答案3
得分: 0
你也可以尝试从AppStore下载Dash(文档和代码片段)。Dash是一个API文档浏览器和代码片段管理器,提供许多语言和框架的离线文档,包括Golang。
英文:
Also you can try Dash (Docs & Snippets) from AppStore. Dash is an API Documentation Browser an d Code Snippet Manager. Offline documentation for a lot of languages and frameworks including Golang.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论