tag:blogger.com,1999:blog-21159391042384108812024-03-13T22:07:46.954-07:00Adentures in GoPlaying with <a href="http://golang.org/">go</a> [<a href="https://bitbucket.org/tebeka/go-wise/src">view source</a>]Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-2115939104238410881.post-28084621159955743512012-12-14T18:35:00.002-08:002012-12-14T18:35:21.814-08:00L.A Gophers - The Standard Library Part 1The <a href="http://www.meetup.com/Los-Angeles-Gophers/">meetup</a> video is <a href="http://www.youtube.com/watch?v=7H3O2ENmdvs&feature=youtu.be">up</a>.Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com1tag:blogger.com,1999:blog-2115939104238410881.post-80418139110494900882012-12-10T09:31:00.000-08:002012-12-10T09:31:04.967-08:00strftimeGo's <a href="http://golang.org/pkg/time/#Time">time.Time</a> already have <a href="http://golang.org/pkg/time/#Time.Format">Format</a>, which is very human readable. However if you try to "embed" time format in longer strings, Format might expand things that you want to stay fixed. Take for example "/report06/2006", the first "06: will be expanded to the current year.<br />
<br />
Python's <a href="http://docs.python.org/2/library/time.html#time.strftime">strftime</a> is less human readable but requires explicit escaping to it's easier to write string with embedded time directives. Now you can have strftime in Go as well.<br />
<br />
To get it, run the usual <span style="font-family: Courier New, Courier, monospace;">go get bitbucket.org/tebeka/strftime</span>.<br />
<br />
<script src="https://bitbucket.org/tebeka/strftime/src/tip/strftime.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-74908478029734178582012-12-04T17:07:00.002-08:002012-12-04T17:07:37.620-08:00snowballI wanted to play a bit with <a href="http://golang.org/cmd/cgo/">cgo</a>. As a project I tried to have Go bindings to <a href="http://snowball.tartarus.org/">snowball</a>.<br />
<br />
One of the problems was that snowball does not come as a library but an archive of sources. cgo can handle C source files, but all in the same directory. I had to "<a href="https://bitbucket.org/tebeka/snowball/src/tip/fetch.sh?at=default">flatten</a>" the source tree, rewriting <span style="font-family: Courier New, Courier, monospace;">#include</span> directives (sed FTW!).<br />
<br />
One the above was done, the rest was pretty much straightforward. I confess that at the beginning I wanted to write a lot of C helper functions, but managed to resist the temptation :)<br />
<br />
You can get it with <span style="font-family: Courier New, Courier, monospace;">go get bitbucket.org/tebeka/snowball</span>. Note the building takes time - that's C compilation for you :)<br />
<script src="https://bitbucket.org/tebeka/snowball/src/tip/snowball.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-29358517090823850352012-10-26T14:23:00.001-07:002012-10-26T14:23:06.385-07:00nrsc - Take 2After getting some good comments on <a href="https://bitbucket.org/tebeka/nrsc">nrsc</a> and reading more. I re-wrote the implementation to append a zip file to the executable and serve resources from there (idea from <a href="http://bit.ly/SmYXXm">Carlos Castillo</a>).<br />
<br />
The order you do the packing has change, you first "<span style="font-family: Courier New, Courier, monospace;">go build</span>" and then run the <span style="font-family: Courier New, Courier, monospace;">nrsc</span> script.<br />
<br />
Here the nrsc script that packs the zip into the executable. The<a href="http://go.pkgdoc.org/bitbucket.org/tebeka/nrsc"> nrsc API</a> didn't change that much.<br />
<br />
<script src="https://bitbucket.org/tebeka/nrsc/src/tip/nrsc?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com1tag:blogger.com,1999:blog-2115939104238410881.post-32660475739087161912012-10-23T09:27:00.000-07:002012-10-23T09:27:23.489-07:00nrsc - Resource CompilerIMO one of the nicest things in Go is the "single executable deployment". However this breaks down when you have some templates, css files, ...<br />
<br />
For this I created <a href="https://bitbucket.org/tebeka/nrsc">nrsc</a>, it's a resource compiler that will compile your resources to a local <span style="font-family: Courier New, Courier, monospace;">nrsc</span> package which you can include in your project. Building your project after running nrsc will embed all the resource in the executable.<br />
<br />
To install <span style="font-family: Courier New, Courier, monospace;">nrsc</span> just run <span style="font-family: Courier New, Courier, monospace;">go get bitbucket.org/tebeka/nrsc</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Here's an example on how to use nrsc in your code:</span><br />
<span style="font-family: inherit;"><br /></span>
<script src="https://gist.github.com/3939872.js?file=gistfile1.go"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-21090773795299283432012-09-21T12:23:00.000-07:002012-09-21T12:23:37.825-07:00Jenkins/Hudson IntegrationThe most dominate CI system is <a href="http://jenkins-ci.org/">Jenkins</a> (was Hudson).<br />
<br />
Jenkins has a nice integration with xunit XML output for tests. I wrote a little utility that converts <span style="font-family: "Courier New",Courier,monospace;"><span style="background-color: #cccccc;">go test -v</span> </span>output to xunit compatible XML called <a href="https://bitbucket.org/tebeka/go2xunit">go2xunit</a>. (install with the usual <span style="background-color: #cccccc;"><span style="font-family: "Courier New",Courier,monospace;">go get bitbucket.org/tebeka/go2xunit</span></span>).<br />
<br />
The view on Jenkins (tests are failing intentionally) is like the below. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYt1COJvO88dHw0z1Dw_MOs_Ll1zgx2OmVVeUhZ58T1Z7yAyjSEU3Sw5UW8gSet-26d5zlEeqrUdwvosoAtH0mbjZ-MUXlIlYV5KMhNl_i1aCukuGF5x-TSLvSg-NzMuou8gdTUB_Whe0/s1600/build-overrview.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="134" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYt1COJvO88dHw0z1Dw_MOs_Ll1zgx2OmVVeUhZ58T1Z7yAyjSEU3Sw5UW8gSet-26d5zlEeqrUdwvosoAtH0mbjZ-MUXlIlYV5KMhNl_i1aCukuGF5x-TSLvSg-NzMuou8gdTUB_Whe0/s320/build-overrview.png" width="320" /></a></div>
<br />
When you click on the tests you get<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgff_7vnOXS-ronVseOYFiEMEr3mNgpdckVf2MmGnjcSCU-zLx_Rhp8GkYO38-7Sk3iOUayxPyFDbEXS1dfo8GGD3DlLWnvUrYLDxwkMKLm0dGWrEi81VvhwPpz5mBAu7wswNGv7tgYXVU/s1600/build-tests.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="129" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgff_7vnOXS-ronVseOYFiEMEr3mNgpdckVf2MmGnjcSCU-zLx_Rhp8GkYO38-7Sk3iOUayxPyFDbEXS1dfo8GGD3DlLWnvUrYLDxwkMKLm0dGWrEi81VvhwPpz5mBAu7wswNGv7tgYXVU/s320/build-tests.png" width="320" /></a></div>
<br />
<br />
There's a <a href="https://bitbucket.org/tebeka/go2xunit/src/tip/demo">demo</a> directory with an <a href="https://bitbucket.org/tebeka/go2xunit/src/tip/demo/jenkins.sh">example bash script</a>. The project configuration looks something like the below. Note the "Execute Shell" command and "Publish JUnit tests report" sections.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTb1fBY0hQH915hGBA2OatL6WDifGvor_EDPM-do2F-ioPCYlBS7wlgjilLr6Wl5m3lriNsC7U9kRIoKFlZYEh8brZ9Hzt-fgNJqmHtsVX4teJqtFU2AEkQ_qfnaoJE4S1NAqkt6NiXUs/s1600/config.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTb1fBY0hQH915hGBA2OatL6WDifGvor_EDPM-do2F-ioPCYlBS7wlgjilLr6Wl5m3lriNsC7U9kRIoKFlZYEh8brZ9Hzt-fgNJqmHtsVX4teJqtFU2AEkQ_qfnaoJE4S1NAqkt6NiXUs/s320/config.png" width="217" /></a></div>
<br />
Happy Testing.<br />
<br />
Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com2tag:blogger.com,1999:blog-2115939104238410881.post-28772042118168938422012-09-06T13:32:00.003-07:002012-09-06T13:32:53.381-07:00seamless - now with multiple backendsUpdated <a href="https://bitbucket.org/tebeka/seamless">seamless</a> to support multiple backends (thank you <a href="https://twitter.com/fabmilo">Fabrizio</a> for helping out).<br />
<br />
The new API is:<br />
<ul>
<li><span style="font-family: "Courier New",Courier,monospace;">/set?backends=host:port,host:port</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;">/add?backend=host:port</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;">/remove?backend=host:port</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;">/get </span></li>
</ul>
The front end will round-robin between the backends.<br />
<br />
You can install either via <span style="background-color: #cccccc;"><span style="font-family: "Courier New",Courier,monospace;">go get bitbucket.org/tebeka/seamless</span></span> or by <a href="https://bitbucket.org/tebeka/seamless/downloads">downloading the binaries</a>.Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-18357017458415173942012-08-10T16:34:00.000-07:002012-08-24T09:30:45.918-07:00seamless - always up services in 85 lines of GoAt <a href="http://www.adconion.com/us/index.html">work</a> we're debating on how to upgrade servers that need to be up all the time. This prompted me to write <a href="https://bitbucket.org/tebeka/seamless">seamless</a>.<br />
<br />
It's a 1 to 1 TCP proxy which lets you switch the backend via an HTTP interface (on a different port than the one being proxied).<br />
<br />
Typical workflow will be:<br />
<ul>
<li>Start backend on internal port</li>
<li>Start seamless and proxy exposed port to backend</li>
<li>When upgrading start new backend on different external port</li>
<li>Tell seamless to switch backends</li>
</ul>
You can install seamless by running:<br />
<span style="font-family: "Courier New", Courier, monospace;"> go install bitbucket.org/tebeka/seamless</span><br />
<br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="font-family: inherit;">or if you don't have the go runtime, you can <a href="https://bitbucket.org/tebeka/seamless/downloads">download the binaries</a>.</span></span> <br />
<ul>
</ul>
All the code (inspired by <a href="http://bit.ly/Oc1YtF">Roger Peppe</a>) is just <strike>72</strike> 85 lines.<br />
<span id="goog_1953072391"></span><a href="http://www.blogger.com/"></a><span id="goog_1953072392"></span>
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/seamless.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-75017620550466909242012-07-03T09:25:00.001-07:002012-07-03T09:25:46.331-07:00timeatA small command line utility to display the current time at a given location. It's a mash between <a href="https://developers.google.com/maps/">Google Maps API</a> (<a href="http://golang.org/pkg/encoding/json/">JSON</a>) and <a href="http://www.geonames.org/export/web-services.html">Geonames</a> (<a href="http://golang.org/pkg/encoding/xml/">XML</a>).<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/timeat.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-81555797226857412022012-04-28T09:10:00.000-07:002012-04-28T09:11:07.228-07:00Image RepositoryHere's a small we app the allows users to upload photos (somewhat like <a href="http://imgur.com/">imgur</a>).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTgdoj4UiMwxBcy05mTL89VLckKGqgKBVRuUpcAdKP5Fljy8pfBb1xgQGON9NPwhTKwBuG95_BMorHtaPzyfG1TwRoVVHQ4NX6vE_ttPqd5EOKiIuBTmXPAXn-FKJ5Lizjgh-DWWvEl84/s1600/screenshot.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="103" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTgdoj4UiMwxBcy05mTL89VLckKGqgKBVRuUpcAdKP5Fljy8pfBb1xgQGON9NPwhTKwBuG95_BMorHtaPzyfG1TwRoVVHQ4NX6vE_ttPqd5EOKiIuBTmXPAXn-FKJ5Lizjgh-DWWvEl84/s400/screenshot.png" width="400" /></a></div>
<br />
<span style="font-size: large;">Code</span><br />
<script src="https://bitbucket.org/tebeka/go-wise/src/a2f448e8b00e/imgur/imgur.go?embed=t">
</script>
<br />
<br />
<span style="font-size: large;">Template</span>
<script src="https://bitbucket.org/tebeka/go-wise/src/a2f448e8b00e/imgur/index.html?embed=t">
</script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-46196379504873667742012-04-19T10:26:00.000-07:002012-12-18T08:41:24.535-08:00Open file/urls with default programHere's the code for a cross platform way to open file/uri with default application.<br />
<br />
You can also install the package with<br />
<span style="font-family: "Courier New",Courier,monospace;"> go install bitbucket.org/tebeka/desktop</span><br />
<br />
<br />
<script src="https://bitbucket.org/tebeka/desktop/src/tip/desktop.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-41869060306691491302012-04-16T17:10:00.002-07:002012-04-16T17:10:56.019-07:00Web/Desktop Application<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDA-zcTJ3XwLe5y8mUU-OhUBJ8B1Xx7HzFzi-qJSBIr34yJ9v_d5LJQCWNXLgf03jTeGiyrdkeUgbGNd4YUFL2JyeUMzTGFdipmxfxfOJHvNcA328PV6oe9-er7rjwVLGfCN_q_49tiok/s1600/webtop.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="172" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDA-zcTJ3XwLe5y8mUU-OhUBJ8B1Xx7HzFzi-qJSBIr34yJ9v_d5LJQCWNXLgf03jTeGiyrdkeUgbGNd4YUFL2JyeUMzTGFdipmxfxfOJHvNcA328PV6oe9-er7rjwVLGfCN_q_49tiok/s320/webtop.png" width="320" /></a>Currently there's no easy/cross platform way to write desktop applications in go.<br />
However I found out the for simple UI (which in my case covers most of them). I can get away with writing the application as a web server and point the user browser to it.<br />
<br />
Here is a small example for a guest book:<br />
<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/22424913007b/gui.go?embed=t">
</script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-36077053431482561262012-04-07T08:03:00.000-07:002012-04-07T08:03:17.322-07:00Building Go ProjectsNow that Go1 is out, the way to build projects is using the <a href="http://golang.org/cmd/go/">go</a> tool. I found out that the following process works for me.<br />
<br />
I have a directory <span style="font-family: "Courier New",Courier,monospace;">goroot</span> somewhere and there under <span style="font-family: "Courier New",Courier,monospace;">src</span> I have all my projects. Then I use the following Makefile (this is an example from <a href="https://bitbucket.org/tebeka/selenium">selenium/webdriver client</a>).<br />
<br />
<script src="https://bitbucket.org/tebeka/selenium/src/tip/Makefile?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-74080209455202823932011-12-14T19:27:00.000-08:002011-12-14T19:27:51.280-08:00dayrangeWhile working on something else, I need to write a little utility function that returns a range of days. (When the <a href="http://weekly.golang.org/pkg/time/">new time package</a> make it to release, this should be much simpler).<br />
<br />
<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/dayrange.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-36801829176544607242011-12-06T14:46:00.001-08:002011-12-06T14:49:23.914-08:00AppEngine Demo - URL Shortener<a href="https://bitbucket.org/tebeka/go-wise/src/22959b53f566/appengine-demo">Here</a> you can find a small <a href="http://code.google.com/appengine/docs/go/overview.html">AppEngine</a> Go example.It is a URL shortener (like <a href="http://bit.ly/">bit.ly</a>). I shows the following capabilities:<br />
<ul>
<li>HTTP Serving</li>
<li>Templates</li>
<li>Datastore</li>
<li>Task Queue</li>
<li>Logging</li>
<li>Memcache</li>
</ul>
Below is the main application code:
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/appengine-demo/shortie/shortie.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com2tag:blogger.com,1999:blog-2115939104238410881.post-39105936646088170822011-11-27T10:18:00.001-08:002011-11-27T10:21:16.405-08:00Reversim InterviewHad great fun talking about Go with Ran and Ori at <a href="http://www.reversim.com/">Reversim</a>.<br />
You can listen to the podcast <a href="http://www.reversim.com/2011/11/118-go-lang-with-miki-tebeka.html">here</a> (note: it's in Hebrew).Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-68674990998255377502011-11-08T16:28:00.000-08:002011-11-08T16:33:36.351-08:00A simple atexit libraryGo does not have an <span style="font-family: "Courier New",Courier,monospace;">atexit</span> library (<a href="https://groups.google.com/forum/#%21msg/golang-nuts/qBQ0bK2zvQA/vmOu9uhkYH0J">and will probably never have</a>). Below is a small implementation of such a <a href="https://bitbucket.org/tebeka/atexit">library</a>. Note that you have to use <span style="font-family: "Courier New",Courier,monospace;">atexit.Exit</span> and not <span style="font-family: "Courier New",Courier,monospace;">os.Exit</span> in your program.<br />
<br />
As usual, you can install with <span style="font-family: "Courier New",Courier,monospace;">goinstall bitbucket.org/tebeka/atexit</span><br />
<script src="https://bitbucket.org/tebeka/atexit/src/tip/atexit.go?embed=t"></script>
And here is an example program (the funky import is due to running this program as a test in the source directory)
<script src="https://bitbucket.org/tebeka/atexit/src/tip/testprog.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-66452518921627008692011-10-24T19:45:00.000-07:002011-10-24T19:45:28.421-07:00expvarThe <a href="http://golang.org/pkg/expvar/">expvar</a> let you expose variables via HTTP/JSON protocol. Here at Adconion we call these metrics, and more than once they have been very instrumental in debugging and monitoring services.<br />
<br />
We usually combine the metrics with an external monitoring system such as <a href="http://www.nagios.org/">Nagios</a> or <a href="http://www.opennms.org/">OpenNMS</a>. We set some thresholds for alerts and also chart some of them metrics over time.<br />
<br />
Below is a small demo on how to use the package.<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/expvar-demo.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com1tag:blogger.com,1999:blog-2115939104238410881.post-22977041709679150272011-10-20T09:28:00.000-07:002011-10-20T09:28:15.521-07:00Network programming with Go<a href="http://jan.newmarch.name/golang/">Network programming with Go</a> is a nice into. It also has a <a href="http://jan.newmarch.name/golang/template/chapter.html">great chapter</a> explaining the new template package.Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com2tag:blogger.com,1999:blog-2115939104238410881.post-43243461567445691682011-10-11T17:43:00.000-07:002011-10-11T17:43:42.459-07:00Number → English<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8ODfIEE_gnKPOYO3oGUD76EJbt-E6YikNH2-mWRhDxvKk5avUx8Y1wyF7K0XcowqF0F64-4dkhXvJIgoi7XdpS-ezhx99ey2H1_IAVXnxK1QYXdTUoLO1A4Bw1_GBzGaPOwru7hRLwmY/s1600/num2eng.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="110" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8ODfIEE_gnKPOYO3oGUD76EJbt-E6YikNH2-mWRhDxvKk5avUx8Y1wyF7K0XcowqF0F64-4dkhXvJIgoi7XdpS-ezhx99ey2H1_IAVXnxK1QYXdTUoLO1A4Bw1_GBzGaPOwru7hRLwmY/s320/num2eng.png" width="320" /></a></div>
Had some fun converting <a href="https://bitbucket.org/tebeka/pythonwise/src/tip/num2eng.py">num2eng.py</a> to Go and making it a web service.
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/num2eng.go?embed=t">
</script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-60718658410360613702011-10-07T15:30:00.000-07:002011-10-07T15:30:29.527-07:00Running Tests In ParallelAs of <a href="http://bit.ly/o42a3C">weekly.2011-10-06</a>, parallel testing is here. In order to have you test run in parallel, add a call to <span style="font-family: "Courier New",Courier,monospace;">t.Parallel()</span> at the top of your test function. Then run <span style="font-family: "Courier New",Courier,monospace;">gotest</span> with <span style="font-family: "Courier New",Courier,monospace;">--parallel N</span> (where N > 1).<br />
<br />
<span style="font-family: inherit;">T</span>hings to notice:<br />
<ul>
<li>A parallel test run in parallel only to other parallel tests. That means your non-parallel tests will run first and then your parallel ones.</li>
<li>A maximum of <span style="font-family: "Courier New",Courier,monospace;">--parallel</span> (a new <span style="font-family: "Courier New",Courier,monospace;">gotest</span> command line switch) tests will run in parallel.<span style="font-family: "Courier New",Courier,monospace;"> --parallel</span> defaults to <span style="font-family: "Courier New",Courier,monospace;">runtime.GOMAXPROCS(0)</span> which is 1. This means the if you don't specify <span style="font-family: "Courier New",Courier,monospace;">--parallel</span>, your parallel tests will run one at a time.</li>
</ul>
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/parallel_test.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-5932317209945833872011-09-26T16:02:00.000-07:002011-09-26T16:03:03.690-07:00Simulate event with closing a channelrog <a href="http://bit.ly/rdKYkT">had showed me</a> a nice way to synchronise several goroutines (something like an event) by closing a channel. Here's a code example:
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/multisync.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-18536429507716015982011-09-19T15:44:00.000-07:002011-09-19T15:44:14.146-07:00Parallel Map<script src="https://bitbucket.org/tebeka/go-wise/src/tip/pmap.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-91551475799083506042011-09-16T06:38:00.000-07:002011-09-16T06:38:15.073-07:00Copy Directory Tree<a href="http://golang.org/pkg/path/filepath/#Walk">filepath.Walk</a> is a very useful function. Here's how you can use it to copy a directory tree:<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/cptree.go?embed=t"></script>Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com0tag:blogger.com,1999:blog-2115939104238410881.post-44107786230719718332011-09-13T20:04:00.000-07:002011-09-13T20:04:26.674-07:00Go on HadoopIt's easy to use Go (or any other language) with<a href="http://hadoop.apache.org/mapreduce/docs/current/streaming.html"> Hadoop streaming</a>. Here's a little "word count" example.<br />
<br />
System Setup:<br />
<ul>
<li>Hadoop running locally (Cloudera cdh3u0)</li>
<li>A copy of hadoop-streaming-0.20.2-cdh3u0.jar in local directory</li>
<li>Copy of "<a href="http://www.gutenberg.org/ebooks/11">Alice In Wonderland</a>" under /user/miki/alice.txt on HDFS</li>
</ul>
mapper.go<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/mapper.go?embed=t">
</script>
<br />
reducer.go<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/reducer.go?embed=t">
</script>
<br />
run-job.sh<br />
<script src="https://bitbucket.org/tebeka/go-wise/src/tip/run-job.sh?embed=t">
</script>
<br />
After the job has ran, you can view the output and check the most common words: <br />
<code></code><br />
<pre><code>hadoop fs -cat /user/miki/words-out/part-00000 | sort -k 2 -n -r | head
the 1686
and 869
to 799
a 672
of 606
I 545
it 540
she 509
said 456
in 414
</code></pre>
Miki Tebekahttp://www.blogger.com/profile/03296782049507092947noreply@blogger.com35