example

package
v0.0.0-...-26b160e Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0, MIT Imports: 11 Imported by: 0

README

Proteus examples

This example shows how to use proteus for a typical use case. Imagine you have your Go models and you need to generate some .proto files to match that models. It has some entities like the ones you could have on a database.

To generate the .proto you can use the proteus binary:

proteus proto -p github.com/src-d/proteus/example \
              -f $GOPATH/src/github.com/src-d/proteus/example/protos \
              --verbose

The generated file will be in:

$GOPATH/src/github.com/src-d/proteus/example/protos/github.com/proteus/example/generated.proto

You can also use make regenerate

Documentation

Overview

Package example is a generated protocol buffer package.

It is generated from these files:

gopkg.in/src-d/proteus.v1/example/protos/gopkg.in/src-d/proteus.v1/example/generated.proto

It has these top-level messages:

Category
MyDuration
MyTime
Price
Product
GetAlphaTimeRequest
GetDurationForLengthRequest
GetDurationForLengthCtxRequest
GetOmegaTimeRequest
GetPhoneRequest
RandomCategoryRequest
RandomNumberRequest
RandomNumberResponse

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowGenerated   = fmt.Errorf("proto: integer overflow")
)
View Source
var Type_name = map[int32]string{
	0: "PUBLIC",
	1: "PRIVATE",
	2: "CUSTOM",
}

Type will be transformed into an enum.

View Source
var Type_value = map[string]int32{
	"PUBLIC":  0,
	"PRIVATE": 1,
	"CUSTOM":  2,
}

Functions

func NewExampleServiceServer

func NewExampleServiceServer() *exampleServiceServer

func RandomBool

func RandomBool() bool

func RandomCategory

func RandomCategory() categories.CategoryOptions

func RandomNumber

func RandomNumber(mean, std float64) float64

func RegisterExampleServiceServer

func RegisterExampleServiceServer(s *grpc.Server, srv ExampleServiceServer)

Types

type Category

type Category struct {
	Model

	Name    string
	Type    Type
	Color   Color
	Options categories.CategoryOptions
}

func (*Category) Descriptor

func (*Category) Descriptor() ([]byte, []int)

func (*Category) Marshal

func (m *Category) Marshal() (dAtA []byte, err error)

func (*Category) MarshalTo

func (m *Category) MarshalTo(dAtA []byte) (int, error)

func (*Category) ProtoMessage

func (*Category) ProtoMessage()

func (*Category) ProtoSize

func (m *Category) ProtoSize() (n int)

func (*Category) Reset

func (m *Category) Reset()

func (*Category) String

func (c *Category) String() string

func (*Category) Unmarshal

func (m *Category) Unmarshal(dAtA []byte) error

type Color

type Color string

Color does not have proteus:generate in a comment, so all fields of type Color will be treated as just string, not as an enum.

const (
	Blue   Color = "blue"
	Red    Color = "red"
	Yellow Color = "yellow"
)

type ExampleServiceClient

type ExampleServiceClient interface {
	GetAlphaTime(ctx context.Context, in *GetAlphaTimeRequest, opts ...grpc.CallOption) (*MyTime, error)
	GetDurationForLength(ctx context.Context, in *GetDurationForLengthRequest, opts ...grpc.CallOption) (*MyDuration, error)
	GetDurationForLengthCtx(ctx context.Context, in *GetDurationForLengthCtxRequest, opts ...grpc.CallOption) (*MyDuration, error)
	GetOmegaTime(ctx context.Context, in *GetOmegaTimeRequest, opts ...grpc.CallOption) (*MyTime, error)
	GetPhone(ctx context.Context, in *GetPhoneRequest, opts ...grpc.CallOption) (*Product, error)
	RandomCategory(ctx context.Context, in *RandomCategoryRequest, opts ...grpc.CallOption) (*gopkg_in_srcd_proteus_v1_example_categories.CategoryOptions, error)
	RandomNumber(ctx context.Context, in *RandomNumberRequest, opts ...grpc.CallOption) (*RandomNumberResponse, error)
}

func NewExampleServiceClient

func NewExampleServiceClient(cc *grpc.ClientConn) ExampleServiceClient

type GetAlphaTimeRequest

type GetAlphaTimeRequest struct {
}

func (*GetAlphaTimeRequest) Descriptor

func (*GetAlphaTimeRequest) Descriptor() ([]byte, []int)

func (*GetAlphaTimeRequest) Marshal

