Documentation ¶
Overview ¶
Package goproto implements conversions from well-known golang/profobuf types.
Index ¶
- func GoFieldsPaths(pb *field_mask.FieldMask, v any) []string
- func Interface(v *structpb.Value, opts ...Option) (any, error)
- func List(s []any, opts ...Option) (*structpb.ListValue, error)
- func Map(p *structpb.Struct, opts ...Option) (map[string]any, error)
- func Slice(l *structpb.ListValue, opts ...Option) ([]any, error)
- func Struct(m map[string]any, opts ...Option) (*structpb.Struct, error)
- func ValidateStruct(st *structpb.Struct) []string
- func Value(v any, opts ...Option) (*structpb.Value, error)
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoFieldsPaths ¶
func GoFieldsPaths(pb *field_mask.FieldMask, v any) []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/v3/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 ValidateStruct ¶ added in v3.25.0
ValidateStruct recursively verifies if the struct contains any invalid values (NaN, -Infinity, Infinity) and emits warning messages for such fields.
Types ¶
Click to show internal directories.
Click to hide internal directories.