Documentation ¶
Overview ¶
Package goproto implements conversions from well-known golang/profobuf types.
Index ¶
- func GoFieldsPaths(pb *field_mask.FieldMask, v interface{}) []string
- func Interface(v *structpb.Value) (interface{}, error)
- func List(s []interface{}) (*structpb.ListValue, error)
- func Map(p *structpb.Struct) (map[string]interface{}, error)
- func Slice(l *structpb.ListValue) ([]interface{}, error)
- func Struct(m map[string]interface{}) (*structpb.Struct, error)
- func Value(v interface{}) (*structpb.Value, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoFieldsPaths ¶
func GoFieldsPaths(pb *field_mask.FieldMask, v interface{}) []string
GoFieldsPaths converts protobuf FieldMask paths to Go fields paths.
This implementation does not support separation by ",", but only paths separated by ".".
Example ¶
package main import ( "fmt" "go.thethings.network/lorawan-stack/pkg/goproto" "google.golang.org/genproto/protobuf/field_mask" ) func main() { type cityDetails struct { Name string `protobuf:"name=name_city"` } type place struct { NameOfTheRegion string `protobuf:"name=name_region"` CityDetails cityDetails `protobuf:"bytes,name=city"` } london := place{ CityDetails: cityDetails{Name: "London"}, } holland := place{ NameOfTheRegion: "Holland", } fields := goproto.GoFieldsPaths(&field_mask.FieldMask{ Paths: []string{"city.name_city"}, }, london) fmt.Println(fields) fields = goproto.GoFieldsPaths(&field_mask.FieldMask{ Paths: []string{"name_region"}, }, holland) fmt.Println(fields) }
Output: [CityDetails.Name] [NameOfTheRegion]
func Interface ¶
func Interface(v *structpb.Value) (interface{}, error)
Interface returns the Value proto as an interface{}.
func List ¶
func List(s []interface{}) (*structpb.ListValue, error)
List returns the slice as a ListValue proto.
func Slice ¶
func Slice(l *structpb.ListValue) ([]interface{}, error)
Slice returns the ListValue proto as a []interface{}.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.