func (m *GetAlphaTimeRequest) Marshal() (dAtA []byte, err error)

func (*GetAlphaTimeRequest) MarshalTo

func (m *GetAlphaTimeRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetAlphaTimeRequest) ProtoMessage

func (*GetAlphaTimeRequest) ProtoMessage()

func (*GetAlphaTimeRequest) ProtoSize

func (m *GetAlphaTimeRequest) ProtoSize() (n int)

func (*GetAlphaTimeRequest) Reset

func (m *GetAlphaTimeRequest) Reset()

func (*GetAlphaTimeRequest) String

func (m *GetAlphaTimeRequest) String() string

func (*GetAlphaTimeRequest) Unmarshal

func (m *GetAlphaTimeRequest) Unmarshal(dAtA []byte) error

type GetDurationForLengthCtxRequest

type GetDurationForLengthCtxRequest struct {
	Arg1 int64 `protobuf:"varint,1,opt,name=arg1,proto3" json:"arg1,omitempty"`
}

func (*GetDurationForLengthCtxRequest) Descriptor

func (*GetDurationForLengthCtxRequest) Descriptor() ([]byte, []int)

func (*GetDurationForLengthCtxRequest) GetArg1

func (*GetDurationForLengthCtxRequest) Marshal

func (m *GetDurationForLengthCtxRequest) Marshal() (dAtA []byte, err error)

func (*GetDurationForLengthCtxRequest) MarshalTo

func (m *GetDurationForLengthCtxRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetDurationForLengthCtxRequest) ProtoMessage

func (*GetDurationForLengthCtxRequest) ProtoMessage()

func (*GetDurationForLengthCtxRequest) ProtoSize

func (m *GetDurationForLengthCtxRequest) ProtoSize() (n int)

func (*GetDurationForLengthCtxRequest) Reset

func (m *GetDurationForLengthCtxRequest) Reset()

func (*GetDurationForLengthCtxRequest) String

func (*GetDurationForLengthCtxRequest) Unmarshal

func (m *GetDurationForLengthCtxRequest) Unmarshal(dAtA []byte) error

type GetDurationForLengthRequest

type GetDurationForLengthRequest struct {
	Arg1 int64 `protobuf:"varint,1,opt,name=arg1,proto3" json:"arg1,omitempty"`
}

func (*GetDurationForLengthRequest) Descriptor

func (*GetDurationForLengthRequest) Descriptor() ([]byte, []int)

func (*GetDurationForLengthRequest) GetArg1

func (m *GetDurationForLengthRequest) GetArg1() int64

func (*GetDurationForLengthRequest) Marshal

func (m *GetDurationForLengthRequest) Marshal() (dAtA []byte, err error)

func (*GetDurationForLengthRequest) MarshalTo

func (m *GetDurationForLengthRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetDurationForLengthRequest) ProtoMessage

func (*GetDurationForLengthRequest) ProtoMessage()

func (*GetDurationForLengthRequest) ProtoSize

func (m *GetDurationForLengthRequest) ProtoSize() (n int)

func (*GetDurationForLengthRequest) Reset

func (m *GetDurationForLengthRequest) Reset()

func (*GetDurationForLengthRequest) String

func (m *GetDurationForLengthRequest) String() string

func (*GetDurationForLengthRequest) Unmarshal

func (m *GetDurationForLengthRequest) Unmarshal(dAtA []byte) error

type GetOmegaTimeRequest

type GetOmegaTimeRequest struct {
}

func (*GetOmegaTimeRequest) Descriptor

func (*GetOmegaTimeRequest) Descriptor() ([]byte, []int)

func (*GetOmegaTimeRequest) Marshal

func (m *GetOmegaTimeRequest) Marshal() (dAtA []byte, err error)

func (*GetOmegaTimeRequest) MarshalTo

func (m *GetOmegaTimeRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetOmegaTimeRequest) ProtoMessage

func (*GetOmegaTimeRequest) ProtoMessage()

func (*GetOmegaTimeRequest) ProtoSize

func (m *GetOmegaTimeRequest) ProtoSize() (n int)

func (*GetOmegaTimeRequest) Reset

func (m *GetOmegaTimeRequest) Reset()

func (*GetOmegaTimeRequest) String

func (m *GetOmegaTimeRequest) String() string

func (*GetOmegaTimeRequest) Unmarshal

func (m *GetOmegaTimeRequest) Unmarshal(dAtA []byte) error

