Go Academy
trpc-go 专题
45 分钟

C1: tRPC 概念与 Go 生态

理解 tRPC 的设计理念,对比 REST/GraphQL,了解 trpc-go 在生态中的定位

学习目标

  • 1.理解 tRPC 的端到端类型安全理念
  • 2.对比 tRPC 与 REST、GraphQL 的优劣
  • 3.了解 trpc-go 的架构设计

课程内容

本课时将帮助你快速掌握相关知识。以下是示例代码:

main.go
1package main
2
3import "fmt"
4
5func main() {
6 fmt.Println("Hello, Go!")
7
8 // Go 的变量声明
9 var name string = "TypeScript Developer"
10 age := 25 // 短变量声明
11
12 fmt.Printf("Name: %s, Age: %d\n", name, age)
13}

上面的代码演示了 Go 的基本语法,包括包声明、导入和变量声明。 注意第 8 行的短变量声明语法 :=,这是 Go 的特色。

与 TypeScript 对比

example.ts
// TypeScript 版本
const name: string = "TypeScript Developer";
const age = 25; // 类型推断
console.log(`Name: ${name}, Age: ${age}`);