首页 > 其他分享 >Golang 构建 Apache thrift 应用

Golang 构建 Apache thrift 应用

时间:2023-02-20 15:46:23浏览次数:37  
标签:string Golang Version Apache 2.0 optional thrift

安装

去官网下载安装包,然后编译安装。

https://thrift.apache.org/download

./configure && make

当然如果我们使用了 MacOS 我们将可以方便的直接使用  Homebrew 进行安装

brew install thrift

 

编写一个 thrift 文件并 generate 出对应代码 code 

/*
 * Copyright (c) 2014-2022 Snowplow Analytics Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0, and
 * you may not use this file except in compliance with the Apache License
 * Version 2.0.  You may obtain a copy of the Apache License Version 2.0 at
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Apache License Version 2.0 is distributed on an "AS
 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the Apache License Version 2.0 for the specific language
 * governing permissions and limitations there under.
 */

namespace go com.snowplowanalytics.snowplow.CollectorPayload.thrift.model1

struct CollectorPayload {
  31337: string schema

  // Required fields which are intrinsic properties of HTTP
  100: string ipAddress

  // Required fields which are Snowplow-specific
  200: i64 timestamp
  210: string encoding
  220: string collector

  // Optional fields which are intrinsic properties of HTTP
  300: optional string userAgent
  310: optional string refererUri
  320: optional string path
  330: optional string querystring
  340: optional string body
  350: optional list<string> headers
  360: optional string contentType

  // Optional fields which are Snowplow-specific
  400: optional string hostname
  410: optional string networkUserId
}

 使用

thrift -r --gen go xxx.thrift

生成出对应文件就可以就可以进行调用工作了。

 

 

Reference:

https://thrift.apache.org/tutorial/

 

标签:string,Golang,Version,Apache,2.0,optional,thrift
From: https://www.cnblogs.com/piperck/p/17137666.html

相关文章

  • 【转】golang bufio、ioutil读文件的速度比较(性能测试)和影响因素分析
    golang读取文件的方式主要有4种:使用File自带的Read方法使用bufio库的Read方法使用io/ioutil库的ReadAll()使用io/ioutil库的ReadFile() 使用io/ioutil库的ReadFile()......
  • 【转】golang的log.Fatal()和panic()函数的区别
    golang的log.Fatal()和panic()函数的区别在讲两者区别之前我们先看一下os.Exit()函数的定义:funcExit(codeint)Exitcausesthecurrentprogramtoexitwiththe......
  • golang拾遗:实现一个不可复制类型
    这是golang拾遗系列的第六篇。这个系列主要用来记录一些平时不常见的知识点,偶尔也会实现些有意思的小功能,比如这篇。golang拾遗系列目录:golang拾遗:指针和接口golang拾......
  • Golang微服务(一)
    Golang微服务(一)目录Golang微服务(一)一、protobuf常规使用及踩坑记录1.类型映射关系及零值2.go_package设置3.protobuf的字段编号4.proto文件的import5.protobuf的message嵌......
  • golang 入门(十) 异常处理
    1、recovery捕获异常代码在运行的时候,总会遇到错误。有的时候我们会希望程序遇到错误以后继续运行后面的流程,而不是直接异常退出。在Python中,使用tryexcept组合实现这种需......
  • Golang基础-Runes
    rune与stringTherunetypeinGoisanaliasforint32.Giventhisunderlyingint32type,therunetypeholdsasigned32-bitintegervalue.However,unlikean......
  • golang 面向对象
    1.张老太养了两只猫:一只名字叫小白,今年3岁,白色。还有一只叫小花,今年100岁,花色。请编写一个程序,当用户输入小猫的名字时,就显示该猫的名字,年龄,颜色。如果用户输入的小猫名字......
  • linux 下装 mono,使apache 运行 asp.net
    1.更新系统  yumupdate  2.安装必要的相关库  yuminstallgccgcc-c++bisonpkgconfigglib2-develgettextmakelibpng-devellibjpeg-devellibtiff-develli......
  • Golang基础-Maps
    常见用法varagesmap[string]int//只声明不初始化是nil,赋值会panic:assignmenttoentryinnilmapfmt.Println(ages==nil)//"true"fmt.Println(len(ag......
  • Golang基础-Time
    常用函数t,err:=time.Parse(layout,date)//time.Time,errort:=time.Date(1995,time.September,22,13,0,0,0,time.UTC)formatedTime:=t.Format("Mon,01/02/2......