type GetPhoneRequest

type GetPhoneRequest struct {
}

func (*GetPhoneRequest) Descriptor

func (*GetPhoneRequest) Descriptor() ([]byte, []int)

func (*GetPhoneRequest) Marshal

func (m *GetPhoneRequest) Marshal() (dAtA []byte, err error)

func (*GetPhoneRequest) MarshalTo

func (m *GetPhoneRequest) MarshalTo(dAtA []byte) (int, error)

func (*GetPhoneRequest) ProtoMessage

func (*GetPhoneRequest) ProtoMessage()

func (*GetPhoneRequest) ProtoSize

func (m *GetPhoneRequest) ProtoSize() (n int)

func (*GetPhoneRequest) Reset

func (m *GetPhoneRequest) Reset()

func (*GetPhoneRequest) String

func (m *GetPhoneRequest) String() string

func (*GetPhoneRequest) Unmarshal

func (m *GetPhoneRequest) Unmarshal(dAtA []byte) error

type Model

type Model struct {
	ID        int64
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt time.Time
}

Model is not marked for generation, so it won't be generated.

type MyDuration

type MyDuration struct {
	Duration time.Duration
	Name     string
}

func GetDurationForLength

func GetDurationForLength(meters int64) *MyDuration

func GetDurationForLengthCtx

func GetDurationForLengthCtx(ctx context.Context, meters int64) (*MyDuration, error)

func (*MyDuration) Descriptor

func (*MyDuration) Descriptor() ([]byte, []int)

func (*MyDuration) Marshal

func (m *MyDuration) Marshal() (dAtA []byte, err error)

func (*MyDuration) MarshalTo

func (m *MyDuration) MarshalTo(dAtA []byte) (int, error)

func (*MyDuration) ProtoMessage

func (*MyDuration) ProtoMessage()

func (*MyDuration) ProtoSize

func (m *MyDuration) ProtoSize() (n int)

func (*MyDuration) Reset

func (m *MyDuration) Reset()

func (*MyDuration) String

func (m *MyDuration) String() string

func (*MyDuration) Unmarshal

func (m *MyDuration) Unmarshal(dAtA []byte) error

type MyTime

type MyTime struct {
	Time time.Time
	Name string
}

func GetAlphaTime

func GetAlphaTime() MyTime

func GetOmegaTime

func GetOmegaTime() (*MyTime, error)

func (*MyTime) Descriptor

func (*MyTime) Descriptor() ([]byte, []int)

func (*MyTime) Marshal

func (m *MyTime) Marshal() (dAtA []byte, err error)

func (*MyTime) MarshalTo

func (m *MyTime) MarshalTo(dAtA []byte) (int, error)

func (*MyTime) ProtoMessage

func (*MyTime) ProtoMessage()

func (*MyTime) ProtoSize

func (m *MyTime) ProtoSize() (n int)

func (*MyTime) Reset

func (m *MyTime) Reset()

func (*MyTime) String

func (m *MyTime) String() string

func (*MyTime) Unmarshal

func (m *MyTime) Unmarshal(dAtA []byte) error

type Price

type Price struct {
	Currency string
	Amount   int64
}

func (*Price) Descriptor

func (*Price) Descriptor() ([]byte, []int)

func (*Price) Marshal

func (m *Price) Marshal() (dAtA []byte, err error)

func (*Price) MarshalTo

func (m *Price) MarshalTo(dAtA []byte) (int, error)

func (*Price) ProtoMessage

func (*Price) ProtoMessage()

func (*Price) ProtoSize

func (m *Price) ProtoSize() (n int)

func (*Price) Reset

func (m *Price) Reset()

func (*Price) String

func (m *Price) String() string

func (*Price) Unmarshal

func (m *Price) Unmarshal(dAtA []byte) error

type Prices

type Prices map[string]Price

type Product

type Product struct {
	Model

	Name  string
	Price Prices

	Tags              Tags
	CategoryID        int64
	PrimaryCategoryID int8
	// Category will not be generated because we explicitly said so.
	Category Category `proteus:"-"`
}

func GetPhone

func GetPhone() *Product

func (*Product) Descriptor

func (*Product) Descriptor() ([]byte, []int)

func (*Product) Marshal

func (m *Product) Marshal() (dAtA []byte, err error)

func (*Product) MarshalTo

func (m *Product) MarshalTo(dAtA []byte) (int, error)

func (*Product) ProtoMessage

func (*Product) ProtoMessage()

