Giter Site home page Giter Site logo

proteus's Introduction

proteus

GoDoc Build Status codecov License Go Report Card codebeat badge

Notice: This repository is abandoned, and no further updates will be done on the code base, nor issues/PRs will be answered or attended.

Proteus /proʊtiəs/ is a tool to generate protocol buffers version 3 compatible .proto files from your Go structs, types and functions.

The motivation behind this library is to use Go as a source of truth for your models instead of the other way around and then generating Go code from a .proto file, which does not generate idiomatic code.

Proteus scans all the code in the selected packages and generates protobuf messages for every exported struct (and all the ones that are referenced in any other struct, even though they are not exported). The types that semantically are used as enumerations in Go are transformed into proper protobuf enumerations. All the exported functions and methods will be turned into protobuf RPC services.

We want to build proteus in a very extensible way, so every step of the generation can be hackable via plugins and everyone can adapt proteus to their needs without actually having to integrate functionality that does not play well with the core library. We are releasing the plugin feature after Go 1.8 is released, which includes the plugin package of the standard library.

For an overall overview of the code architecture take a look at the architecture documentation.

You can read more about the motivations behind building proteus in this blog post.

Install

go get -v gopkg.in/src-d/proteus.v1/...

Requirements

There are two requirements for the full process.

  • protoc binary installed on your path
  • go get -u github.com/gogo/protobuf/...

Usage

You can generate the proto files, the marshal/unmarshal and the rest of protobuf stuff for your Go types, the RPC client and server interface and the RPC server implementation for your packages. That is, the whole process.

proteus -f /path/to/protos/folder \
        -p my/go/package \
        -p my/other/go/package

You can generate proto files only using the command line tool provided with proteus.

proteus proto -f /path/to/output/folder \
        -p my/go/package \
        -p my/other/go/package
        --verbose

You can also only generate gRPC server implementations for your packages.

proteus rpc -p my/go/package \
        -p my/other/go/package

NOTE: Of course, if the defaults don't suit your needs, until proteus is extensible via plugins, you can hack together your own generator command using the provided components. Check out the godoc documentation of the package.

Generate protobuf messages

Proteus will generate protobuf messages with the structure of structs with the comment //proteus:generate. Obviously, the structs have to be exported in Go (first letter must be in upper case).

//proteus:generate
type Exported struct {
        Field string
}

type NotExported struct {
        Field string
}

Generated by requirement

Note that, even if the struct is not explicitly exported, if another struct has a field of that type, it will be generated as well.

//proteus:generate
type Preference struct {
        Name string
        Value string
        Options Options
}

type Options struct {
        Enabled bool
}

In that example, even if Options is not explicitly generated, it will be because it is required to generate Preference.

So far, this does not happen if the field is an enum. It is a known problem and we are working on fixing it. Until said fix lands, please, explicitly mark enums to be generated.

Struct embedding

You can embed structs as usual and they will be generated as if the struct had the fields of the embedded struct.

//proteus:generate
type User struct {
        Model
        Username string
}

type Model struct {
        ID int
        CreatedAt time.Time
}

This example will generate the following protobuf message.

message User {
        int32 id = 1;
        google.protobuf.Timestamp created_at = 2;
        string username = 3;
}

CAUTION: if you redefine a field, it will be ignored and the one from the embedded will be taken. Same thing happens if you embed several structs and they have repeated fields. This may change in the future, for now this is the intended behaviour and a warning is printed.

Ignore specific fields

You can ignore specific fields using the struct tag proteus:"-".

//proteus:generate
type Foo struct {
        Bar int
        Baz int `proteus:"-"`
}

This becomes:

message Foo {
        int32 bar = 1;
}

Generating enumerations

You can make a type declaration (not a struct type declaration) be exported as an enumeration, instead of just an alias with the comment //proteus:generate.

//proteus:generate
type Status int

const (
        Pending Status = iota
        Active
        Closed
)

This will generate:

enum Status {
        PENDING = 0;
        ACTIVE = 1;
        CLOSED = 2;
}

NOTE: protobuf enumerations require you to start the enumeration with 0 and do not have gaps between the numbers. So keep that in mind when setting the values of your consts.

