Mahir.devv2
KursusBukuDokumentasiPlayground
Masuk
Mahir.dev

Jalur belajar pengembangan web berbasis teks untuk orang yang sudah capek lompat-lompat tutorial. Selesaikan, buktikan, dan pakai skill webmu.

Pembelajaran

  • Katalog Belajar
  • Buku Digital
  • Dokumentasi
  • Playground
  • Dashboard & Sertifikat
  • Tentang Mahir.dev

Kebijakan & Legal

  • Kebijakan Privasi
  • Syarat & Ketentuan
  • Penggunaan Wajar
  • Penafian (Disclaimer)

© 2026 Mahir.dev Academy. Semua hak cipta dilindungi.

Bahasa Indonesia (ID)
DokumentasiGo (Golang)Go gRPC
Daftar Isi0%
DefinisiKapan dipakaiCara kerjaProtoServerClientStruktur alurCatatan implementasiKesalahan umumReferensi terkait
Kembali ke Kategori Go (Golang)

Go gRPC

Go (Golang)3 September 2026Diperbarui 3 September 20262 menit baca

Go gRPC

Definisi

gRPC adalah RPC framework berbasis HTTP/2 dengan kontrak protobuf (.proto). Di Go, protoc + plugin go-grpc menghasilkan stub; server mengimplementasikan interface, client memanggil seperti fungsi lokal.

Kapan dipakai

Pakai untuk komunikasi antar-service internal (microservice) yang butuh performa tinggi & kontrak kuat. Hindari untuk publik browser (butuh grpc-web proxy) atau API publik sederhana (REST/JSON lebih mudah).

Cara kerja

Proto

protoproto
syntax = "proto3";
package api;
service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloRequest { string name = 1; }
message HelloReply { string message = 1; }

Server

gogo
func (s *server) SayHello(ctx context.Context, in *api.HelloRequest) (*api.HelloReply, error) {
    return &api.HelloReply{Message: "Halo " + in.Name}, nil
}
 
// lis := net.Listen; grpc.NewServer(); api.RegisterGreeterServer(s, &server{}); s.Serve(lis)

Client

gogo
conn, _ := grpc.Dial("localhost:50051", grpc.WithInsecure())
c := api.NewGreeterClient(conn)
r, _ := c.SayHello(context.Background(), &api.HelloRequest{Name: "Budi"})

Struktur alur

Loading diagram...

Catatan implementasi

  • Generate: protoc --go_out=. --go-grpc_out=. *.proto.
  • grpc.WithInsecure() deprecated; pakai credentials untuk produksi (TLS).
  • Selain unary, ada server/client streaming & bidirectional — cocok realtime.
  • Proto versioning: jangan ubah nomor field; tambah field baru (backward compatible).

Kesalahan umum

  • Ubah field number: merusak kompatibilitas serialisasi.
  • Tanpa TLS di produksi: man-in-the-middle; pakai credentials.
  • Blocking dial tanpa context: hang; selalu timeout.
  • Lupa generate ulang stub: kode tidak cocok proto terbaru.

Referensi terkait

  • Go Web API Lanjut: Validasi, Error Response, Versioning
  • Go net/http Middleware Chain
  • Go Context Usage Patterns, Cancellation, Timeouts

Jadikan Sumber Pilihan di Google Search

Dapatkan tutorial, materi, dan dokumentasi Mahir.dev lebih mudah di Google Search dan AI Overviews.

Pelajari selengkapnya

Selesai membaca dokumentasi ini?

Kembali ke rujukan utama Go (Golang) untuk melanjutkan topik lainnya.

Kembali ke Kategori