Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New exporter: go #405

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/go.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Go lang struct exporter

This exporter produces type struct definitions for the [go](https://go.dev/) programming language.

## Exporter specific arguments

### `--package`

The name of the package the generated sources (output and types output) will have.

# Example

Input model:
```yaml
# model.vspec
Vehicle:
type: branch
description: Vehicle
Vehicle.Speed:
type: sensor
description: Speed
datatype: uint16
Vehicle.Location:
type: sensor
description: Location
datatype: Types.GPSLocation
```

Input type definitions:
```yaml
# types.vspec
Types:
type: branch
description: Custom Types
Types.GPSLocation:
type: struct
description: GPS Location
Types.GPSLocation.Longitude:
type: property
description: Longitude
datatype: float
Types.GPSLocation.Latitude:
type: property
description: Latitude
datatype: float
```

Generator call:
```bash
vspec export go --vspec model.vspec --types types.vspec --package vss --output vss.go
```

Generated file:
```go
// vss.go
package vss

type Vehicle struct {
Speed uint16
Location GPSLocation
}
type GPSLocation struct {
Longitude float32
Latitude float32
}
```
1 change: 1 addition & 0 deletions docs/vspec.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ vspec export json --vspec spec/VehicleSignalSpecification.vspec --output vss.jso
- [id](./id.md)
- [protobuf](./protobuf.md)
- [samm](./samm.md)
- [go](./go.md)

## Argument Explanations

Expand Down
1 change: 1 addition & 0 deletions src/vss_tools/vspec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def cli(ctx: click.Context, log_level: str, log_file: Path):
"yaml": "vss_tools.vspec.vssexporters.vss2yaml:cli",
"tree": "vss_tools.vspec.vssexporters.vss2tree:cli",
"samm": "vss_tools.vspec.vssexporters.vss2samm.vss2samm:cli",
"go": "vss_tools.vspec.vssexporters.vss2go:cli",
},
)
@click.pass_context
Expand Down
Loading