Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jkawamoto/structpbconv
Converts structpb.Struct to another structure.
https://github.com/jkawamoto/structpbconv
go google-compute-engine protocol-buffers
Last synced: 13 days ago
JSON representation
Converts structpb.Struct to another structure.
- Host: GitHub
- URL: https://github.com/jkawamoto/structpbconv
- Owner: jkawamoto
- License: mit
- Created: 2016-12-29T08:01:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-25T00:22:21.000Z (almost 5 years ago)
- Last Synced: 2024-06-21T08:14:11.080Z (5 months ago)
- Topics: go, google-compute-engine, protocol-buffers
- Language: Go
- Homepage: https://godoc.org/github.com/jkawamoto/structpbconv
- Size: 10.7 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# structpbconv
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)Converts [structpb.Struct](https://github.com/golang/protobuf/blob/master/ptypes/struct/struct.pb.go)
to another structure.## Usage
For example, let us assume to convert Payload of a [logging.Entry](https://godoc.org/cloud.google.com/go/logging#Entry) to
an ActivityPayload, which is a basic log format in
[Google Compute Engine](https://cloud.google.com/compute/).The type of Payload of logging.Entry is `interface{}` but it can be casted
to `*structpb.Struct` in most cases.The following code converts the instance of `*structpb.Struct` to an
instance of ActivityPayload, which is also defined in that code.Note that to specify a field name, use `structpb` tag.
```go
import (
"github.com/golang/protobuf/ptypes/struct"
"github.com/jkawamoto/structpbconv"
)type ActivityPayload struct {
EventTimestampUs string `structpb:"event_timestamp_us"`
EventType string `structpb:"event_type"`
TraceID string `structpb:"trace_id"`
Actor struct {
User string
}
Resource struct {
Zone string
Type string
ID string
Name string
}
Version string
EventSubtype string `structpb:"event_subtype"`
Operation struct {
Zone string
Type string
ID string
Name string
}
}func NewActivityPayload(payload *structpb.Struct) *ActivityPayload {
var res ActivityPayload
structpbconv.Convert(payload, &res)
return &res
}
```## License
This software is released under the MIT License, see [LICENSE](LICENSE).