func (*Product) ProtoSize

func (m *Product) ProtoSize() (n int)

func (*Product) Reset

func (m *Product) Reset()

func (*Product) String

func (m *Product) String() string

func (*Product) Unmarshal

func (m *Product) Unmarshal(dAtA []byte) error

type RandomCategoryRequest

type RandomCategoryRequest struct {
}

func (*RandomCategoryRequest) Descriptor

func (*RandomCategoryRequest) Descriptor() ([]byte, []int)

func (*RandomCategoryRequest) Marshal

func (m *RandomCategoryRequest) Marshal() (dAtA []byte, err error)

func (*RandomCategoryRequest) MarshalTo

func (m *RandomCategoryRequest) MarshalTo(dAtA []byte) (int, error)

func (*RandomCategoryRequest) ProtoMessage

func (*RandomCategoryRequest) ProtoMessage()

func (*RandomCategoryRequest) ProtoSize

func (m *RandomCategoryRequest) ProtoSize() (n int)

func (*RandomCategoryRequest) Reset

func (m *RandomCategoryRequest) Reset()

func (*RandomCategoryRequest) String

func (m *RandomCategoryRequest) String() string

func (*RandomCategoryRequest) Unmarshal

func (m *RandomCategoryRequest) Unmarshal(dAtA []byte) error

type RandomNumberRequest

type RandomNumberRequest struct {
	Arg1 float64 `protobuf:"fixed64,1,opt,name=arg1,proto3" json:"arg1,omitempty"`
	Arg2 float64 `protobuf:"fixed64,2,opt,name=arg2,proto3" json:"arg2,omitempty"`
}

func (*RandomNumberRequest) Descriptor

func (*RandomNumberRequest) Descriptor() ([]byte, []int)

func (*RandomNumberRequest) GetArg1

func (m *RandomNumberRequest) GetArg1() float64

func (*RandomNumberRequest) GetArg2

func (m *RandomNumberRequest) GetArg2() float64

func (*RandomNumberRequest) Marshal

func (m *RandomNumberRequest) Marshal() (dAtA []byte, err error)

func (*RandomNumberRequest) MarshalTo

func (m *RandomNumberRequest) MarshalTo(dAtA []byte) (int, error)

func (*RandomNumberRequest) ProtoMessage

func (*RandomNumberRequest) ProtoMessage()

func (*RandomNumberRequest) ProtoSize

func (m *RandomNumberRequest) ProtoSize() (n int)

func (*RandomNumberRequest) Reset

func (m *RandomNumberRequest) Reset()

func (*RandomNumberRequest) String

func (m *RandomNumberRequest) String() string

func (*RandomNumberRequest) Unmarshal

func (m *RandomNumberRequest) Unmarshal(dAtA []byte) error

type RandomNumberResponse

type RandomNumberResponse struct {
	Result1 float64 `protobuf:"fixed64,1,opt,name=result1,proto3" json:"result1,omitempty"`
}

func (*RandomNumberResponse) Descriptor

func (*RandomNumberResponse) Descriptor() ([]byte, []int)

func (*RandomNumberResponse) GetResult1

func (m *RandomNumberResponse) GetResult1() float64

func (*RandomNumberResponse) Marshal

func (m *RandomNumberResponse) Marshal() (dAtA []byte, err error)

func (*RandomNumberResponse) MarshalTo

func (m *RandomNumberResponse) MarshalTo(dAtA []byte) (int, error)

func (*RandomNumberResponse) ProtoMessage

func (*RandomNumberResponse) ProtoMessage()

func (*RandomNumberResponse) ProtoSize

func (m *RandomNumberResponse) ProtoSize() (n int)

func (*RandomNumberResponse) Reset

func (m *RandomNumberResponse) Reset()

func (*RandomNumberResponse) String

func (m *RandomNumberResponse) String() string

func (*RandomNumberResponse) Unmarshal

func (m *RandomNumberResponse) Unmarshal(dAtA []byte) error

type Tags

type Tags []string

type Type

type Type byte

Type will be transformed into an enum.

const (
	Public Type = iota
	Private
	Custom
)

func (Type) EnumDescriptor

func (Type) EnumDescriptor() ([]byte, []int)

func (Type) String

func (t Type) String() string

type User

type User struct {
	Model

	Username string
	Password string
	Email    string
}

User will not be generated.

Directories

Path Synopsis
Package categories is a generated protocol buffer package.
Package categories is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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