Author: buildbot Date: Fri Dec 4 19:47:13 2015 New Revision: 974573 Log: Staging update by buildbot for thrift
Modified: websites/staging/thrift/trunk/content/ (props changed) websites/staging/thrift/trunk/content/tutorial/go.html Propchange: websites/staging/thrift/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Fri Dec 4 19:47:13 2015 @@ -1 +1 @@ -1717100 +1718014 Modified: websites/staging/thrift/trunk/content/tutorial/go.html ============================================================================== --- websites/staging/thrift/trunk/content/tutorial/go.html (original) +++ websites/staging/thrift/trunk/content/tutorial/go.html Fri Dec 4 19:47:13 2015 @@ -257,6 +257,106 @@ h2:hover > .headerlink, h3:hover > .head <a href="http://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=tutorial/go/src/server.go;hb=HEAD"</a>tutorial/go/src/server.go</a> </p> +<h3 id="server-handler">Server Handler<a class="headerlink" href="#server-handler" title="Permanent link">¶</a></h3> +<style type="text/css"> +/* The following code is added by mdx_elementid.py + It was originally lifted from http://subversion.apache.org/style/site.css */ +/* + * Hide class="elementid-permalink", except when an enclosing heading + * has the :hover property. + */ +.headerlink, .elementid-permalink { + visibility: hidden; +} +h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> + +<div class="codehilite"><pre><span class="n">import</span> <span class="p">(</span> + <span class="s">"fmt"</span> + <span class="s">"shared"</span> + <span class="s">"strconv"</span> + <span class="s">"tutorial"</span> +<span class="p">)</span> + +<span class="n">type</span> <span class="n">CalculatorHandler</span> <span class="k">struct</span> <span class="p">{</span> + <span class="n">log</span> <span class="n">map</span><span class="p">[</span><span class="kt">int</span><span class="p">]</span><span class="o">*</span><span class="n">shared</span><span class="p">.</span><span class="n">SharedStruct</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="n">NewCalculatorHandler</span><span class="p">()</span> <span class="o">*</span><span class="n">CalculatorHandler</span> <span class="p">{</span> + <span class="k">return</span> <span class="o">&</span><span class="n">CalculatorHandler</span><span class="p">{</span><span class="nl">log:</span> <span class="n">make</span><span class="p">(</span><span class="n">map</span><span class="p">[</span><span class="kt">int</span><span class="p">]</span><span class="o">*</span><span class="n">shared</span><span class="p">.</span><span class="n">SharedStruct</span><span class="p">)}</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">CalculatorHandler</span><span class="p">)</span> <span class="n">Ping</span><span class="p">()</span> <span class="p">(</span><span class="n">err</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span> + <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">"ping()</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> + <span class="k">return</span> <span class="n">nil</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">CalculatorHandler</span><span class="p">)</span> <span class="n">Add</span><span class="p">(</span><span class="n">num1</span> <span class="n">int32</span><span class="p">,</span> <span class="n">num2</span> <span class="n">int32</span><span class="p">)</span> <span class="p">(</span><span class="n">retval17</span> <span class="n">int32</span><span class="p">,</span> <span class="n">err</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span> + <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">"add("</span><span class="p">,</span> <span class="n">num1</span><span class="p">,</span> <span class="s">","</span><span class="p">,</span> <span class="n">num2</span><span class="p">,</span> <span class="s">")</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> + <span class="k">return</span> <span class="n">num1</span> <span class="o">+</span> <span class="n">num2</span><span class="p">,</span> <span class="n">nil</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">CalculatorHandler</span><span class="p">)</span> <span class="n">Calculate</span><span class="p">(</span><span class="n">logid</span> <span class="n">int32</span><span class="p">,</span> <span class="n">w</span> <span class="o">*</span><span class="n">tutorial</span><span class="p">.</span><span class="n">Work</span><span class="p">)</span> <span class="p">(</span><span class="n">val</span> <span class="n">int32</span><span class="p">,</span> <span class="n">err</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span> + <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">"calculate("</span><span class="p">,</span> <span class="n">logid</span><span class="p">,</span> <span class="s">", {"</span><span class="p">,</span> <span class="n">w</span><span class="p">.</span><span class="n">Op</span><span class="p">,</span> <span class="s">","</span><span class="p">,</span> <span class="n">w</span><span class="p">.</span><span class="n">Num1</span><span class="p">,</span> <span class="s">","</span><span class="p">,</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span><span class="p">,</span> <span class="s">"})</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> + <span class="k">switch</span> <span class="n">w</span><span class="p">.</span><span class="n">Op</span> <span class="p">{</span> + <span class="k">case</span> <span class="n">tutorial</span><span class="p">.</span><span class="nl">Operation_ADD:</span> + <span class="n">val</span> <span class="o">=</span> <span class="n">w</span><span class="p">.</span><span class="n">Num1</span> <span class="o">+</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span> + <span class="k">break</span> + <span class="k">case</span> <span class="n">tutorial</span><span class="p">.</span><span class="nl">Operation_SUBTRACT:</span> + <span class="n">val</span> <span class="o">=</span> <span class="n">w</span><span class="p">.</span><span class="n">Num1</span> <span class="o">-</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span> + <span class="k">break</span> + <span class="k">case</span> <span class="n">tutorial</span><span class="p">.</span><span class="nl">Operation_MULTIPLY:</span> + <span class="n">val</span> <span class="o">=</span> <span class="n">w</span><span class="p">.</span><span class="n">Num1</span> <span class="o">*</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span> + <span class="k">break</span> + <span class="k">case</span> <span class="n">tutorial</span><span class="p">.</span><span class="nl">Operation_DIVIDE:</span> + <span class="k">if</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">{</span> + <span class="n">ouch</span> <span class="o">:=</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">NewInvalidOperation</span><span class="p">()</span> + <span class="n">ouch</span><span class="p">.</span><span class="n">WhatOp</span> <span class="o">=</span> <span class="n">int32</span><span class="p">(</span><span class="n">w</span><span class="p">.</span><span class="n">Op</span><span class="p">)</span> + <span class="n">ouch</span><span class="p">.</span><span class="n">Why</span> <span class="o">=</span> <span class="s">"Cannot divide by 0"</span> + <span class="n">err</span> <span class="o">=</span> <span class="n">ouch</span> + <span class="k">return</span> + <span class="p">}</span> + <span class="n">val</span> <span class="o">=</span> <span class="n">w</span><span class="p">.</span><span class="n">Num1</span> <span class="o">/</span> <span class="n">w</span><span class="p">.</span><span class="n">Num2</span> + <span class="k">break</span> + <span class="k">default</span><span class="o">:</span> + <span class="n">ouch</span> <span class="o">:=</span> <span class="n">tutorial</span><span class="p">.</span><span class="n">NewInvalidOperation</span><span class="p">()</span> + <span class="n">ouch</span><span class="p">.</span><span class="n">WhatOp</span> <span class="o">=</span> <span class="n">int32</span><span class="p">(</span><span class="n">w</span><span class="p">.</span><span class="n">Op</span><span class="p">)</span> + <span class="n">ouch</span><span class="p">.</span><span class="n">Why</span> <span class="o">=</span> <span class="s">"Unknown operation"</span> + <span class="n">err</span> <span class="o">=</span> <span class="n">ouch</span> + <span class="k">return</span> + <span class="p">}</span> + <span class="n">entry</span> <span class="o">:=</span> <span class="n">shared</span><span class="p">.</span><span class="n">NewSharedStruct</span><span class="p">()</span> + <span class="n">entry</span><span class="p">.</span><span class="n">Key</span> <span class="o">=</span> <span class="n">logid</span> + <span class="n">entry</span><span class="p">.</span><span class="n">Value</span> <span class="o">=</span> <span class="n">strconv</span><span class="p">.</span><span class="n">Itoa</span><span class="p">(</span><span class="kt">int</span><span class="p">(</span><span class="n">val</span><span class="p">))</span> + <span class="n">k</span> <span class="o">:=</span> <span class="kt">int</span><span class="p">(</span><span class="n">logid</span><span class="p">)</span> + <span class="cm">/*</span> +<span class="cm"> oldvalue, exists := p.log[k]</span> +<span class="cm"> if exists {</span> +<span class="cm"> fmt.Print("Replacing ", oldvalue, " with ", entry, " for key ", k, "\n")</span> +<span class="cm"> } else {</span> +<span class="cm"> fmt.Print("Adding ", entry, " for key ", k, "\n")</span> +<span class="cm"> }</span> +<span class="cm"> */</span> + <span class="n">p</span><span class="p">.</span><span class="n">log</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">entry</span> + <span class="k">return</span> <span class="n">val</span><span class="p">,</span> <span class="n">err</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">CalculatorHandler</span><span class="p">)</span> <span class="n">GetStruct</span><span class="p">(</span><span class="n">key</span> <span class="n">int32</span><span class="p">)</span> <span class="p">(</span><span class="o">*</span><span class="n">shared</span><span class="p">.</span><span class="n">SharedStruct</span><span class="p">,</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span> + <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">"getStruct("</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="s">")</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> + <span class="n">v</span><span class="p">,</span> <span class="n">_</span> <span class="o">:=</span> <span class="n">p</span><span class="p">.</span><span class="n">log</span><span class="p">[</span><span class="kt">int</span><span class="p">(</span><span class="n">key</span><span class="p">)]</span> + <span class="k">return</span> <span class="n">v</span><span class="p">,</span> <span class="n">nil</span> +<span class="p">}</span> + +<span class="n">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">CalculatorHandler</span><span class="p">)</span> <span class="n">Zip</span><span class="p">()</span> <span class="p">(</span><span class="n">err</span> <span class="n">error</span><span class="p">)</span> <span class="p">{</span> + <span class="n">fmt</span><span class="p">.</span><span class="n">Print</span><span class="p">(</span><span class="s">"zip()</span><span class="se">\n</span><span class="s">"</span><span class="p">)</span> + <span class="k">return</span> <span class="n">nil</span> +<span class="p">}</span> +</pre></div> + +<p class='snippet_footer'> + This snippet was generated by Apache Thrift's <strong>source tree docs</strong>: + <a href="http://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=tutorial/go/src/handler.go;hb=HEAD"</a>tutorial/go/src/handler.go</a> +</p> + <h2 id="additional-information">Additional Information<a class="headerlink" href="#additional-information" title="Permanent link">¶</a></h2> <ul> <li>Try using one of the other available protocols, default is binary.</li>