Skip to content

Commit c9db60b

Browse files
authored
Support the new RIDL "basepath" keyword (#8)
1 parent 2d99a94 commit c9db60b

6 files changed

Lines changed: 14 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- name: Install webrpc-gen
1717
run: |
18-
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.18.6/webrpc-gen.linux-amd64
18+
curl -o ./webrpc-gen -fLJO https://github.com/webrpc/webrpc/releases/download/v0.32.3/webrpc-gen.linux-amd64
1919
chmod +x ./webrpc-gen
2020
echo $PWD >> $GITHUB_PATH
2121

_examples/hello-webrpc/webapp/client.gen.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// hello-webrpc v1.0.0 4fc01b139e8de5a1eb11b0581cd706326a434708
1+
// hello-webrpc v1.0.0 7037367a376940060eaf2739a920c4dca4a6dc2e
22
// --
3-
// Code generated by webrpc-gen@v0.18.6 with ../../ generator. DO NOT EDIT.
3+
// Code generated by webrpc-gen@v0.32.3 with ../../ generator. DO NOT EDIT.
44
//
55
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js
66

@@ -11,7 +11,7 @@ const WebRPCVersion = "v1"
1111
const WebRPCSchemaVersion = "v1.0.0"
1212

1313
// Schema hash generated from your RIDL schema
14-
const WebRPCSchemaHash = "4fc01b139e8de5a1eb11b0581cd706326a434708"
14+
const WebRPCSchemaHash = "7037367a376940060eaf2739a920c4dca4a6dc2e"
1515

1616
//
1717
// Types

client.go.tmpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{{define "client"}}
22

3+
{{- $basepath := .BasePath -}}
4+
{{- $services := .Services -}}
35
{{- $opts := .Opts -}}
46

5-
{{- if .Services}}
7+
{{- if $services }}
68
//
79
// Client
810
//
9-
{{ range .Services}}
11+
{{ range $services }}
1012
{{if $opts.exports}}export {{end}}class {{.Name}} {
1113
constructor(hostname, fetch) {
12-
this.path = '/rpc/{{.Name}}/'
14+
this.path = '{{$basepath}}{{.Name}}/'
1315
this.hostname = hostname
1416
this.fetch = (input, init) => fetch(input, init)
1517
}

main.go.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969

7070
{{template "types" dict "Services" .Services "Types" .Types "Opts" $opts}}
7171
{{- if $opts.client}}
72-
{{template "client" dict "Services" .Services "Opts" $opts}}
72+
{{template "client" dict "BasePath" .BasePath "Services" .Services "Opts" $opts}}
7373
{{template "client_helpers" .}}
7474
{{- end}}
7575
{{- if $opts.server}}
76-
{{template "server" dict "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
76+
{{template "server" dict "BasePath" .BasePath "Services" .Services "Opts" $opts "TypeMap" $typeMap}}
7777
{{- end}}
7878
{{- end}}

server.go.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{define "server"}}
22

3+
{{- $basepath := .Basepath -}}
34
{{- $services := .Services -}}
45
{{- $typeMap := .TypeMap -}}
56

@@ -37,7 +38,7 @@ import express from 'express'
3738
switch(requestPath) {
3839
{{range $_, $method := $service.Methods}}
3940
40-
case "/rpc/{{$service.Name}}/{{$method.Name}}": {
41+
case "{{$basepath}}{{$service.Name}}/{{$method.Name}}": {
4142
try {
4243
{{ range $_, $input := $method.Inputs }}
4344
{{- if not $input.Optional}}

tests/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class Complex {
174174

175175
export class TestApi {
176176
constructor(hostname, fetch) {
177-
this.path = '/rpc/TestApi/'
177+
this.path = '/v1/TestApi/'
178178
this.hostname = hostname
179179
this.fetch = () => fetch
180180
}

0 commit comments

Comments
 (0)