package message;
import "gogo.proto";
option (gogoproto.sizer_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
message Header {
enum HmacHashFunction {
MD5 = 0;
SHA1 = 1;
}
required uint32 message_length = 1; // length in bytes
optional HmacHashFunction hmac_hash_function = 3 [default = MD5];
optional string hmac_signer = 4;
optional uint32 hmac_key_version = 5;
optional bytes hmac = 6;
}
message Field {
enum ValueType {
STRING = 0;
BYTES = 1;
INTEGER = 2;
DOUBLE = 3;
BOOL = 4;
}
required string name = 1;
optional ValueType value_type = 2 [default = STRING];
optional string representation = 3;
repeated string value_string = 4;
repeated bytes value_bytes = 5;
repeated int64 value_integer = 6 [packed=true];
repeated double value_double = 7 [packed=true];
repeated bool value_bool = 8 [packed=true];
}
message Message {
required bytes uuid = 1;
required int64 timestamp = 2; // nanoseconds since UNIX epoch
optional string type = 3;
optional string logger = 4;
optional int32 severity = 5 [default = 7];
optional string payload = 6;
optional string env_version = 7;
optional int32 pid = 8;
optional string hostname = 9;
repeated Field fields = 10;
}
-------------------------事先安装--------------------------------
1.从 https://github.com/google/protobuf/releases 获取 Protobuf 编译器 protoc
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar zxvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
./configure
make
make install
protoc -h
2.获取 goprotobuf 提供的 Protobuf 编译器插件 protoc-gen-go(被放置于 $GOPATH/bin 下,$GOPATH/bin 应该被加入 PATH 环境变量,以便 protoc 能够找到 protoc-gen-go)
此插件被 protoc 使用,用于编译 .proto 文件为 Golang 源文件,通过此源文件可以使用定义在 .proto 文件中的消息。
go get github.com/golang/protobuf/protoc-gen-go
cd github.com/golang/protobuf/protoc-gen-go
go build
go install
vi /etc/profile 将$GOPATH/bin 加入环境变量
source profile