trpc.group/trpc-go/trpc-go@v1.0.3/testdata/restful/bookstore/bookstore.proto (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 syntax = "proto3"; 15 16 package trpc.examples.restful.bookstore; 17 18 option go_package = "trpc.group/trpc-go/trpc-go/examples/restful/bookstore"; 19 20 import "trpc/api/annotations.proto"; 21 import "google/protobuf/field_mask.proto"; 22 import "google/protobuf/empty.proto"; 23 24 // 书店服务 25 service Bookstore { 26 // 获取所有的书柜 27 rpc ListShelves(google.protobuf.Empty) returns (ListShelvesResponse) { 28 option (trpc.api.http) = { 29 get: "/shelves" 30 response_body: "shelves" 31 }; 32 } 33 34 // 创建一个书柜 35 rpc CreateShelf(CreateShelfRequest) returns (Shelf) { 36 option (trpc.api.http) = { 37 post: "/shelf" 38 body: "*" 39 additional_bindings: { 40 post: "/shelf/theme/{shelf.theme}" 41 } 42 }; 43 } 44 45 // 获取一个书柜 46 rpc GetShelf(GetShelfRequest) returns (Shelf) { 47 option (trpc.api.http) = { 48 get: "/shelf/{shelf}" 49 }; 50 } 51 52 // 删除一个书柜 53 rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) { 54 option (trpc.api.http) = { 55 delete: "/shelf/{shelf}" 56 }; 57 } 58 59 // 获取所有的书 60 rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) { 61 option (trpc.api.http) = { 62 get: "/books/shelf/{shelf}" 63 }; 64 } 65 66 // 创建一本书 67 rpc CreateBook(CreateBookRequest) returns (Book) { 68 option (trpc.api.http) = { 69 post: "/book/shelf/{shelf}" 70 body: "book" 71 }; 72 } 73 74 // 获取一本书 75 rpc GetBook(GetBookRequest) returns (Book) { 76 option (trpc.api.http) = { 77 get: "/book/shelfid/{shelf}/bookid/{book}" 78 }; 79 } 80 81 // 删除一本书 82 rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) { 83 option (trpc.api.http) = { 84 delete: "/book/shelfid/{shelf}/bookid/{book}" 85 }; 86 } 87 88 // 更新一本书 89 rpc UpdateBook(UpdateBookRequest) returns (Book) { 90 option (trpc.api.http) = { 91 patch: "/book/shelfid/{shelf}/bookid/{book.id}" 92 body: "book" 93 }; 94 } 95 96 rpc UpdateBooks(UpdateBooksRequest) returns (ListBooksResponse) { 97 option (trpc.api.http) = { 98 patch: "/book/shelfid/{shelf}" 99 body: "books" 100 }; 101 } 102 } 103 104 // 书柜 105 message Shelf { 106 int64 id = 1; 107 string theme = 2; 108 } 109 110 // 书 111 message Book { 112 int64 id = 1; 113 string author = 2; 114 string title = 3; 115 Content content = 4; 116 } 117 118 // 书内容 119 message Content { 120 string summary = 1; 121 } 122 123 // 获取所有的书柜响应 124 message ListShelvesResponse { 125 repeated Shelf shelves = 1; 126 } 127 128 // 创建一个书柜请求 129 message CreateShelfRequest { 130 Shelf shelf = 1; 131 } 132 133 // 获取一个书柜请求 134 message GetShelfRequest { 135 int64 shelf = 1; 136 } 137 138 // 删除一个书柜请求 139 message DeleteShelfRequest { 140 int64 shelf = 1; 141 } 142 143 // 获取所有的书请求 144 message ListBooksRequest { 145 int64 shelf = 1; 146 } 147 148 // 获取所有的书 149 message ListBooksResponse { 150 repeated Book books = 1; 151 } 152 153 // 创建一本书请求 154 message CreateBookRequest { 155 int64 shelf = 1; 156 Book book = 2; 157 } 158 159 // 获取一本书请求 160 message GetBookRequest { 161 int64 shelf = 1; 162 int64 book = 2; 163 } 164 165 // 删除一本书请求 166 message DeleteBookRequest { 167 int64 shelf = 1; 168 int64 book = 2; 169 } 170 171 // 更新一本书请求 172 message UpdateBookRequest { 173 int64 shelf = 1; 174 Book book = 2; 175 google.protobuf.FieldMask update_mask = 3; 176 } 177 178 message UpdateBooksRequest { 179 int64 shelf = 1; 180 repeated Book books = 2; 181 }