Checking in vendor folder for ease of using go get.
This commit is contained in:
parent
7a1251853b
commit
cdb4b5a1d0
3554 changed files with 1270116 additions and 0 deletions
102
vendor/git.apache.org/thrift.git/tutorial/go/src/client.go
generated
vendored
Normal file
102
vendor/git.apache.org/thrift.git/tutorial/go/src/client.go
generated
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
func handleClient(client *tutorial.CalculatorClient) (err error) {
|
||||
client.Ping()
|
||||
fmt.Println("ping()")
|
||||
|
||||
sum, _ := client.Add(1, 1)
|
||||
fmt.Print("1+1=", sum, "\n")
|
||||
|
||||
work := tutorial.NewWork()
|
||||
work.Op = tutorial.Operation_DIVIDE
|
||||
work.Num1 = 1
|
||||
work.Num2 = 0
|
||||
quotient, err := client.Calculate(1, work)
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case *tutorial.InvalidOperation:
|
||||
fmt.Println("Invalid operation:", v)
|
||||
default:
|
||||
fmt.Println("Error during operation:", err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Whoa we can divide by 0 with new value:", quotient)
|
||||
}
|
||||
|
||||
work.Op = tutorial.Operation_SUBTRACT
|
||||
work.Num1 = 15
|
||||
work.Num2 = 10
|
||||
diff, err := client.Calculate(1, work)
|
||||
if err != nil {
|
||||
switch v := err.(type) {
|
||||
case *tutorial.InvalidOperation:
|
||||
fmt.Println("Invalid operation:", v)
|
||||
default:
|
||||
fmt.Println("Error during operation:", err)
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
fmt.Print("15-10=", diff, "\n")
|
||||
}
|
||||
|
||||
log, err := client.GetStruct(1)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to get struct:", err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("Check log:", log.Value)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
|
||||
var transport thrift.TTransport
|
||||
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
|
||||
}
|
||||
transport, err = transportFactory.GetTransport(transport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer transport.Close()
|
||||
if err := transport.Open(); err != nil {
|
||||
return err
|
||||
}
|
||||
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
|
||||
}
|
101
vendor/git.apache.org/thrift.git/tutorial/go/src/handler.go
generated
vendored
Normal file
101
vendor/git.apache.org/thrift.git/tutorial/go/src/handler.go
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"shared"
|
||||
"strconv"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
type CalculatorHandler struct {
|
||||
log map[int]*shared.SharedStruct
|
||||
}
|
||||
|
||||
func NewCalculatorHandler() *CalculatorHandler {
|
||||
return &CalculatorHandler{log: make(map[int]*shared.SharedStruct)}
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Ping() (err error) {
|
||||
fmt.Print("ping()\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Add(num1 int32, num2 int32) (retval17 int32, err error) {
|
||||
fmt.Print("add(", num1, ",", num2, ")\n")
|
||||
return num1 + num2, nil
|
||||
}
|
||||
|
||||
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:
|
||||
val = w.Num1 + w.Num2
|
||||
break
|
||||
case tutorial.Operation_SUBTRACT:
|
||||
val = w.Num1 - w.Num2
|
||||
break
|
||||
case tutorial.Operation_MULTIPLY:
|
||||
val = w.Num1 * w.Num2
|
||||
break
|
||||
case tutorial.Operation_DIVIDE:
|
||||
if w.Num2 == 0 {
|
||||
ouch := tutorial.NewInvalidOperation()
|
||||
ouch.WhatOp = int32(w.Op)
|
||||
ouch.Why = "Cannot divide by 0"
|
||||
err = ouch
|
||||
return
|
||||
}
|
||||
val = w.Num1 / w.Num2
|
||||
break
|
||||
default:
|
||||
ouch := tutorial.NewInvalidOperation()
|
||||
ouch.WhatOp = int32(w.Op)
|
||||
ouch.Why = "Unknown operation"
|
||||
err = ouch
|
||||
return
|
||||
}
|
||||
entry := shared.NewSharedStruct()
|
||||
entry.Key = logid
|
||||
entry.Value = strconv.Itoa(int(val))
|
||||
k := int(logid)
|
||||
/*
|
||||
oldvalue, exists := p.log[k]
|
||||
if exists {
|
||||
fmt.Print("Replacing ", oldvalue, " with ", entry, " for key ", k, "\n")
|
||||
} else {
|
||||
fmt.Print("Adding ", entry, " for key ", k, "\n")
|
||||
}
|
||||
*/
|
||||
p.log[k] = entry
|
||||
return val, err
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) GetStruct(key int32) (*shared.SharedStruct, error) {
|
||||
fmt.Print("getStruct(", key, ")\n")
|
||||
v, _ := p.log[int(key)]
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (p *CalculatorHandler) Zip() (err error) {
|
||||
fmt.Print("zip()\n")
|
||||
return nil
|
||||
}
|
82
vendor/git.apache.org/thrift.git/tutorial/go/src/main.go
generated
vendored
Normal file
82
vendor/git.apache.org/thrift.git/tutorial/go/src/main.go
generated
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Usage() {
|
||||
fmt.Fprint(os.Stderr, "Usage of ", os.Args[0], ":\n")
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprint(os.Stderr, "\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = Usage
|
||||
server := flag.Bool("server", false, "Run server")
|
||||
protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
|
||||
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()
|
||||
|
||||
var protocolFactory thrift.TProtocolFactory
|
||||
switch *protocol {
|
||||
case "compact":
|
||||
protocolFactory = thrift.NewTCompactProtocolFactory()
|
||||
case "simplejson":
|
||||
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
|
||||
case "json":
|
||||
protocolFactory = thrift.NewTJSONProtocolFactory()
|
||||
case "binary", "":
|
||||
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
|
||||
default:
|
||||
fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
|
||||
Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var transportFactory thrift.TTransportFactory
|
||||
if *buffered {
|
||||
transportFactory = thrift.NewTBufferedTransportFactory(8192)
|
||||
} else {
|
||||
transportFactory = thrift.NewTTransportFactory()
|
||||
}
|
||||
|
||||
if *framed {
|
||||
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
|
||||
}
|
||||
|
||||
if *server {
|
||||
if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
|
||||
fmt.Println("error running server:", err)
|
||||
}
|
||||
} else {
|
||||
if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
|
||||
fmt.Println("error running client:", err)
|
||||
}
|
||||
}
|
||||
}
|
54
vendor/git.apache.org/thrift.git/tutorial/go/src/server.go
generated
vendored
Normal file
54
vendor/git.apache.org/thrift.git/tutorial/go/src/server.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"git.apache.org/thrift.git/lib/go/thrift"
|
||||
"tutorial"
|
||||
)
|
||||
|
||||
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 ", addr)
|
||||
return server.Serve()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue