Question

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...

Était-ce utile?

La solution

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!)

Autres conseils

  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 & Groups, YOUR CURRENT USER, Login Items, +, Select /Application/star_go_doc, Add.

DONE.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top