github.com/uuosio/chaintester@v0.0.0-20230731100329-1f6fad7372e5/interfaces/push_actions-remote/push_actions-remote.go (about) 1 // Code generated by Thrift Compiler (0.15.0). DO NOT EDIT. 2 3 package main 4 5 import ( 6 "context" 7 "flag" 8 "fmt" 9 "math" 10 "net" 11 "net/url" 12 "os" 13 "strconv" 14 "strings" 15 thrift "github.com/apache/thrift/lib/go/thrift" 16 "interfaces" 17 ) 18 19 var _ = interfaces.GoUnusedProtection__ 20 21 func Usage() { 22 fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") 23 flag.PrintDefaults() 24 fmt.Fprintln(os.Stderr, "\nFunctions:") 25 fmt.Fprintln(os.Stderr, " i32 push_actions( actions)") 26 fmt.Fprintln(os.Stderr) 27 os.Exit(0) 28 } 29 30 type httpHeaders map[string]string 31 32 func (h httpHeaders) String() string { 33 var m map[string]string = h 34 return fmt.Sprintf("%s", m) 35 } 36 37 func (h httpHeaders) Set(value string) error { 38 parts := strings.Split(value, ": ") 39 if len(parts) != 2 { 40 return fmt.Errorf("header should be of format 'Key: Value'") 41 } 42 h[parts[0]] = parts[1] 43 return nil 44 } 45 46 func main() { 47 flag.Usage = Usage 48 var host string 49 var port int 50 var protocol string 51 var urlString string 52 var framed bool 53 var useHttp bool 54 headers := make(httpHeaders) 55 var parsedUrl *url.URL 56 var trans thrift.TTransport 57 _ = strconv.Atoi 58 _ = math.Abs 59 flag.Usage = Usage 60 flag.StringVar(&host, "h", "localhost", "Specify host and port") 61 flag.IntVar(&port, "p", 9090, "Specify port") 62 flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") 63 flag.StringVar(&urlString, "u", "", "Specify the url") 64 flag.BoolVar(&framed, "framed", false, "Use framed transport") 65 flag.BoolVar(&useHttp, "http", false, "Use http") 66 flag.Var(headers, "H", "Headers to set on the http(s) request (e.g. -H \"Key: Value\")") 67 flag.Parse() 68 69 if len(urlString) > 0 { 70 var err error 71 parsedUrl, err = url.Parse(urlString) 72 if err != nil { 73 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 74 flag.Usage() 75 } 76 host = parsedUrl.Host 77 useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https" 78 } else if useHttp { 79 _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) 80 if err != nil { 81 fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) 82 flag.Usage() 83 } 84 } 85 86 cmd := flag.Arg(0) 87 var err error 88 var cfg *thrift.TConfiguration = nil 89 if useHttp { 90 trans, err = thrift.NewTHttpClient(parsedUrl.String()) 91 if len(headers) > 0 { 92 httptrans := trans.(*thrift.THttpClient) 93 for key, value := range headers { 94 httptrans.SetHeader(key, value) 95 } 96 } 97 } else { 98 portStr := fmt.Sprint(port) 99 if strings.Contains(host, ":") { 100 host, portStr, err = net.SplitHostPort(host) 101 if err != nil { 102 fmt.Fprintln(os.Stderr, "error with host:", err) 103 os.Exit(1) 104 } 105 } 106 trans = thrift.NewTSocketConf(net.JoinHostPort(host, portStr), cfg) 107 if err != nil { 108 fmt.Fprintln(os.Stderr, "error resolving address:", err) 109 os.Exit(1) 110 } 111 if framed { 112 trans = thrift.NewTFramedTransportConf(trans, cfg) 113 } 114 } 115 if err != nil { 116 fmt.Fprintln(os.Stderr, "Error creating transport", err) 117 os.Exit(1) 118 } 119 defer trans.Close() 120 var protocolFactory thrift.TProtocolFactory 121 switch protocol { 122 case "compact": 123 protocolFactory = thrift.NewTCompactProtocolFactoryConf(cfg) 124 break 125 case "simplejson": 126 protocolFactory = thrift.NewTSimpleJSONProtocolFactoryConf(cfg) 127 break 128 case "json": 129 protocolFactory = thrift.NewTJSONProtocolFactory() 130 break 131 case "binary", "": 132 protocolFactory = thrift.NewTBinaryProtocolFactoryConf(cfg) 133 break 134 default: 135 fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) 136 Usage() 137 os.Exit(1) 138 } 139 iprot := protocolFactory.GetProtocol(trans) 140 oprot := protocolFactory.GetProtocol(trans) 141 client := interfaces.NewPushActionsClient(thrift.NewTStandardClient(iprot, oprot)) 142 if err := trans.Open(); err != nil { 143 fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) 144 os.Exit(1) 145 } 146 147 switch cmd { 148 case "push_actions": 149 if flag.NArg() - 1 != 1 { 150 fmt.Fprintln(os.Stderr, "PushActions requires 1 args") 151 flag.Usage() 152 } 153 arg151 := flag.Arg(1) 154 mbTrans152 := thrift.NewTMemoryBufferLen(len(arg151)) 155 defer mbTrans152.Close() 156 _, err153 := mbTrans152.WriteString(arg151) 157 if err153 != nil { 158 Usage() 159 return 160 } 161 factory154 := thrift.NewTJSONProtocolFactory() 162 jsProt155 := factory154.GetProtocol(mbTrans152) 163 containerStruct0 := interfaces.NewPushActionsPushActionsArgs() 164 err156 := containerStruct0.ReadField1(context.Background(), jsProt155) 165 if err156 != nil { 166 Usage() 167 return 168 } 169 argvalue0 := containerStruct0.Actions 170 value0 := argvalue0 171 fmt.Print(client.PushActions(context.Background(), value0)) 172 fmt.Print("\n") 173 break 174 case "": 175 Usage() 176 break 177 default: 178 fmt.Fprintln(os.Stderr, "Invalid function ", cmd) 179 } 180 }