For example, if you have the following code:

type PageSize int

const (
        Mobile PageSize = 320
        Tablet PageSize = 768
        Desktop PageSize = 1024
)

Instead of doing an enumeration, consider not exporting the type and instead it will be treated as an alias of int32 in protobuf, which is the default behaviour for not exported types.

Generate services

For every package, a single service is generated with all the methods or functions having //proteus:generate.

For example, if you have the following package:

package users

//proteus:generate
func GetUser(id uint64) (*User, error) {
        // impl
}

//proteus:generate
func (s *UserStore) UpdateUser(u *User) error {
        // impl
}

The following protobuf service would be generated:

message GetUserRequest {
        uint64 arg1 = 1;
}

message UserStore_UpdateUserResponse {
}

service UsersService {
        rpc GetUser(users.GetUserRequest) returns (users.User);
        rpc UserStore_UpdateUser(users.User) returns (users.UserStore_UpdateUserResponse);
}

Note that protobuf does not support input or output types that are not messages or empty input/output, so instead of returning nothing in UserStore_UpdateUser it returns a message with no fields, and instead of receiving an integer in GetUser, receives a message with only one integer field. The last error type is ignored.

Generate RPC server implementation

gogo/protobuf generates the interface you need to implement based on your .proto file. The problem with that is that you actually have to implement that and maintain it. Instead, you can just generate it automatically with proteus.

Consider the Go code of the previous section, we could generate the implementation of that service.

Something like this would be generated:

type usersServiceServer struct {
}

func NewUsersServiceServer() *usersServiceServer {
        return &usersServiceServer{}
}

func (s *userServiceServer) GetUser(ctx context.Context, in *GetUserRequest) (result *User, err error) {
        result = GetUser(in.Arg1)
        return
}

func (s *userServiceServer) UserStore_UpdateUser(ctx context.Context, in *User) (result *UserStore_UpdateUser, err error) {
        s.UserStore.UpdateUser(in)
        return
}

There are 3 interesting things in the generated code that, of course, would not work:

  • usersServiceServer is a generated empty struct.
  • NewUsersServiceServer is a generated constructor for usersServiceServer.
  • UserStore_UpdateUser uses the field UserStore of userServiceServer that, indeed, does not exist.

The server struct and its constructor are always generated empty but only if they don't exist already. That means that you can, and should, implement them yourself to make this code work.

For every method you are using, you are supposed to implement a receiver in the server type and initialize it however you want in the constructor. How would we fix this?

type userServiceServer struct {
        UserStore *UserStore
}

func NewUserServiceServer() *userServiceServer {
        return &userServiceServer{
                UserStore: NewUserStore(),
        }
}

Now if we generate the code again, the server struct and the constructor are implemented and the defaults will not be added again. Also, UserStore_UpdateUser would be able to find the field UserStore in userServiceServer and the code would work.

Not scanned types

What happens if you have a type in your struct that is not in the list of scanned packages? It is completely ignored. The only exception to this are time.Time and time.Duration, which are allowed by default even though you are not adding time package to the list.

In the future, this will be extensible via plugins.

Examples

You can find an example of a real use case on the example folder. For checking how the server and client works, see server.go and client.go. The orchestration of server and client is done in example_test.go. The example creates a server and a new client and tests the output.

Features to come

  • Extensible mapping and options via plugins (waiting for Go 1.8 release).

Known Limitations

The following is a list of known limitations and the current state of them.

  • Only {,u}int32 and {,u}int64 is supported in protobuf. Therefore, all {,u}int types are upgraded to the next size and a warning is printed. Same thing happens with floats and doubles.
  • If a struct contains a field of type time.Time, then that struct can only be serialized and deserialized using the Marshal and Unmarshal methods. Other marshallers use reflection and need a few struct tags generated by protobuf that your struct won't have. This also happens with fields whose type is a declaration to a slice of another type (type Alias []base).

Contribute

If you are interested on contributing to proteus, open an issue explaining which missing functionality you want to work in, and we will guide you through the implementation, and tell you beforehand if that is a functionality we might consider merging in the first place.

