Giter Site home page Giter Site logo

grpc-utils's Introduction

runtime

JSON marshal

JSON marshal is a combination of golang jsonbp and JSONBuiltin marshaler. This marshaler doesn't ignore json tags such as json:"myName" or json:"-"

⚠️ don't forget to import gogoproto in proto file

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

RemoveEmpty

RemoveEmpty overrides EmitDefaults option. It can be used to remove json:"something,omitempty" tags generated by some generators

usage:

in main file

mux := runtime.NewServeMux(runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONCustom{RemoveEmpty:true}))

proto file

message User{
    name string = 1 [(gogoproto.jsontag) = "NAME,removeEmpty"];
}

Nested

This feature can be used to nest fields in the resulting JSON while maintaining a flat structure in code.

⚠️ working only with structures generated from proto (use jsonproto marshaller)

Marshall:

Usage:

proto file

message Msg {
    Firstname string = 1 [(gogoproto.jsontag) = "name.firstname"];
    PseudoFirstname string = 2 [(gogoproto.jsontag) = "lastname"];
    EmbedMsg = 3  [(gogoproto.nullable) = false, (gogoproto.embed) = true];
    Lastname string = 4 [(gogoproto.jsontag) = "name.lastname"];
    Inside string  = 5 [(gogoproto.jsontag) = "name.inside.a.b.c"];
}

message EmbedMsg{
    Opt1 string = 1 [(gogoproto.jsontag) = "opt1"];
}
In your code:
msgInput := Msg{
    Firstname:       "One",
	Lastname:        "Two",
	PseudoFirstname: "Three",
	EmbedMsg: EmbedMsg{
		Opt1: "var",
	},
	Inside: "goo",
}
Output:
{
	"lastname": "Three",
	"name": {
		"firstname": "One",
		"inside": {
			"a": {
				"b": {
					"c": "goo"
				}
			}
		},
		"lastname": "Two"
	},
	"opt1": "var"
}

context

IncomingToOutgoingHeaderKey transforms incoming gRPC context into outgoing. It can be used when proxying gRPC requests.

usage:
someClient.someMethod(IncomingToOutgoingContext(ctx), &someMsg{})

grpc-utils's People

Contributors

rysavyvladan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.