Sitemap
Aditya Okke Sugiarso

Aditya Okke Sugiarso

Basic gRPC

2 min readJun 4, 2025

I write this basic documentation based on my learning experience
Using Go as the language

proto file structure

syntax = "proto3";

package yourgrpc

/**
* SearchRequest represents a search query, with pagination options to
* indicate which results to include in the response.
*/
message SearchRequest {
reserved 4, 15, 9 to 11;
reserved "foo", "bar";

string query = 1;

// Which page number do we want?
int32 page_number = 2;

// Number of results to return per page.
int32 results_per_page = 3;
}

message User {
int64 id = 1;
string name = 2;
}

message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 results_per_page = 3;
Corpus corpus = 4;
}

message SearchResponse {
repeated Result users = 1;
}

enum Corpus {
reserved 3, 15, 9 to 11, 40 to max;
reserved "FOO", "BAR";

// no negatif value
CORPUS_UNSPECIFIED = 0;
CORPUS_UNIVERSAL = 1;
CORPUS_WEB = 2;
}

enum EnumAllowingAlias {
// 1 key can have 2 naming
option allow_alias = true;
EAA_UNSPECIFIED = 0;
EAA_STARTED = 1;
EAA_RUNNING = 1;
EAA_FINISHED = 2;
}

fieldType fieldName = numericValue;

fieldType can be enum, scalar, or composite

numericValue is a unique number; use 1 through 15 for the most-frequently-set fields.

Get Aditya Okke Sugiarso’s stories in your inbox

Join Medium for free to get updates from this writer.

Default value:

  • For strings, the default value is the empty string.
  • For bytes, the default value is empty bytes.
  • For bools, the default value is false.
  • For numeric types, the default value is zero.
  • For message fields, the field is not set. Its exact value is language-dependent. See the generated code guide for details.
  • For enums, the default value is the first defined enum value, which must be 0. See Enum Default Value.
  • The default value for repeated fields is empty (generally an empty list in the appropriate language).
  • The default value for map fields is empty (generally an empty map in the appropriate language).

--

--