License

MIT, see LICENSE

proteus's People

Contributors

ajnavarro avatar dennwc avatar erizocosmico avatar jhayotte avatar jwilander avatar marnovo avatar mcuadros avatar serabe avatar smacker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proteus's Issues

Issue with time.Duration

This works fine:

package mytest

type MyDuration int64

//proteus:generate
type MyType struct {
        Sleeping MyDuration
}
$ proteus -p github.com/alban/mytest -f . ; echo $?
0

But this does not work:

package mytest

import (
        "time"
)

//proteus:generate
type MyType struct {
        Sleeping time.Duration
}
$ proteus -p github.com/alban/mytest -f . ; echo $?
generated.proto: warning: Import google/protobuf/duration.proto but not used.
ERROR: field MyType.Sleeping is a native type and in proto3 syntax with nullable=false there exists conflicting implementations when encoding zero values--gofast_out: protoc-gen-gofast: Plugin failed with status code 1.
error generating Go files from "github.com/alban/mytest/generated.proto": exit status 1
1

I don't understand what that means. time.Duration is basically a int64, so what's the difference between the two code snippets?

/cc @asymmetric

provide a mechanism to add a license header to generated files

In order to comply with licensing requirements, some projects require that every file, included autogenerated ones, start with a predefined copyright header.

It would be nice if proteus provided a way of specifying that header. Maybe with a CLI option --header <path-to-header-file>.

My initial idea was having a flag --include-header that takes the license header from source files, if any. But as @Serabe pointed out, a proto can be generated from many files, so making it automagic is problematic.

zsh: command not found: proteus

After installing this library with go get -v gopkg.in/src-d/proteus.v1/... I receive the zsh: command not found: proteus eror. I am using this on a Mac. Any hints?

Avoid generating String() methods

proteus generates a String() method for my enums, but I already have one (generated by stringer). So I would like to avoid generating this String() method.

I don't care if this is a command line flag enabling it globally or annotation-based opt-in per type. Both would work for me.

➜  sdk git:(expand-uast) ✗ proteus --pkg github.com/bblfsh/sdk/uast --pkg github.com/bblfsh/sdk/protocol -f $GOPATH/src/github.com/bblfsh/sdk/protos --verbose
WARN: ignoring type interface{Next() /home/smola/dev/go/src/github.com/bblfsh/sdk/uast.Path}
WARN: ignoring type interface{Step(); /home/smola/dev/go/src/github.com/bblfsh/sdk/uast.PathIter}
WARN: ignoring type interface{ToNode(src interface{}) (*/home/smola/dev/go/src/github.com/bblfsh/sdk/uast.Node, error)}
error scanning package "github.com/bblfsh/sdk/protocol": /home/smola/dev/go/src/github.com/bblfsh/sdk/protocol/protocol.go:4:2: could not import github.com/bblfsh/sdk/uast (/home/smola/dev/go/src/github.com/bblfsh/sdk/uast/role_string.go:11:15: method String already declared for Role)

proteus complains about test packages

Proteus complains about test packages:

