Skip to content

Commit

Permalink
use schemaName and schema version from ridl directly
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasJenicek committed Sep 30, 2024
1 parent b822369 commit ad915d5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
26 changes: 16 additions & 10 deletions _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion _examples/golang-basics/example.ridl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
webrpc = v1 # version of webrpc schema format (ridl or json)

name = example # name of your backend app
version = golang-basics@v0.0.1 # version of your schema
version = v0.0.1 # version of your schema

# user role
# which defines which type of operations user can do
Expand Down
20 changes: 13 additions & 7 deletions _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,43 @@ type WebRPCGenVersions struct {
WebRPCGenVersion string
TmplTarget string
TmplVersion string
SchemaName string
SchemaVersion string
}

// WebRPCHeader
// TmplVersion might be empty when generated from local template folder
func WebRPCHeader() string {
return "webrpc@{{.WebrpcGenVersion}};{{.TmplTarget}}@{{ if eq .TmplVersion "" }}unknown{{ else }}{{.TmplVersion}}{{end}};{{.SchemaVersion}}"
return "webrpc@{{.WebrpcGenVersion}};{{.TmplTarget}}@{{ if eq .TmplVersion "" }}unknown{{ else }}{{.TmplVersion}}{{end}};{{.SchemaName}}@{{.SchemaVersion}}"
}

func ParseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) {
versions := strings.Split(header, ";")

if len(versions) < 3 {
return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %s", header)
}

_, webrpcGenVersion, ok := strings.Cut(versions[0], "@")
if !ok {
return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", header)
return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0])
}

tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@")
if !ok {
return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", header)
return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1])
}

schemaName, schemaVersion, ok := strings.Cut(versions[2], "@")
if !ok {
return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2])
}

return &WebRPCGenVersions{
WebRPCGenVersion: webrpcGenVersion,
TmplTarget: tmplTarget,
TmplVersion: tmplVersion,
SchemaVersion: versions[2],
SchemaName: schemaName,
SchemaVersion: schemaVersion,
}, nil
}

Expand Down

0 comments on commit ad915d5

Please sign in to comment.