Golang 构建 Apache 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/

 

posted @ 2023-02-20 15:35  piperck  阅读(40)  评论(0编辑  收藏  举报