Files
model/README.md
T

71 lines
1.8 KiB
Markdown
Raw Normal View History

# Fog Model
This module contains the Protocol Buffer schemas and generated Go types used to
represent Fog deployment data and control messages.
## Schemas
- `deployment.proto` defines `DeploymentAction` (`STOP` or `START`),
`GlobalEnvironment`, `ConfigFile`, and `Deployment`.
- `c2o/operation.proto` defines request `Message` values and `RequestType`
(`PING` or `DEPLOYMENT`).
The generated Go packages are `beejay.kim/fog/model` and
`beejay.kim/fog/model/c2o`, respectively. The generated `.pb.go` files are
checked in; edit the `.proto` files rather than editing generated code.
## Using the Go types
Import the generated package and use the standard Protocol Buffers Go API:
```go
package main
import (
"fmt"
model "beejay.kim/fog/model"
"google.golang.org/protobuf/proto"
)
func main() {
deployment := &model.Deployment{
Id: "example",
Action: model.DeploymentAction_START,
Env: &model.GlobalEnvironment{
Version: "1",
Variables: map[string]string{"REGION": "west"},
},
}
data, err := proto.Marshal(deployment)
if err != nil {
panic(err)
}
var decoded model.Deployment
if err := proto.Unmarshal(data, &decoded); err != nil {
panic(err)
}
fmt.Println(decoded.GetId())
}
```
The module requires Go 1.27 and `google.golang.org/protobuf`.
## Regenerating Go code
Install `protoc` 36.2 using the [official installation
instructions](https://protobuf.dev/installation/), and ensure it and the Go
generator are on `PATH`:
```sh
protoc --version
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.12
make proto
```
`make proto` regenerates the Go files from both schemas. Commit the updated
`.pb.go` files together with any schema changes. The workflow pushes generated
files to same-repository pull request branches; for pull requests from forks,
it reports an error if generated files are out of date.