$ proteus -f $PWD/proteus/ -p github.com/weaveworks/scope/report
error scanning package "github.com/weaveworks/scope/report": more than one package found in a directory
$ cat report/* | grep package | sort | uniq
package report
package report_test

Workaround: delete the tests with rm *test.go

Unknown import when using timestamp

If you use timestamp in a package, the resultant file generated by gogoproto contains this import:

import _ "google/protobuf"

This import, obviously, doesn't exist.

Wrong message field type in generated proto file for a named type of []byte

Right now I am doing something like this:

type OrderID []byte

type Order struct {
	ID          OrderID
	description string
}

The proto generated by proteus was:

message Order {
	option (gogoproto.goproto_getters) = false;
	option (gogoproto.typedecl) = false;
	repeated uint32 id = 1 [(gogoproto.casttype) = "byte", (gogoproto.customname) = "ID"];
}

The expected output:

message Order {
	option (gogoproto.goproto_getters) = false;
	option (gogoproto.typedecl) = false;
	repeated bytes id = 1 [(gogoproto.casttype) = "OrderID", (gogoproto.customname) = "ID"];
}

method redeclared: Size

The method Size() is defined both in the source and in the generated file:

# github.com/weaveworks/scope/report
report/generated.pb.go:57: undefined: "github.com/weaveworks/scope/vendor/github.com/golang/protobuf/proto".ProtoPackageIsVersion2
report/generated.pb.go:151: undefined: "github.com/weaveworks/scope/vendor/github.com/golang/protobuf/proto".RegisterType
report/generated.pb.go:152: undefined: "github.com/weaveworks/scope/vendor/github.com/golang/protobuf/proto".RegisterType
report/generated.pb.go:153: undefined: "github.com/weaveworks/scope/vendor/github.com/golang/protobuf/proto".RegisterType
report/generated.pb.go:1250: method redeclared: Counters.Size
	method(Counters) func() int
	method(*Counters) func() int
report/generated.pb.go:1256: method redeclared: EdgeMetadatas.Size
	method(EdgeMetadatas) func() int
	method(*EdgeMetadatas) func() int
report/latest_map_generated.go:47: method redeclared: StringLatestMap.Size
	method(*StringLatestMap) func() int
	method(StringLatestMap) func() int
report/latest_map_generated.go:199: method redeclared: NodeControlDataLatestMap.Size
	method(*NodeControlDataLatestMap) func() int
	method(NodeControlDataLatestMap) func() int
report/node_set.go:100: method redeclared: NodeSet.Size
	method(*NodeSet) func() int
	method(NodeSet) func() int
report/sets.go:71: method redeclared: Sets.Size
	method(*Sets) func() int
	method(Sets) func() int
report/generated.pb.go:153: too many errors

Note: I am using this branch in Scope for testing.

Refactor Transformer

While implementing enum-typed fields, state needed to be added to transformer.

Would be nice to refactor the transform process to account for this and ease the pain.

type ... will be ignored because it was not present on the scan path.

proteus handles []byte,

>proteus  proto -f /tmp/proteus -p ufdata/tst --verbose
INFO: Generated proto: /tmp/proteus/ufdata/tst/generated.proto

>cat ./main.go 
package main

// Exported smth
//proteus:generate
type Exported struct {
	Field string
	SrcIP []byte `json:"src_ip"`
}

while does not handle net.IP which is effectively the same producing
type "IP" of package net will be ignored because it was not present on the scan path.

>proteus  proto -f /tmp/proteus -p ufdata/tst --verbose
WARN: type "IP" of package net will be ignored because it was not present on the scan path.
INFO: Generated proto: /tmp/proteus/ufdata/tst/generated.proto
>cat ./main.go 
package main

import "net"

// Exported smth
//proteus:generate
type Exported struct {
	Field string
	SrcIP net.IP `json:"src_ip"`
}

I can see in strace that proteus reads net/ip.go source file, while it does not help.
Is there any way to use such types?

Does not worker with time.Time field

error scanning package "git.byted.org/ee/byteview/svc/core/model": 

/Users/xxx/go/src/git.byted.org/ee/byteview/svc/core/model/model.go:3:8: 

could not import time (/Users/xxx/go/gosdk/go1.14/src/time/format.go:7:8: 

could not import errors (/Users/xxx/go/gosdk/go1.14/src/errors/wrap.go:8:2: 

could not import internal/reflectlite(/Users/xxx/go/gosdk/go1.14/src/internal/reflectlite/value.go:8:2: 

could not import runtime (/Users/xxx/go/gosdk/go1.14/src/runtime/atomic_pointer.go:8:2: 

could not import runtime/internal/atomic (/Users/xxx/go/gosdk/go1.14/src/runtime/internal/atomic/atomic_amd64.go:23:28: 

cannot convert ptr (variable of type unsafe.Pointer) to *unsafe.Pointer)))))

Rename `newNamed` in scanner/scanner_test

There is newNamed in scanner/scanner_test and NewNamed in scanner/package. They are both used in tests

{
    "named type",
    newNamed("/foo/bar", "Bar", nil),
    NewNamed("/foo/bar", "Bar"),
},

print a meaninful error when string enums are used

When a string type is used as a enum-like, proteus does generate code, but that code is invalid and fails to build.

For example:

➜  server git:(initial-version) ✗ go build ./cmd/bblfsh/...
# github.com/bblfsh/sdk/protocol
../sdk/protocol/generated.pb.go:233: cannot convert 0 to type Status
../sdk/protocol/generated.pb.go:233: invalid operation: m.Status != 0 (mismatched types Status and int)
../sdk/protocol/generated.pb.go:236: cannot convert m.Status (type Status) to type uint64
../sdk/protocol/generated.pb.go:305: cannot convert 0 to type Status
../sdk/protocol/generated.pb.go:305: invalid operation: m.Status != 0 (mismatched types Status and int)
../sdk/protocol/generated.pb.go:308: cannot convert m.Status (type Status) to type uint64
../sdk/protocol/generated.pb.go:378: cannot convert 0 to type Status
../sdk/protocol/generated.pb.go:378: invalid operation: m.Status != 0 (mismatched types Status and int)
../sdk/protocol/generated.pb.go:379: cannot convert m.Status (type Status) to type uint64
../sdk/protocol/generated.pb.go:407: cannot convert 0 to type Status
../sdk/protocol/generated.pb.go:407: too many errors

I saw it is actually documented in the README.md, but it would still be good to give an error or a warning when calling proteus.

could not import fmt

I'm getting an error when I run proteus on a very basic example package.

[aoneill@foolxps blah]$ proteus proto -f $HOME/src/aponeill.com/blah/blahpb -p aponeill.com/blah
error scanning package "aponeill.com/blah": /home/aoneill/src/aponeill.com/blah/blah.go:3:8: could not import fmt (/home/aoneill/go-tip/src/fmt/format.go:8:2: could not import strconv (/home/aoneill/go-tip/src/strconv/atof.go:13:8: could not import math (/home/aoneill/go-tip/src/map

the blah package just includes

package blah // import "aponeill.com/blah"

import "fmt"

//proteus:generate
type Blah struct {
        Name string
}

//proteus:generate
func (b *Blah) Blaher() {
        fmt.Println("blah")
}

any idea what is going on here?

master doesn't build

Cloning into '/home/mvdan/go/land/src/gopkg.in/src-d/go-parse-utils.v1'...
error: RPC failed; HTTP 301 curl 22 The requested URL returned error: 301

Reproducible via git clone https://gopkg.in/src-d/go-parse-utils.v1

Make Scope work with Proteus

Repo: https://github.com/kinvolk/scope/tree/alban/proteus

The problem is related to map[string]SomeStruct, given the value type is not nullable and protobuf expects so. I'm investigating an option for gogo/protobuf to allow a value type to be nullable in a map.

Current problems:

  • report/generated.pb.go:535: cannot convert nil to type Metric
  • report/generated.pb.go:545: cannot convert nil to type Metric
  • report/generated.pb.go:1057: cannot convert nil to type Node
  • report/generated.pb.go:1067: cannot convert nil to type Node
  • report/generated.pb.go:1085: cannot convert nil to type Control
  • report/generated.pb.go:1095: cannot convert nil to type Control
  • report/generated.pb.go:1113: cannot convert nil to type MetadataTemplate
  • report/generated.pb.go:1123: cannot convert nil to type MetadataTemplate
  • report/generated.pb.go:1141: cannot convert nil to type MetricTemplate
  • report/generated.pb.go:1151: cannot convert nil to type MetricTemplate

m.XXX_unrecognized undefined

hello,

when I run my app, the follow error is returning:

JPFARIA-MacBook-Pro:server jpfaria$ go run main.go

gitlab.b2w/joao.faria/knativegrpcexample

../generated.pb.go:288:6: m.XXX_unrecognized undefined (type *User has no field or method XXX_unrecognized)
../generated.pb.go:289:24: m.XXX_unrecognized undefined (type *User has no field or method XXX_unrecognized)
../generated.pb.go:351:6: m.XXX_unrecognized undefined (type *User has no field or method XXX_unrecognized)
../generated.pb.go:352:13: m.XXX_unrecognized undefined (type *User has no field or method XXX_unrecognized)
../generated.pb.go:564:5: m.XXX_unrecognized undefined (type *User has no field or method XXX_unrecognized)

Proteus is no longer maintained

It's been years since proteus has had any activity. The parent company, source{d}, website https://sourced.tech/ has been down for months and the original authors @Serabe and @erizocosmico no longer work at source{d} according to LinkedIn. The only two people still in the src-d organization are @eiso and @marnovo. Maybe they can give us some clarity.

If I could, I'd pick things up, but unfortunately that isn't possible for me right now. There are a few forks that are ahead and I'm going to list them here to maybe get their attention.

@daniel-sullivan (via charm-jp)
@michelaquino
@alidawud
@zimbabao

Is anyone willing to pick up this tool and give it the love that it needs?

Don't inline fields of embedded messages, keep them as separated messages

Right now, if we do something like the following:

type Model struct {
  ID int64
}

type User struct {
  Model
  Name string
}

The result of the proto generated by proteus is:

message User {
  int64 id = 1;
  string name = 2;
}

Which works fine right now, but we should maybe change it because as a result, Model is not generated and does not get its ProtoMessage and all the mumbo jumbo it should have generated for it, which can be a mess for reflection-based marshal/unmarshal if we finally make it work with that.

Right now it works, but we should evaluate if this is worth fixing/changing or not in the long run.

Error calling proteus under Windows

Hello,
when I try to call proteus.exe on Windows I get errors because I'm not able to understand the path format to use to specify -f and -p parameters.
I'm trying to generate proto files for package github.com/SMerrony/tello.
Assume that:

  1. current folder is: C:\Users\Filippo\go\src\github.com\SMerrony\tello
  2. in tello folder I have created a subfolder named protos
  3. $GOPATH is C:\Users\Filippo\go

If I call proteus I get:

  • proteus -f .\protos -p github.com/SMerrony/tello
    • error scanning package "github.com/SMerrony/tello": La sintassi del nome del file, della directory o del volume non è corretta.
  • proteus -f .\protos -p C:\Users\Filippo\go\src\github.com\SMerrony\tello
    • CreateFile C:\Users\Filippo\go\src\C:\Users\Filippo\go\src\github.com\SMerrony\tello: La sintassi del nome del file, della directory o del volume non è corretta.

How can I solve this issue on Windows?

Regards,
Filippo.

Proteus is generating a proto message even when the struct is not marked for generation:

the structs are not marked for generation but proteus is generating a proto file with a Address message related to Address type from go code. Check below what I am doing:

package order

type Address struct {
	City    string
	Country string
	Line1   string
	Line2   string
	ZipCode string
	State   string
}

type Shipping struct {
	Address        *Address
	Carrier        string
	FirstName      string
	LastName       string
	Phone          string
	TrackingNumber string
}

Output after proteus execution:

syntax = "proto3";
package example.pkg.order;

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

option (gogoproto.protosizer_all) = true;
option (gogoproto.sizer_all) = false;
option go_package = "order";

message Address {
	option (gogoproto.goproto_getters) = false;
	option (gogoproto.typedecl) = false;
	string city = 1;
	string country = 2;
	string line1 = 3;
	string line2 = 4;
	string zip_code = 5;
	string state = 6;
}

Expected output:

syntax = "proto3";
package example.pkg.order;

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

option (gogoproto.protosizer_all) = true;
option (gogoproto.sizer_all) = false;
option go_package = "order";

I think that is a bug because it is working proper if the Address type is embedded in the Shipping type for example:

package order

type Address struct {
	City    string
	Country string
	Line1   string
	Line2   string
	ZipCode string
	State   string
}

type Shipping struct {
	Address
	Carrier        string
	FirstName      string
	LastName       string
	Phone          string
	TrackingNumber string
}

Update docs

  • Architecture documentation
  • Update README to reflect current features

Some files in multi-file package ignored

I'm trying to generate protobufs for openrtb, but some of the data structures i need in the files bid_request.go and bid_response.go aren't being generated, and without any warning or output explaining why.

I figured it might be a naming issue, so I renamed them to be one word with no underscore, both camel case and all lower case. Neither worked.

I'd really like to be able to use this project, it would make my life so much easier, but this is a real brick wall for me.

Any insight?

Running with this script
proteus proto -p gopkg.in/mxmCherry/openrtb.v2 \ -f ./openrtb-protobuf --verbose

I run some extra sed/grep magic to do some extra stuff, but I've confirmed it's not what is interfering here.

Thanks for the help.

Windows?

Don't work under Windows!

C:\goworkspace\models>proteus proto -f C:\test -p gitlink/models --verbose
mkdir C:\test\C::  Error....

other test

C:\goworkspace\models>proteus proto -f /test -p gitlink/models --verbose
mkdir \test\C::  Error....

generated code uses wrong package

$ go get github.com/bblfsh/sdk
$ cd $GOPATH/src/github.com/bblfsh/sdk
$ proteus  -f $GOPATH/src/github.com/bblfsh/sdk/protos -p github.com/bblfsh/sdk/protocol -p github.com/bblfsh/sdk/uast --verbose
$ go build ./protocol/...
# github.com/bblfsh/sdk/protocol
protocol/generated.pb.go:503: undefined: github_com_bblfsh_sdk_uast in github_com_bblfsh_sdk_uast.Node
protocol/generated.pb.go:723: undefined: github_com_bblfsh_sdk_uast in github_com_bblfsh_sdk_uast.Node

The following patch applied manually to the generated code makes it build again:

diff --git a/protocol/generated.pb.go b/protocol/generated.pb.go
index cb0e03b..6b03fce 100644
--- a/protocol/generated.pb.go
+++ b/protocol/generated.pb.go
@@ -20,7 +20,7 @@ import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
 import _ "github.com/gogo/protobuf/gogoproto"
-import _ "github.com/bblfsh/sdk/uast"
+import github_com_bblfsh_sdk_uast "github.com/bblfsh/sdk/uast"
 
 import (
        context "golang.org/x/net/context"

Improve `time.Time` support in RPC

Currently, in RPC inputs or outputs containing only time.Time does not retrieve the proper type. I think this is related to the stdtime plugin not being supported in gRPC services, but more research needs to be done.

Problem with type `int`

Problem

There is no int in protobuf, only int32 and int64. Then, when we generate the .proto file we have to choose between one of them. Right now, the choice is int32.

Problem is, when doing the gogoproto step, it takes into account the proto file, and not the Go source code, and thus what it thinks is that the type is an int32 instead of int.

Steps to reproduce:

  • Generate this:
package foo

//proteus:generate
type Foo struct {
        A int
}

Fix

  • Set custom type on proto when the type has no direct translation in protobuf
  • Change the transation of int to int64 and uint to uint64 in protobuf

Caveats

  • It probably happens as well with time.Duration and all the types that don't have a clear direct mapping (all other ints besides signed and unsigned int32 and int64)

map[string][]string is converted to map<string, string>

Hello,
I've got an issue with theb generated protobuf.
My function signature is
FindApp(ctx context.Context, criteria map[string][]string) ([]App, error)

The generated rpc parameter is

message appservice_FindAppRequest {
	map<string, string> arg1 = 1;
}

Is it normal ?
I tried to convert map[string][]string to a proper type like that:

type CriteriaList []string
type SearchCriteria map[string]CriteriaList

But the generated code is still the same.
I think it ois a bug but I'm not sure.
Thanks a lot for your help !

Names of fields can't be converted back to their original name

On the step to generate the marshal code from the protobuf we can't generate the previous names we had.

Go source:

type Foo struct {
        ID uint64
}

Proto:

message Foo {
        uint64 id = 1;
}

What gogoproto thinks it should generate:

type Foo struct {
        Id uint64
}

We have two options:

  • Leave it as is and document that behaviour: FooURL => FooUrl
  • Somehow fix this in gogoprotobuf via an option field.

How to use FieldMask type?

Hi

I would like to use gRPC FieldMask type. Is there any way to be control generated protobuf definition?

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.