gogoproto

package
v0.0.0-...-60b8695 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 5 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"

	"github.com/aureliar8/ttn-fork/pkg/gogoproto"
	pbtypes "github.com/gogo/protobuf/types"
)

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(&pbtypes.FieldMask{
		Paths: []string{"city.name_city"},
	}, london)
	fmt.Println(fields)

	fields = gogoproto.GoFieldsPaths(&pbtypes.FieldMask{
		Paths: []string{"name_region"},
	}, holland)
	fmt.Println(fields)

}
Output:

[CityDetails.Name]
[NameOfTheRegion]

func Interface

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

Interface returns the Value proto as an interface{}.

func List

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

List returns the slice as a ListValue proto.

func Map

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

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

func Slice

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

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

func Struct

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

Struct returns the map as a Struct proto.

func Value

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

Value returns the value as a Value proto

Types

This section is empty.

Jump to

Keyboard shortcuts

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