type http2FrameHeader struct {
valid bool // caller can access []byte fields in the Frame
// Type is the 1 byte frame type. There are ten standard frame
// types, but extension frame types may be written by WriteRawFrame
// and will be returned by ReadFrame (as UnknownFrame).
Type http2FrameType
// Flags are the 1 byte of 8 potential bit flags per frame.
// They are specific to the frame type.
Flags http2Flags
// Length is the length of the frame, not including the 9 byte header.
// The maximum size is one byte less than 16MB (uint24), but only
// frames up to 16KB are allowed without peer agreement.
Length uint32
// StreamID is which stream this frame is for. Certain frames
// are not stream-specific, in which case this field is 0.
StreamID uint32
}type http2FrameType uint8
const (
http2FrameData http2FrameType = 0x0
http2FrameHeaders http2FrameType = 0x1
http2FramePriority http2FrameType = 0x2
http2FrameRSTStream http2FrameType = 0x3
http2FrameSettings http2FrameType = 0x4
http2FramePushPromise http2FrameType = 0x5
http2FramePing http2FrameType = 0x6
http2FrameGoAway http2FrameType = 0x7
http2FrameWindowUpdate http2FrameType = 0x8
http2FrameContinuation http2FrameType = 0x9
http2FramePriorityUpdate http2FrameType = 0x10
)type http2DataFrame struct {
http2FrameHeader // заголовок фрейма
data []byte // сами данные
}type http2HeadersFrame struct {
http2FrameHeader // заголовок фрейма
// Priority is set if FlagHeadersPriority is set in the FrameHeader.
Priority http2PriorityParam // параметры приоритета
headerFragBuf []byte // not owned // буфер с фрагментом заголовков
}type http2Flags uint8
// Frame-specific FrameHeader flag bits.
const (
// Data Frame
http2FlagDataEndStream http2Flags = 0x1
http2FlagDataPadded http2Flags = 0x8
// Headers Frame
http2FlagHeadersEndStream http2Flags = 0x1
http2FlagHeadersEndHeaders http2Flags = 0x4
http2FlagHeadersPadded http2Flags = 0x8
http2FlagHeadersPriority http2Flags = 0x20
// Settings Frame
http2FlagSettingsAck http2Flags = 0x1
// Ping Frame
http2FlagPingAck http2Flags = 0x1
// Continuation Frame
http2FlagContinuationEndHeaders http2Flags = 0x4
http2FlagPushPromiseEndHeaders http2Flags = 0x4
http2FlagPushPromisePadded http2Flags = 0x8
)POST /go HTTP/1
Content-Length: 24
{"hello": "@igorutine"}HeaderFrame{
StreamId: 1
Flags: FlagEndHeaders
[
:method: POST
:path: /go
Content-Length: 24
]
}DataFrame{
StreamId: 1,
Flags: FlagEndStream,
PayloadLength: 24,
Data: {"hello": "..."},
}200 OK
Content-Length: 0
Date: Sat, 14 Feb 2026 16:34:56 GMTHeadersFrame{
StreamId: 1
Flags: FlagEndHeaders | FlagEndStream
[
:status: 200
Content-Length: 0
Date: Sat, ...
]
}HeadersFrame{
StreamId: 1
Flags: FlagEndHeaders | FlagEndStream
[
:method: POST
:path: /go
Content-Length: 0
]
}
HeadersFrame{
StreamId: 3
Flags: FlagEndHeaders | FlagEndStream
[
:method: POST
:path: /go
Content-Length: 0
]
}HeadersFrame{
StreamId: 1
Flags: FlagEndHeaders | FlagEndStream
[
:status: 20
Content-Length: 0
Date: Sat, ...
]
}
HeadersFrame{
StreamId: 3
Flags: FlagEndHeaders | FlagEndStream
[
:status: 20
Content-Length: 0
Date: Sat, ...
]
}package grpctest.v1
service HelloService {
rpc SayHello(HelloRequest) returns (HelloResponse);
}:method: POST
:path: /grpctest.v1.HelloService/SayHello
content-type: application/grpc
user-agent: grpc-go/1.52.0
body: [...]message HelloRequest {
string name = 1;
}
message HelloResponse {
string message = 1;
}message ScalarValueTypesExample {
double double_field = 1; // Go Type: float64
float api_field = 2; // Go Type: float32
int32 int32_field = 3; // Go Type: int32
int64 int64_field = 4; // Go Type: int64
uint32 uint32_field = 5; // Go Type: uint32
uint64 uint64_field = 6; // Go Type: uint64
sint32 sint32_field = 7; // Go Type: int32
sint64 sint64_field = 8; // Go Type: int64
fixed32 fixed32_field = 9; // Go Type: uint32
fixed64 fixed64_field = 10; // Go Type: uint64
sfixed32 sfixed32_field = 11; // Go Type: int32
sfixed64 sfixed64_field = 12; // Go Type: int64
bool bool_field = 13; // Go Type: bool
string string_field = 14; // Go Type: string
bytes bytes_field = 15; // Go Type: []byte
}message WellKnownTypesExample {
google.protobuf.Any any_field = 1;
google.protobuf.Api api_field = 2;
google.protobuf.Duration duration_field = 3;
google.protobuf.Empty empty_field = 4;
google.protobuf.FieldMask field_mask_field = 5;
google.protobuf.SourceContext source_context_field = 6;
google.protobuf.Struct struct_field = 7;
google.protobuf.Timestamp timestamp_field = 8;
google.protobuf.Type type_field = 9;
google.protobuf.DoubleValue double_field = 10;
google.protobuf.FloatValue float_field = 11;
google.protobuf.Int64Value int64_field = 12;
google.protobuf.UInt64Value uint64_field = 13;
google.protobuf.Int32Value int32_field = 14;
google.protobuf.UInt32Value uint32_field = 15;
google.protobuf.BoolValue bool_field = 16;
google.protobuf.StringValue string_field = 17;
google.protobuf.BytesValue bytes_field = 18;
google.protobuf.Value value_field = 19;
}message CommonTypes {
google.type.Interval interval_field = 1;
google.type.Date date_field = 2;
google.type.DayOfWeek day_of_week_field = 3;
google.type.TimeOfDay time_of_day_field = 4;
google.type.LatLng lat_lng_field = 5;
google.type.Money money_field = 6;
google.type.PostalAddress postal_address_field = 7;
google.type.Color color_field = 8;
google.type.Month month_field = 9;
google.type.CalendarPeriod calendar_period_field = 10;
google.type.Decimal decimal_field = 11;
google.type.Expr expr_field = 12;
google.type.Fraction fraction_field = 13;
google.type.LocalizedText localized_text_field = 14;
google.type.PhoneNumber phone_number_field = 15;
}message OptionalExample {
int32 required_field = 1; // required (if not provided we get default
value: 0) Go type: int32
optional int32 optional_field = 2; // optional (if not provided we get
null) Go type: *int32
}enum Corpus {
CORPUS_UNSPECIFIED = 0;
CORPUS_UNIVERSAL = 1;
CORPUS_WEB = 2;
CORPUS_IMAGES = 3;
CORPUS_LOCAL = 4;
CORPUS_NEWS = 5;
CORPUS_PRODUCTS = 6;
CORPUS_VIDEO = 7;
}message DeprecatedExample {
// Use new_field instead old_field
int32 old_field = 1 [deprecated = true];
int64 new_field = 2;
}type DeprecatedExample struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Use new_field instead old_field
//
// Deprecated: Do not use.
OldField int32
`protobuf:"varint,1,opt,name=old_field,json=oldField,proto3"
json:"old_field,omitempty"`
NewField int64
`protobuf:"varint,2,opt,name=new_field,json=newField,proto3"
json:"new_field,omitempty"`
}enum Foo {
reserved 2, 15, 9 to 11, 40 to max;
reserved "FOO", "BAR";
FOO = 2;
}api/examples/enum.proto: Enum value "FOO" uses reserved number 2.
api/examples/enum.proto:22:5: Enum value "FOO" is reserved.message SearchResponse {
message Result {
string url = 1;
string title = 2;
repeated string snippets = 3;
}
repeated Result result = 1;
}message Stock {
// Stock-specific data
}
message Currency {
// Currency-specific data
}
message ChangeNotification {
int32 id = 1;
oneof instrument {
Stock stock = 2;
Currency currency = 3;
}
}message GetProjectResponse {
message Project {
// data
}
map<string, Project> projects = 1;
}// Один запрос, один ответ:
rpc Send(Message) returns (Result);
// Один запрос, поток ответов:
rpc Send(Message) returns (stream Result);
// Поток запросов, один ответ:
rpc Send(stream Message) returns (Result);
// Поток запросов, поток ответов:
rpc Send(stream Message) returns (stream Result);syntax = "proto3";
package user.v1;
option go_package = "example.com/project/gen/user/v1;userv1";
service UserService {
rpc GetUser(GetUserRequest) returns (GetUserResponse);
}
message GetUserRequest {
string id = 1;
}
message GetUserResponse {
string id = 1;
string name = 2;
}go install google.golang.org/protobuf/cmd/protoc-gen-go@latestgo install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestprotoc \
-I {{.PROTO_DIR}} \
--go_out={{.GEN_DIR}} \
--go_opt=paths=source_relative \
--go-grpc_out={{.GEN_DIR}} \
--go-grpc_opt=paths=source_relative \
{{.PROTO_DIR}}/user/v1/user.prototype GetUserRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}
type GetUserResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3"
json:"name,omitempty"`
}var file_user_v1_user_proto_rawDesc = []byte{
0x0a, 0x12, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x75, 0x73,
0x65, 0x72, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x76,
0x31, 0x22, 0x20, 0x0a,
0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12,
...
}