-
Notifications
You must be signed in to change notification settings - Fork 0
Language Go
The Go generator emits a stand-alone .go file.
swift run lexicon-generate commerce.lexicon \
--type go \
--go-package commerce \
-o internal/commerce/lexiconThis writes:
internal/commerce/lexicon.go
--go-package controls the package declaration. The default is lexicon.
Generated Go defines:
-
I, the shared interface withID()andLocalized(). -
Lemma, a string-backed exact-path helper. -
L, the base implementation. - one struct per concrete lemma.
- constructors for generated structs.
- exported TitleCase fields and methods for accessors.
Example:
package checkout
import "example.com/app/internal/commerce"
func TrackSubmit() string {
submit := commerce.Commerce.Api.Order.Submit
return submit.ID()
}The ID() method returns the exact lemma path.
Generated Go includes:
func l(path string) Lemma {
return Lemma(path)
}Use it when a path must stay in string form, such as migration tables or test fixtures:
expected := l("commerce.api.order.submit")
if expected.ID() != commerce.Commerce.Api.Order.Submit.ID() {
panic("unexpected vocabulary path")
}The helper keeps exact lowercase lemma identifiers even though Go selectors are exported TitleCase.
Go selectors are generated as exported TitleCase identifiers. A lemma path such as:
test.type.even.bad
is used from Go as:
lexicon.Test.Type.Even.Bad.ID()The underlying ID remains:
test.type.even.bad
Add a generation directive near the package that owns the generated file:
//go:generate swift run lexicon-generate ../../lexicons/commerce.lexicon --type go --go-package commerce -o lexiconThen run:
go generate ./...If the Go build should not require Swift, commit the generated .go file.
lexicon-lsp recognizes exact-path calls in Go:
l("commerce.api.order.submit")With editor integration, completions and unknown-path diagnostics work inside the string. The typed generated selectors are handled by normal Go tooling.
See Editor Support and GoLand and JetBrains.