You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/02/05 21:34:16 UTC
svn commit: r1564918 - in /thrift/site: content/tutorial/go.md
publish/tutorial/go/index.html
Author: jensg
Date: Wed Feb 5 20:34:16 2014
New Revision: 1564918
URL: http://svn.apache.org/r1564918
Log:
Updated Go tutorial according to THRIFT-2349
Modified:
thrift/site/content/tutorial/go.md
thrift/site/publish/tutorial/go/index.html
Modified: thrift/site/content/tutorial/go.md
URL: http://svn.apache.org/viewvc/thrift/site/content/tutorial/go.md?rev=1564918&r1=1564917&r2=1564918&view=diff
==============================================================================
--- thrift/site/content/tutorial/go.md (original)
+++ thrift/site/content/tutorial/go.md Wed Feb 5 20:34:16 2014
@@ -15,6 +15,7 @@ Implements the client code which consume
<pre><code class="language-c">
import (
+ "crypto/tls"
"fmt"
"git.apache.org/thrift.git/lib/go/thrift"
"tutorial"
@@ -31,12 +32,15 @@ func handleClient(client *tutorial.Calcu
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 1
work.Num2 = 0
- quotient, ouch, err := client.Calculate(1, work)
+ quotient, err := client.Calculate(1, work)
if err != nil {
- fmt.Println("Error during operation:", err)
+ switch v := err.(type) {
+ case *tutorial.InvalidOperation:
+ fmt.Println("Invalid operation:", v)
+ default:
+ fmt.Println("Error during operation:", err)
+ }
return err
- } else if ouch != nil {
- fmt.Println("Invalid operation:", ouch)
} else {
fmt.Println("Whoa we can divide by 0 with new value:", quotient)
}
@@ -44,12 +48,15 @@ func handleClient(client *tutorial.Calcu
work.Op = tutorial.Operation_SUBTRACT
work.Num1 = 15
work.Num2 = 10
- diff, ouch, err := client.Calculate(1, work)
+ diff, err := client.Calculate(1, work)
if err != nil {
- fmt.Println("Error during operation:", err)
+ switch v := err.(type) {
+ case *tutorial.InvalidOperation:
+ fmt.Println("Invalid operation:", v)
+ default:
+ fmt.Println("Error during operation:", err)
+ }
return err
- } else if ouch != nil {
- fmt.Println("Invalid operation:", ouch)
} else {
fmt.Print("15-10=", diff, "\n")
}
@@ -64,9 +71,16 @@ func handleClient(client *tutorial.Calcu
return err
}
-func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
+func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
- transport, err := thrift.NewTSocket(addr)
+ var err error
+ if secure {
+ cfg := new(tls.Config)
+ cfg.InsecureSkipVerify = true
+ transport, err = thrift.NewTSSLSocket(addr, cfg)
+ } else {
+ transport, err = thrift.NewTSocket(addr)
+ }
if err != nil {
fmt.Println("Error opening socket:", err)
return err
@@ -86,21 +100,36 @@ Implements a simple socket server.
<pre><code class="language-c">
import (
+ "crypto/tls"
"fmt"
"git.apache.org/thrift.git/lib/go/thrift"
"tutorial"
)
-func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
- transport, err := thrift.NewTServerSocket(addr)
+func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
+ var transport thrift.TServerTransport
+ var err error
+ if secure {
+ cfg := new(tls.Config)
+ if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err == nil {
+ cfg.Certificates = append(cfg.Certificates, cert)
+ } else {
+ return err
+ }
+ transport, err = thrift.NewTSSLServerSocket(addr, cfg)
+ } else {
+ transport, err = thrift.NewTServerSocket(addr)
+ }
+
if err != nil {
return err
}
+ fmt.Printf("%T\n", transport)
handler := NewCalculatorHandler()
processor := tutorial.NewCalculatorProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
- fmt.Println("Starting the simple server... on ", transport.Addr())
+ fmt.Println("Starting the simple server... on ", addr)
return server.Serve()
}
</code></pre>
@@ -136,7 +165,7 @@ func (p *CalculatorHandler) Add(num1 int
return num1 + num2, nil
}
-func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, ouch *tutorial.InvalidOperation, err error) {
+func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, err error) {
fmt.Print("calculate(", logid, ", {", w.Op, ",", w.Num1, ",", w.Num2, "})\n")
switch w.Op {
case tutorial.Operation_ADD:
@@ -150,17 +179,19 @@ func (p *CalculatorHandler) Calculate(lo
break
case tutorial.Operation_DIVIDE:
if w.Num2 == 0 {
- ouch = tutorial.NewInvalidOperation()
+ ouch := tutorial.NewInvalidOperation()
ouch.What = int32(w.Op)
ouch.Why = "Cannot divide by 0"
+ err = ouch
return
}
val = w.Num1 / w.Num2
break
default:
- ouch = tutorial.NewInvalidOperation()
+ ouch := tutorial.NewInvalidOperation()
ouch.What = int32(w.Op)
ouch.Why = "Unknown operation"
+ err = ouch
return
}
entry := shared.NewSharedStruct()
@@ -169,7 +200,7 @@ func (p *CalculatorHandler) Calculate(lo
k := int(logid)
p.log[k] = entry
- return val, ouch, err
+ return val, err
}
func (p *CalculatorHandler) GetStruct(key int32) (*shared.SharedStruct, error) {
@@ -205,10 +236,11 @@ func Usage() {
func main() {
flag.Usage = Usage
server := flag.Bool("server", false, "Run server")
- protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, simplejson)")
+ protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json)")
framed := flag.Bool("framed", false, "Use framed transport")
buffered := flag.Bool("buffered", false, "Use buffered transport")
addr := flag.String("addr", "localhost:9090", "Address to listen to")
+ secure := flag.Bool("secure", false, "Use tls secure transport")
flag.Parse()
@@ -216,8 +248,6 @@ func main() {
switch *protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
- case "simplejson":
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
@@ -240,11 +270,11 @@ func main() {
}
if *server {
- if err := runServer(transportFactory, protocolFactory, *addr); err != nil {
+ if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running server:", err)
}
} else {
- if err := runClient(transportFactory, protocolFactory, *addr); err != nil {
+ if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println("error running client:", err)
}
}
Modified: thrift/site/publish/tutorial/go/index.html
URL: http://svn.apache.org/viewvc/thrift/site/publish/tutorial/go/index.html?rev=1564918&r1=1564917&r2=1564918&view=diff
==============================================================================
--- thrift/site/publish/tutorial/go/index.html (original)
+++ thrift/site/publish/tutorial/go/index.html Wed Feb 5 20:34:16 2014
@@ -68,7 +68,9 @@
<div class="container">
<h2>Go Tutorial</h2>
-<hr><h3>Introduction</h3>
+<hr>
+
+<h3>Introduction</h3>
<p>All Apache Thrift tutorials require that you have:</p>
@@ -81,16 +83,21 @@
</code></pre>
</li>
<li><p>Followed all prerequesets listed </p></li>
-</ol><h3>Prerequisites</h3>
+</ol>
+
+<h3>Prerequisites</h3>
<ul>
<li>At least Go 1.1.x is required to run the tutorial code. </li>
<li>The GOPATH may need to be adjusted, alternatively manually put the Go Thrift library files into a suitable location. </li>
-</ul><h3>Client</h3>
+</ul>
+
+<h3>Client</h3>
<p>Implements the client code which consumes the tutorial service.</p>
<div class="CodeRay"><div class="code"><pre><code class="language-c">import (
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">crypto/tls</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">fmt</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">git.apache.org/thrift.git/lib/go/thrift</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">tutorial</span><span style="color:#710">"</span></span>
@@ -107,12 +114,15 @@ func handleClient(client *tutorial.Calcu
work.Op = tutorial.Operation_DIVIDE
work.Num1 = <span style="color:#00D">1</span>
work.Num2 = <span style="color:#00D">0</span>
- quotient, ouch, err := client.Calculate(<span style="color:#00D">1</span>, work)
+ quotient, err := client.Calculate(<span style="color:#00D">1</span>, work)
<span style="color:#080;font-weight:bold">if</span> err != nil {
- fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Error during operation:</span><span style="color:#710">"</span></span>, err)
+ <span style="color:#080;font-weight:bold">switch</span> v := err.(type) {
+ <span style="color:#080;font-weight:bold">case</span> *tutorial.InvalidOperation:
+ fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid operation:</span><span style="color:#710">"</span></span>, v)
+ <span style="color:#080;font-weight:bold">default</span>:
+ fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Error during operation:</span><span style="color:#710">"</span></span>, err)
+ }
<span style="color:#080;font-weight:bold">return</span> err
- } <span style="color:#080;font-weight:bold">else</span> <span style="color:#080;font-weight:bold">if</span> ouch != nil {
- fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid operation:</span><span style="color:#710">"</span></span>, ouch)
} <span style="color:#080;font-weight:bold">else</span> {
fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Whoa we can divide by 0 with new value:</span><span style="color:#710">"</span></span>, quotient)
}
@@ -120,12 +130,15 @@ func handleClient(client *tutorial.Calcu
work.Op = tutorial.Operation_SUBTRACT
work.Num1 = <span style="color:#00D">15</span>
work.Num2 = <span style="color:#00D">10</span>
- diff, ouch, err := client.Calculate(<span style="color:#00D">1</span>, work)
+ diff, err := client.Calculate(<span style="color:#00D">1</span>, work)
<span style="color:#080;font-weight:bold">if</span> err != nil {
- fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Error during operation:</span><span style="color:#710">"</span></span>, err)
+ <span style="color:#080;font-weight:bold">switch</span> v := err.(type) {
+ <span style="color:#080;font-weight:bold">case</span> *tutorial.InvalidOperation:
+ fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid operation:</span><span style="color:#710">"</span></span>, v)
+ <span style="color:#080;font-weight:bold">default</span>:
+ fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Error during operation:</span><span style="color:#710">"</span></span>, err)
+ }
<span style="color:#080;font-weight:bold">return</span> err
- } <span style="color:#080;font-weight:bold">else</span> <span style="color:#080;font-weight:bold">if</span> ouch != nil {
- fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Invalid operation:</span><span style="color:#710">"</span></span>, ouch)
} <span style="color:#080;font-weight:bold">else</span> {
fmt.Print(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">15-10=</span><span style="color:#710">"</span></span>, diff, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>)
}
@@ -140,9 +153,16 @@ func handleClient(client *tutorial.Calcu
<span style="color:#080;font-weight:bold">return</span> err
}
-func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
+func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure <span style="color:#0a5;font-weight:bold">bool</span>) error {
var transport thrift.TTransport
- transport, err := thrift.NewTSocket(addr)
+ var err error
+ <span style="color:#080;font-weight:bold">if</span> secure {
+ cfg := new(tls.Config)
+ cfg.InsecureSkipVerify = <span style="color:#069">true</span>
+ transport, err = thrift.NewTSSLSocket(addr, cfg)
+ } <span style="color:#080;font-weight:bold">else</span> {
+ transport, err = thrift.NewTSocket(addr)
+ }
<span style="color:#080;font-weight:bold">if</span> err != nil {
fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Error opening socket:</span><span style="color:#710">"</span></span>, err)
<span style="color:#080;font-weight:bold">return</span> err
@@ -160,21 +180,36 @@ func runClient(transportFactory thrift.T
<p>Implements a simple socket server.</p>
<div class="CodeRay"><div class="code"><pre><code class="language-c">import (
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">crypto/tls</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">fmt</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">git.apache.org/thrift.git/lib/go/thrift</span><span style="color:#710">"</span></span>
<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">tutorial</span><span style="color:#710">"</span></span>
)
-func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
- transport, err := thrift.NewTServerSocket(addr)
+func runServer(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure <span style="color:#0a5;font-weight:bold">bool</span>) error {
+ var transport thrift.TServerTransport
+ var err error
+ <span style="color:#080;font-weight:bold">if</span> secure {
+ cfg := new(tls.Config)
+ <span style="color:#080;font-weight:bold">if</span> cert, err := tls.LoadX509KeyPair(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">server.crt</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">server.key</span><span style="color:#710">"</span></span>); err == nil {
+ cfg.Certificates = append(cfg.Certificates, cert)
+ } <span style="color:#080;font-weight:bold">else</span> {
+ <span style="color:#080;font-weight:bold">return</span> err
+ }
+ transport, err = thrift.NewTSSLServerSocket(addr, cfg)
+ } <span style="color:#080;font-weight:bold">else</span> {
+ transport, err = thrift.NewTServerSocket(addr)
+ }
+
<span style="color:#080;font-weight:bold">if</span> err != nil {
<span style="color:#080;font-weight:bold">return</span> err
}
+ fmt.Printf(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">%T</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>, transport)
handler := NewCalculatorHandler()
processor := tutorial.NewCalculatorProcessor(handler)
server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
- fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the simple server... on </span><span style="color:#710">"</span></span>, transport.Addr())
+ fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Starting the simple server... on </span><span style="color:#710">"</span></span>, addr)
<span style="color:#080;font-weight:bold">return</span> server.Serve()
}</code></pre></div></div>
@@ -207,7 +242,7 @@ func (p *CalculatorHandler) Add(num1 int
<span style="color:#080;font-weight:bold">return</span> num1 + num2, nil
}
-func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, ouch *tutorial.InvalidOperation, err error) {
+func (p *CalculatorHandler) Calculate(logid int32, w *tutorial.Work) (val int32, err error) {
fmt.Print(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">calculate(</span><span style="color:#710">"</span></span>, logid, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">, {</span><span style="color:#710">"</span></span>, w.Op, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">,</span><span style="color:#710">"</span></span>, w.Num1, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">,</span><span style="color:#710">"</span></span>, w.Num2, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">})</span><span style="color:#b0b">\n</span><span style="color:#710">"</span></span>)
<span style="color:#080;font-weight:bold">switch</span> w.Op {
<span style="color:#080;font-weight:bold">case</span> tutorial.Operation_ADD:
@@ -221,17 +256,19 @@ func (p *CalculatorHandler) Calculate(lo
<span style="color:#080;font-weight:bold">break</span>
<span style="color:#080;font-weight:bold">case</span> tutorial.Operation_DIVIDE:
<span style="color:#080;font-weight:bold">if</span> w.Num2 == <span style="color:#00D">0</span> {
- ouch = tutorial.NewInvalidOperation()
+ ouch := tutorial.NewInvalidOperation()
ouch.What = int32(w.Op)
ouch.Why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Cannot divide by 0</span><span style="color:#710">"</span></span>
+ err = ouch
<span style="color:#080;font-weight:bold">return</span>
}
val = w.Num1 / w.Num2
<span style="color:#080;font-weight:bold">break</span>
<span style="color:#080;font-weight:bold">default</span>:
- ouch = tutorial.NewInvalidOperation()
+ ouch := tutorial.NewInvalidOperation()
ouch.What = int32(w.Op)
ouch.Why = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Unknown operation</span><span style="color:#710">"</span></span>
+ err = ouch
<span style="color:#080;font-weight:bold">return</span>
}
entry := shared.NewSharedStruct()
@@ -240,7 +277,7 @@ func (p *CalculatorHandler) Calculate(lo
k := <span style="color:#0a5;font-weight:bold">int</span>(logid)
p.log[k] = entry
- <span style="color:#080;font-weight:bold">return</span> val, ouch, err
+ <span style="color:#080;font-weight:bold">return</span> val, err
}
func (p *CalculatorHandler) GetStruct(key int32) (*shared.SharedStruct, error) {
@@ -274,10 +311,11 @@ func Usage() {
func main() {
flag.Usage = Usage
server := flag.Bool(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">server</span><span style="color:#710">"</span></span>, <span style="color:#069">false</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Run server</span><span style="color:#710">"</span></span>)
- protocol := flag.String(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">P</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">binary</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Specify the protocol (binary, compact, simplejson)</span><span style="color:#710">"</span></span>)
+ protocol := flag.String(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">P</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">binary</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Specify the protocol (binary, compact, json)</span><span style="color:#710">"</span></span>)
framed := flag.Bool(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">framed</span><span style="color:#710">"</span></span>, <span style="color:#069">false</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Use framed transport</span><span style="color:#710">"</span></span>)
buffered := flag.Bool(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">buffered</span><span style="color:#710">"</span></span>, <span style="color:#069">false</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Use buffered transport</span><span style="color:#710">"</span></span>)
addr := flag.String(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">addr</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">localhost:9090</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Address to listen to</span><span style="color:#710">"</span></span>)
+ secure := flag.Bool(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">secure</span><span style="color:#710">"</span></span>, <span style="color:#069">false</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Use tls secure transport</span><span style="color:#710">"</span></span>)
flag.Parse()
@@ -285,8 +323,6 @@ func main() {
<span style="color:#080;font-weight:bold">switch</span> *protocol {
<span style="color:#080;font-weight:bold">case</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">compact</span><span style="color:#710">"</span></span>:
protocolFactory = thrift.NewTCompactProtocolFactory()
- <span style="color:#080;font-weight:bold">case</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">simplejson</span><span style="color:#710">"</span></span>:
- protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
<span style="color:#080;font-weight:bold">case</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">json</span><span style="color:#710">"</span></span>:
protocolFactory = thrift.NewTJSONProtocolFactory()
<span style="color:#080;font-weight:bold">case</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">binary</span><span style="color:#710">"</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#710">"</span></span>:
@@ -309,11 +345,11 @@ func main() {
}
<span style="color:#080;font-weight:bold">if</span> *server {
- <span style="color:#080;font-weight:bold">if</span> err := runServer(transportFactory, protocolFactory, *addr); err != nil {
+ <span style="color:#080;font-weight:bold">if</span> err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">error running server:</span><span style="color:#710">"</span></span>, err)
}
} <span style="color:#080;font-weight:bold">else</span> {
- <span style="color:#080;font-weight:bold">if</span> err := runClient(transportFactory, protocolFactory, *addr); err != nil {
+ <span style="color:#080;font-weight:bold">if</span> err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
fmt.Println(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">error running client:</span><span style="color:#710">"</span></span>, err)
}
}
@@ -326,6 +362,7 @@ func main() {
<li>Try using the buffered and/or framed transport options.</li>
<li>Note that both server and client must use the exact same protocol and transport stack.</li>
</ul>
+
</div>
<div class="container">
<hr>