What does your Go workflow look like

blov · · 1387 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have found working in the Go environment extremely refreshing. From the language to the tools. I was curious what everyone else was using to get their work done. Is it your hobby or your job or both? I am currently doing Go as a hobby but prepping for a large application build at work.</p> <p><a href="http://imgur.com/uQ2b8K9">http://imgur.com/uQ2b8K9</a> is a screenshot of my work environment. OS X / iTerm2 / tmux / vim / GoAuto (of course)</p> <hr/>**评论:**<br/><br/>UserNumber42: <pre><p>Two terminals in i3. One using vim to code, the other to run and build the project. I see people using all sorts of tools and haven&#39;t really jumped on that train. I&#39;m guessing the majority here are more advanced than me so let me know what I&#39;m missing.</p></pre>samuellampa: <pre><p>Basically same here (unless I use terminator or tmux for multi-terminal). Only I always make sure to have auto-completion installed in vim, so I don&#39;t need to look up the docs all the time. Then, since my vim/autocompletion setup tends to bitrot every other week, I set up an ansible config for it, and fire it up in a vagrant/docker, so I can easily throw away and restart when needing (available at: <a href="https://github.com/samuell/devbox-golang" rel="nofollow">https://github.com/samuell/devbox-golang</a> )</p></pre>mirovarga: <pre><p>I use the Atom editor with the go-plus package, an xterm to run the application (mostly a server) and a browser.</p></pre>rr1pp3rr: <pre><ol> <li>Gvim + spf13 + vim-go</li> <li>Tmux + zsh + guake</li> <li>Vagrant + docker</li> </ol> <p>I like to run my dev environments in the Vagrant machine for production parity. (I use arch, whereas we generally have Ubuntu servers).</p> <p>GVim is good once it&#39;s set up with spf13. Feels sorta like an IDE, not quite as smooth as intellij or visual studio, but free OSS. Really excited at the prospect of NeoVim.</p> <p>Basically I code up in vim, hit F12 to bring up guake, and I&#39;ll have a couple of splits in my tmux. One with vagrant and another local. The local one I&#39;ll use for godoc or gofmt or whatever, and I&#39;ll build/run on my vagrant.</p> <p>With vim-go it runs gofmt on your files on save, which is nice. But I also add some git commit hooks to run gofmt, go vet, go build, and whatever unit tests I have.</p> <p>I don&#39;t have any watchers set up, mainly because of the issues with inotify and vagrant. I&#39;d love to have something like this though, especially for tests.</p> <p>A couple of packages I use:</p> <ol> <li>Ginkgo + Gomega for tests</li> <li>Hopwatch for debugging (not a true step-through debugger, but has breaks and nicely formatted object dumps)</li> <li>Godep for dependency management</li> </ol></pre>dshills: <pre><p>Nice. I&#39;m excited for NeoVim as well. I switched from gofmt to goimports. Formatting + imports. Stood up a couple of Vagrants but never get them finished...</p></pre>rr1pp3rr: <pre><p>I have been using goimports for a while but never realized it also ran gofmt automatically as well! That would definitely improve my workflow, thanks.</p> <p>Also, I have a bootstrap file that I use for go vagrant machines. Basically installs go and sets up godep to use the dependencies in the file. If you want I can shoot you over the script. It has some specific things in there for my workflow, such as using godeps and installing some other dependancies, but you can tailor it for your personal use.</p> <p>If others are interested I can post it here as well.</p> <p>Man, I really need to start a blog or something.</p></pre>dshills: <pre><p>Very cool. It would be great if you posted it. Maybe other people have stuff to contribute to it as well.</p></pre>rr1pp3rr: <pre><p>Here it is. It&#39;s very simple, just installs go and builds the project. It is specific to a Debian-flavored distro because of the apt-get stuff. Installs Golang 1.4.2, you could parameterize that. There is probably a vagrant image with go already installed in their repos, but I wanted to start from a vanilla ubuntu box. </p> <p>You have to add the command to run the project yourself, if you want it to run after provisioning (like if you&#39;re running an API service):</p> <pre><code>#!/bin/bash ############################################## ######### SETUP ############################################## if ! command -v git &gt;/dev/null 2&gt;&amp;1; then echo &#34;INSTALL GIT&#34; apt-get -y install git fi if ! command -v hg &gt;/dev/null 2&gt;&amp;1; then echo &#34;INSTALL MERCURIAL&#34; apt-get -y install mercurial fi ############################################### ######### BUILD STEPS ############################################### if ! command -v go &gt;/dev/null 2&gt;&amp;1; then echo &#34;INSTALLING GO&#34; cd /tmp/ wget -q https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz ln -s /usr/local/go/bin/go /usr/bin/go mkdir -p /go/src/github.com/my_github_user ln -s /srv/projects/my_project/ /go/src/github.com/my_github_user/my_project GOPATH=/go/ go get github.com/tools/godep GOPATH=/go/ go get github.com/onsi/ginkgo/ginkgo GOPATH=/go/ go get github.com/onsi/gomega cd /go/src/github.com/my_github_user/my_project GOPATH=/go/ /go/bin/godep restore # Helps when ssh&#39;ing into the box echo &#34;export PATH=$PATH:/go/bin&#34; &gt;&gt; /home/vagrant/.bashrc echo &#34;export GOPATH=/go/&#34; &gt;&gt; /home/vagrant/.bashrc echo &#34;cd /go/src/github.com/my_github_user/my_project&#34; &gt;&gt; /home/vagrant/.bashrc echo &#34;sudo su&#34; &gt;&gt; /home/vagrant/.bashrc echo &#34;export PATH=$PATH:/go/bin&#34; &gt;&gt; /root/.bashrc echo &#34;export GOPATH=/go/&#34; &gt;&gt; /root/.bashrc echo &#34;cd /go/src/github.com/my_github_user/my_project&#34; &gt;&gt; /root/.bashrc fi echo &#34;BUILDING PROJECT&#34; cd /go/src/github.com/my_github_user/my_project GOPATH=/go/ /go/bin/godep go build ############################################### ######### RUN ############################################### echo &#34;RUNNING PROJECT&#34; # PUT YOUR RUN COMMAND HERE </code></pre></pre>dshills: <pre><p>Very cool, thx for sharing</p></pre>dvirsky: <pre><p>If you use the standard library&#39;s parser to manipulate the AST of a source file, dumping it back writes it properly formatted by default. So any time you manipulate a source file properly you&#39;re getting gofmt for free :)</p></pre>rr1pp3rr: <pre><p>Awesome. I haven&#39;t messed with the AST package yet, but I might have to now...</p> <p>Perhaps I can implement YAPMG (Yet another poor mans generics)</p></pre>dvirsky: <pre><p>I&#39;m using it with code I&#39;m generating using the text/template package. I&#39;m passing the generated code via the ast and formatter, both to make sure it is valid, and so I can pay less attention to the formatting in the template itself (which is harder to get right).</p></pre>Simpfally: <pre><p>Nice. I&#39;ve probably got the worst workflow you can think off. One xterm with vim on one half of the screen, and another xterm where I type go run. Hm.</p></pre>ericanderton: <pre><p>The advantage to this approach is that you could start over on a fresh system, and still be just as productive immediately after installing Go.</p></pre>beefsack: <pre><p>Go is a hobby of mine but would very much enjoy to get paid for it. I&#39;ve probably written in excess of 100k LOC of Go. My main project in Go is around 50k LOC across 20-30 packages and I&#39;ve been working on it in my spare time for nearly three years.</p> <p>My development machines are all Arch Linux (Gnome) tri-monitor desktops set up like the following:</p> <ul> <li>Left monitor: portrait running terminator with two horizontal splits. Shell is zsh.</li> <li>Central monitor: horizontal running gvim, single vertical split, looking very similar to OPs (molokai theme, vim-go, airline, bunch of plugins from Shougo.)</li> <li>Right monitor: horizontal running chromium, with email and documentation practically permanently open.</li> </ul> <p>I switch editors quite frequently but always end up coming back to Vim. Was using Emacs for a week or so very recently, playing with Atom with vim-mode at the moment but feels a bit clunky. vim-mode in Atom is quite impressive though and definitely makes Atom usable, and go-plus works rather well.</p></pre>dshills: <pre><p>I always end up back in vim as well. I have heard Evil mode in emacs has come a long way. I&#39;ve tricked out vim so much over the years it&#39;s so hard to give all that stuff up.</p></pre>ecmdome: <pre><p>I&#39;ve found the vim mode in atom less impressive than sublime personally. </p></pre>LarrySoetoro: <pre><p>Shut up and take my money. But seriously, I&#39;m hiring go dudes near Miami.</p> <p>Also, ive tried everything and i3 + vim is still my best experience. I use make for evil mostly.</p></pre>jordic: <pre><p>Ubuntu 14. Plan9ports + acme. Watch go test for file changes and apipe (from rog) for diff goimports inside acme windows. I also check godoc and man pages with acme. I tren to do all shell things from a project file that i use as a guide. I just wrote commands there and exec them. I also use acme for python projects using apipe with autopep8 When compile files simply with a right click i jump to the error. If i need a packaje i just write go get in front of the error. Also i use git inside acme. Curl for downloading js libs, ssh for remote commands... But all from inside acme wins :) I work with acme at full screen.</p></pre>dshills: <pre><p>Rob Pike did acme, correct? Interesting, now I have something else I have to go read about lol</p></pre>jordic: <pre><p>yes! And at least him and rsc from core go team are currently using it. The nice part of acme is that you can easy extend it wit go, or shell or anything you like.. check 9fans.net</p></pre>acln: <pre><p>I use acme in full screen for everything too!</p> <p>Do you use a fixed-width font for Go? I gave variable-width fonts a try for a while (since variable-width was the default in acme), but gofmt-ed structs were not nice to look at, so I stuck with fixed-width in the end.</p></pre>jordic: <pre><p>I can&#39;t work with a variable width font. Last time, I use Menlo, as my acme font. Same that in go src web.</p></pre>4ad: <pre><p>I use Anonymous Pro (a fixed width font) on my external monitor, and Lucida Grande (variable width) on my laptop&#39;s display.</p></pre>dinkumator: <pre><p>I use GoSublime + SFTP plugins for Sublime Text, and my web framework watches for file changes on the server (running in tmux) and reloads itself with the updated code.</p></pre>kurin: <pre><p>I write Go at work. I pretty much just use Emacs with goimports in a save hook. There&#39;s some special tooling to make the Go workflow fit into our tooling, which is unfortunate because it&#39;s about a billionty times worse than <code>go build</code> but still, it works.</p></pre>cyrusol: <pre><p>I still have Windows on my desktop. When Go went 1.0 I used LiteIDE, but after a while I discovered the niceties of MSYS2. Since then I just used vim. I have a bunch of compiler commands (or similar like bench, test) set up on F1-F12 including go build and bin/&lt;insert_binary_name&gt;. I usually just press those keys and the file gets saved, a cleared shell will spawn, the compiler will run (and spit out errors if any) and then the program will be run against the tests and/or executed and its output will be saved. Then I press Ctrl+D and are back in vim. I&#39;m doing the same for Rust, Java, Python, C and bash/zsh programs but I&#39;ve not found a satisfying way of running/testing big server side PHP software like Magento. Also I&#39;m trying to apply a src, lib, bin directory structure for projects or workspaces of any language.</p> <p>A vagrant VM is something I always wanted and still want, but cannot afford, since <em>all</em> my PCs and my workstation at work have 4 GB RAM max and a browser alone needs 1-2GB, a VM would need another 1GB for the likes of Magento, but what about Photoshop then?... Yes, web stuff.</p></pre>dshills: <pre><p>Don&#39;t know your setup but you could keep a term open on the server and use GoAuto, Grunt, Gulp etc to kick off tests when files change. My one plug for GoAuto would be that you would build it yourself and could add things like timers to not rerun tests unless x amount of time has passed or email if something doesn&#39;t pass or whatever.</p></pre>dvirsky: <pre><p>I&#39;m writing Go professionally. I have an Ubuntu box with Gnome 14.04 and I usually work more or less like this:</p> <ol> <li><p>LiteIDE as the editor, testing console, localy playground, debugger front-end, etc. I used Sublime for a year or so, but lately LiteIDE has become really good. Atom and Intellij are making great progress as well.</p></li> <li><p>Godep for vendoring dependencies. Nut looks promising too.</p></li> <li><p>Docker for packaging my servers.</p></li> <li><p>Hudson as a CI system.</p></li> <li><p>Fabric for deployment to EC2. </p></li> </ol></pre>oldcoderexception: <pre><p>Linux Mint 17, Sublime Text 2 with GoSublime, some bash scripts in a terminal for building and moving things to run directories for test. Then I just rsync from there to production (production is Ubuntu 14.04). The systems guys will likely start using linux containers very soon (they most likely will be Docker) at which point I&#39;ll jump on that band wagon, especially since the current project involves many micro-services. First post ever by the way! ;)</p></pre>anlhord: <pre><p>gedit: Cobalt theme bash, gnome-terminal font: dejaVu Sans Mono 12 browsers: mozilla, chromium virtualbox: windows 7, visual studio</p></pre>ericanderton: <pre><p>I tend to run pretty lean and mean:</p> <ul> <li>OSX</li> <li>Vim with the stock golang syntax files</li> <li>Custom vim shortcuts for buffer management</li> <li>Git bash prompt extensions to show current branch and clean/dirty state on command line</li> <li>Second terminal to do make execution</li> <li>Go projects always have a makefile to further enhance Go&#39;s lightweight build/test automation</li> </ul> <p>I have made a few passes at quickfix integration, with mixed results. The core problem has to do with path handling, so I&#39;ve started moving away from it. Since my Macbook makes shifting between terminals a breeze (three finger swipe left/right if full-screen, or just Cmd+Tilde), it works out well.</p> <p>Edit: I&#39;ll add that I tend to use Vim more like an editor than an IDE. I find myself editing a set of buffers at at time, then returning to the command line to fire up a vim session for a different set of files. In general, I prefer BASH&#39;s handling of file matching and tab completion quirks to vim&#39;s. Sometimes, I&#39;ll browse using vim (e.g. &#34;sp:&#34;), but usually that&#39;s not the case.</p> <p>Edit2: In Linux I&#39;ll do much the same, but I&#39;ll also run with some enhancements to BASH tab completion, specifically for Git and Make. Makefile auto-completion is incredibly nice as it makes each project <em>almost</em> self-documenting, which is helpful if you wrangle many projects.</p></pre>dshills: <pre><p>I was the same way with vim till about a year ago. I started using Unite+vimfiler and vim-fugitive for git. Now I rarely leave vim.</p> <ul> <li><a href="https://github.com/Shougo/vimfiler.vim" rel="nofollow">https://github.com/Shougo/vimfiler.vim</a></li> <li><a href="https://github.com/Shougo/unite.vim" rel="nofollow">https://github.com/Shougo/unite.vim</a></li> <li><a href="https://github.com/tpope/vim-fugitive" rel="nofollow">https://github.com/tpope/vim-fugitive</a></li> </ul> <p>| edited for formatting</p></pre>icholy: <pre><p>ubuntu 12.04, i3, dual monitor zsh, neovim, fatih/vim-go, YouCompleteMe</p> <p><a href="http://i.imgur.com/LeDkL2L.png" rel="nofollow">http://i.imgur.com/LeDkL2L.png</a></p></pre>hipone: <pre><blockquote> <p><a href="http://imgur.com/uQ2b8K9">http://imgur.com/uQ2b8K9</a></p> </blockquote> <p>The users slice should be of len(records) - 1 size.</p></pre>icholy: <pre><p>Lol, I knew that when I posted it but thought, &#34;Who&#39;s going to notice?&#34;.</p></pre>joshuagopher: <pre><p>I think you quoted the wrong image.</p></pre>dshills: <pre><p>I see what you did there :)</p></pre>balfrag: <pre><p>Nice work! What themes are you using for iTerm2 and Vim?</p></pre>anticucho: <pre><p>I&#39;m not OP but it looks like powerline for the bottom tmux status bar and Molokai for the color scheme. Check out base16 for a great vim color scheme manager.</p></pre>dshills: <pre><ul> <li>Airline with Powerline in vim.</li> <li>Molokai colo but I change around a lot</li> <li>I use a color scheme for iTerm2 called Atom.</li> <li>I also use godlygeek/csapprox in vim to help approximate what MacVim would show.</li> <li>12pt Droid Sans Powerline Plus </li> <li>The tmux line is configured to be out of the way and show very little.</li> <li>zsh</li> </ul> <p>| edited for format and clarity</p></pre>om0tho: <pre><ul> <li>OS X + Linux</li> <li>Terminal.app (<a href="https://github.com/chriskempson/tomorrow-theme/tree/master/OS%20X%20Terminal" rel="nofollow">Tomorrow Theme</a>)</li> <li>Zsh + <a href="https://github.com/robbyrussell/oh-my-zsh" rel="nofollow">Oh My Zsh</a></li> <li><a href="https://godoc.org/golang.org/x/tools/cmd/goimports" rel="nofollow">goimports</a></li> <li><a href="https://github.com/fatih/vim-go" rel="nofollow">vim-go</a></li> <li><a href="https://bitbucket.org/eradman/entr/" rel="nofollow">entr</a></li> <li>git</li> <li>Sublime Text + <a href="https://packagecontrol.io/packages/GoSublime" rel="nofollow">GoSublime</a> (I used to use this more.)</li> </ul></pre>JokerSp3: <pre><p>Mostly liteide on ubuntu with terminal for running everything</p></pre>kingmanaz: <pre><p>I build using go 1.4.2 from MS Windows at work. My setup is gVim, &#34;misc/vim&#34; copied over from from go 1.3, and gocode.</p> <p>I tried installing &#34;go-vim&#34; but couldn&#39;t get it running after 10 minutes. I abandoned it for 1.3&#39;s &#34;misc/vim&#34; scripts and couldn&#39;t be happier.</p></pre>farslan: <pre><p>Vim-go author here. Sorry to hear it. vim-go is now very stable and lots of fixes are merged. Binaries are not required if you don&#39;t use the specific features (such as oracle,godef, etc..). Let me know If I can help, I really want to deliver the best possible Vim experience :) Thanks</p></pre>afisk: <pre><p>I gotta say I just updated vim-go from my install from a few months back, and I&#39;m super impressed with all the progress. Great contribution @farsian!</p></pre>dshills: <pre><p>Thanks for vim-go. It rocks, no seriously, it rocks :)</p></pre>musquirt: <pre><p>Sublime Text to write code.</p> <p>I use <code>docker-compose</code> to run my application, run unit tests, run cucumber tests, initialize my database, and even to run <code>go fmt</code>. Using <code>docker-compose</code> allows me to not have to keep track of a local go install and all the dependencies. I use a <code>Godep</code> file alongside <code>gvm</code> to install dependencies in my <code>docker</code> containers.</p></pre>shirro: <pre><p>A laptop (macbook, chrome book, linux, whatever I pick up that is charged), ssh, a Debian VPS, vim with a few plugins (anything from tpope, vim-go and some completion stuff) some shell scripts, git, chrome.</p></pre>FUZxxl: <pre><p>I use <code>ed</code> to edit my code, which I compile with <code>go build</code> and check in with <code>git</code> every once in a while.</p></pre>idobi: <pre><p>vim + tmux + rerun I use vim (sometimes atom or sublime text depending on how I am feeling that day), tmux and <a href="https://github.com/skelterjohn/rerun" rel="nofollow">https://github.com/skelterjohn/rerun</a> to iteratively build and test as I code. I highly suggest rerun no matter the environment. I even do Go GUI programming using it.</p></pre>purak: <pre><p>Just a tmux session on a DigitalOcean VM(Ubuntu 14.04). I also use vim with vim-go plugin. Thanks to this setup, I am ready to develop in anywhere and at anytime. </p></pre>varun06: <pre><p>OSX+Sublime Text 3 + iterm2 Using this setup for professional as well as personal go development.</p></pre>motyar: <pre><p>Go setup on DigitalOcean VPS Remote access in Vim on MacBooKAir ( tmux, xterm)</p></pre>samuellampa: <pre><p>I work completely in the terminal, with a vim-setup with auto-completion. What I like best about my setup is that it is all automated as a vagrant box, that provisions a docker image using Ansible (available at <a href="https://github.com/samuell/devbox-golang" rel="nofollow">https://github.com/samuell/devbox-golang</a> ... screenshot on the front). This might sound like I just try to use all the coolest tech together, but I in fact do it simply because it works so extremely well. Docker makes a very light-weight and fast setup of the environment, ansible lets me re-use the configuration script for other targets (like my host operating system, or a cloud image), and vagrant makes operating the combo so easy that anyone can do it: vagrant up, vagrant ssh, and off you go!</p></pre>HR-Uriel: <pre><p>I&#39;m using brackets, from Adobe. Simple, powerful and lot of plugins for go and git. </p></pre>dshills: <pre><p>Intriguing. Never even heard of brackets. Downloading now.</p></pre>joshuagopher: <pre><p>I don&#39;t have a lot of time to set up a lot of command line stuff, but I will consider checking out GoAuto. I use plain old Atom editor, because of the nice colors. I&#39;ve used Go at work once for a small scraper tool, but other than that it&#39;s a hobby. <a href="http://i.imgur.com/KmLQwDE.jpg" rel="nofollow">http://i.imgur.com/KmLQwDE.jpg</a></p> <p>OSX / Atom</p> <p>Also I use relative paths on my import statements, saves me time.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1387 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传