gogoproto

package
v3.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gogoproto implements conversions from well-known gogo/profobuf types.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoFieldsPaths

func GoFieldsPaths(pb *pbtypes.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/v3/pkg/gogoproto"
	"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
)

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 := gogoproto.GoFieldsPaths(ttnpb.FieldMask("city.name_city"), london)
	fmt.Println(fields)

	fields = gogoproto.GoFieldsPaths(ttnpb.FieldMask("name_region"), holland)
	fmt.Println(fields)

}
Output:

[CityDetails.Name]
[NameOfTheRegion]

func Interface

func Interface(v *types.Value, opts ...Option) (interface{}, error)

Interface returns the Value proto as an interface{}.

func List

func List(s []interface{}, opts ...Option) (*types.ListValue, error)

List returns the slice as a ListValue proto.

func Map

func Map(p *types.Struct, opts ...Option) (map[string]interface{}, error)

Map returns the Struct proto as a map[string]interface{}.

func Slice

func Slice(l *types.ListValue, opts ...Option) ([]interface{}, error)

Slice returns the ListValue proto as a []interface{}.

func Struct

func Struct(m map[string]interface{}, opts ...Option) (*types.Struct, error)

Struct returns the map as a Struct proto.

func Value

func Value(v interface{}, opts ...Option) (*types.Value, error)

Value returns the value as a Value proto

Types

type Option added in v3.21.0

type Option func(*serializationState)

Option represents a serialization option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL