add README documentation for Fog Model and Protocol Buffer schemas #1
@@ -0,0 +1,67 @@
|
|||||||
|
# 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` and the Go generator, and ensure both executables are on
|
||||||
|
`PATH`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
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.
|
||||||
Reference in new issue
Block a user