-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { loader } from './loader.js' | ||
|
||
const start = async (addr) => { | ||
await loader.init() | ||
const clients = await loader.initClients({ services: { 'simple.Hellor': addr } }) | ||
|
||
const client = clients.get('simple.Hellor') | ||
const { response } = await client.sayHello({ message: 'grpcity' }) | ||
console.log(response) | ||
} | ||
|
||
start('localhost:5051') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ProtoLoader } from '../../lib/index.js' | ||
// same as import { ProtoLoader } from 'grpcity' | ||
|
||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
// get this file dir path | ||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
export const loader = new ProtoLoader({ | ||
location: path.join(__dirname, './'), | ||
files: ['service.proto'] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { loader } from './loader.js' | ||
|
||
const start = async (addr) => { | ||
await loader.init() | ||
const server = await loader.initServer() | ||
|
||
const implementation = { | ||
sayHello: async (call) => { | ||
return { message: `I got your message: ${call.request.message}` } | ||
} | ||
} | ||
|
||
server.add('simple.Hellor', implementation) | ||
await server.listen(addr) | ||
console.log('start:', addr) | ||
} | ||
|
||
start('localhost:5051') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
package simple; | ||
|
||
service Hellor { | ||
rpc sayHello (Message) returns (Message) {} | ||
} | ||
|
||
message Message { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters