在OS X中自动启动godoc本地服务器怎么做?

huangapple go评论100阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN
           http://www.apple.com/DTDs/PropertyList-1.0.dtd &gt;
&lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.golang.doc.example&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
      &lt;string&gt;/usr/local/go/bin/godoc&lt;/string&gt;
      &lt;string&gt;-http=:6060&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;true /&gt;
  &lt;/dict&gt;
&lt;/plist&gt;

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

  1. 打开终端并输入:

    cd /Applications/

    echo "godoc -http=:3333" > start_go_doc

    chmod u+x start_go_doc

  2. 打开系统偏好设置用户与群组,选择当前用户,登录项+,选择 /Applications/start_go_doc添加

完成。

英文:
  1. Open Terminal and type:

    cd /Applications/

    echo "godoc -http=:3333" > start_go_doc

    chmod u+x start_go_doc

  2. Open System Preferences, Users &amp; 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.

huangapple
  • 本文由 发表于 2013年9月27日 12:52:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/19042963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定