63 | gRPC-web!
64 | Visit the Svelte tutorial to learn how to build Svelte apps.
65 |
66 |
67 |
68 | {#each cats.slice(0,50) as cat}
69 | -
70 | {cat.id} - {cat.name}
71 |
72 | {/each}
73 |
74 |
75 |
76 |
77 | {#each catsJson.slice(0,50) as cat}
78 | -
79 | {cat.id} - {cat.name}
80 |
81 | {/each}
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/frontend/src/main.js:
--------------------------------------------------------------------------------
1 | import App from './App.svelte';
2 |
3 | const app = new App({
4 | target: document.body,
5 | props: {
6 | name: 'world---'
7 | }
8 | });
9 |
10 | export default app;
--------------------------------------------------------------------------------
/frontend/src/services/category.js:
--------------------------------------------------------------------------------
1 | export default class{
2 | constructor(deps){
3 | this.tokenKey = deps.tokenKey
4 | this.proto = deps.proto
5 | this.client = new deps.proto.CategoryClient('http://localhost:9002', null, null)
6 | }
7 |
8 | index (){
9 | const req = new this.proto.IndexRequest()
10 | return this.client.index(req, {}).then(res=>{
11 | return res.getCategoriesList().map(category=>{
12 | return {
13 | id: category.getId(),
14 | name: category.getName(),
15 | }
16 | });
17 | })
18 | }
19 | }
--------------------------------------------------------------------------------
/proto/categories.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package proto;
4 | option go_package = ".;proto";
5 |
6 | service CategoryService {
7 | rpc Index(IndexRequest) returns (Categories) {}
8 | }
9 |
10 | message Categories {
11 | repeated Category categories = 1;
12 | }
13 |
14 | message Category {
15 | string id = 1;
16 | string name = 2;
17 | }
18 |
19 | message IndexRequest {}
20 |
21 |
--------------------------------------------------------------------------------