Documentation ¶
Overview ¶
Package pbgo provides mini rpc/rest framework based on Protobuf.
Index ¶
- Variables
- func BindBody(r *http.Request, req proto.Message) error
- func BindForm(r *http.Request, req proto.Message) error
- func BindNamedParams(r *http.Request, req proto.Message, params interface{ ... }, name ...string) error
- func BindQuery(r *http.Request, req proto.Message) error
- func Bool(val string) (bool, error)
- func BuildUrlValues(msg interface{}) (m url.Values, err error)
- func Bytes(val string) ([]byte, error)
- func Duration(val string) (*duration.Duration, error)
- func Float32(val string) (float32, error)
- func Float64(val string) (float64, error)
- func HttpDo(method, urlpath string, input, output interface{}) error
- func HttpGet(urlpath string, input, output interface{}) error
- func HttpPost(urlpath string, input, output interface{}) error
- func Int32(val string) (int32, error)
- func Int64(val string) (int64, error)
- func JSON(w http.ResponseWriter, code int, obj interface{})
- func NewHttpRequest(method, urlpath string, input interface{}) (*http.Request, error)
- func PopulateFieldFromPath(msg proto.Message, fieldPathString string, value string) error
- func PopulateQueryParameters(msg proto.Message, values url.Values) error
- func PopulateQueryParametersEx(msg proto.Message, values url.Values, ignoreUnknownParam bool) error
- func String(val string) (string, error)
- func Timestamp(val string) (*timestamp.Timestamp, error)
- func Uint32(val string) (uint32, error)
- func Uint64(val string) (uint64, error)
- type CustomHttpRule
- func (*CustomHttpRule) Descriptor() ([]byte, []int)
- func (m *CustomHttpRule) GetContentBody() string
- func (m *CustomHttpRule) GetContentType() string
- func (m *CustomHttpRule) GetCustomHeader() string
- func (m *CustomHttpRule) GetMethod() string
- func (m *CustomHttpRule) GetRequestBody() string
- func (m *CustomHttpRule) GetUrl() string
- func (*CustomHttpRule) ProtoMessage()
- func (m *CustomHttpRule) Reset()
- func (m *CustomHttpRule) String() string
- func (m *CustomHttpRule) XXX_DiscardUnknown()
- func (m *CustomHttpRule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CustomHttpRule) XXX_Merge(src proto.Message)
- func (m *CustomHttpRule) XXX_Size() int
- func (m *CustomHttpRule) XXX_Unmarshal(b []byte) error
- type Error
- type HttpRule
- func (*HttpRule) Descriptor() ([]byte, []int)
- func (m *HttpRule) GetAdditionalBindings() []*CustomHttpRule
- func (m *HttpRule) GetDelete() string
- func (m *HttpRule) GetGet() string
- func (m *HttpRule) GetPatch() string
- func (m *HttpRule) GetPost() string
- func (m *HttpRule) GetPut() string
- func (*HttpRule) ProtoMessage()
- func (m *HttpRule) Reset()
- func (m *HttpRule) String() string
- func (m *HttpRule) XXX_DiscardUnknown()
- func (m *HttpRule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *HttpRule) XXX_Merge(src proto.Message)
- func (m *HttpRule) XXX_Size() int
- func (m *HttpRule) XXX_Unmarshal(b []byte) error
- type ServiceOptions
- func (*ServiceOptions) Descriptor() ([]byte, []int)
- func (m *ServiceOptions) GetRename() string
- func (*ServiceOptions) ProtoMessage()
- func (m *ServiceOptions) Reset()
- func (m *ServiceOptions) String() string
- func (m *ServiceOptions) XXX_DiscardUnknown()
- func (m *ServiceOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ServiceOptions) XXX_Merge(src proto.Message)
- func (m *ServiceOptions) XXX_Size() int
- func (m *ServiceOptions) XXX_Unmarshal(b []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var E_RestApi = &proto.ExtensionDesc{ ExtendedType: (*descriptor.MethodOptions)(nil), ExtensionType: (*HttpRule)(nil), Field: 20180715, Name: "pbgo.rest_api", Tag: "bytes,20180715,opt,name=rest_api", Filename: "pbgo.proto", }
View Source
var E_ServiceOpt = &proto.ExtensionDesc{ ExtendedType: (*descriptor.ServiceOptions)(nil), ExtensionType: (*ServiceOptions)(nil), Field: 20180715, Name: "pbgo.service_opt", Tag: "bytes,20180715,opt,name=service_opt", Filename: "pbgo.proto", }
View Source
var ProtoFiles = map[string]string{
"pbgo.proto": `// Copyright 2018 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a Apache
// license that can be found in the LICENSE file.
syntax = "proto3";
package pbgo;
option go_package = "github.com/chai2010/pbgo;pbgo";
import "google/protobuf/descriptor.proto";
extend google.protobuf.ServiceOptions {
ServiceOptions service_opt = 20180715;
}
extend google.protobuf.MethodOptions {
HttpRule rest_api = 20180715;
}
message ServiceOptions {
string rename = 1;
}
message HttpRule {
string get = 1;
string put = 2;
string post = 3;
string delete = 4;
string patch = 5;
repeated CustomHttpRule additional_bindings = 6;
}
message CustomHttpRule {
string method = 1;
string url = 2;
string content_type = 3; // must be 'string' type
string content_body = 4; // must be 'bytes' type
string custom_header = 5; // must be 'map<string,string>' type
string request_body = 6; // must be 'bytes' type
}
`,
}
Functions ¶
func BindNamedParams ¶ added in v1.3.0
func BuildUrlValues ¶ added in v1.3.0
Example ¶
var msg = &hello_pb.Message{ Value: "chai2010", Array: []int32{1, 2, 3}, Dict: map[string]string{ "aaa": "111", "bbb": "222", }, Subfiled: &hello_pb.String{ Value: "value", }, } x, err := pbgo.BuildUrlValues(msg) if err != nil { panic(err) } fmt.Println(x.Encode())
Output: array=1&array=2&array=3&dict.aaa=111&dict.bbb=222&subfiled.value=value&value=chai2010
func Bytes ¶
Bytes converts the given string representation of a byte sequence into a slice of bytes A bytes sequence is encoded in URL-safe base64 without padding
func Float32 ¶
Float32 converts the given string representation of a floating point number into float32.
func Float64 ¶
Float64 converts the given string representation into representation of a floating point number into float64.
func JSON ¶ added in v1.3.0
func JSON(w http.ResponseWriter, code int, obj interface{})
func NewHttpRequest ¶ added in v1.4.0
func PopulateFieldFromPath ¶
PopulateFieldFromPath sets a value in a nested Protobuf structure. It instantiates missing protobuf fields as it goes.
func PopulateQueryParameters ¶
PopulateQueryParameters populates "values" into "msg".
func PopulateQueryParametersEx ¶ added in v1.3.0
PopulateQueryParametersEx populates "values" into "msg".
Types ¶
type CustomHttpRule ¶
type CustomHttpRule struct { Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` ContentType string `protobuf:"bytes,3,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"` ContentBody string `protobuf:"bytes,4,opt,name=content_body,json=contentBody,proto3" json:"content_body,omitempty"` CustomHeader string `protobuf:"bytes,5,opt,name=custom_header,json=customHeader,proto3" json:"custom_header,omitempty"` RequestBody string `protobuf:"bytes,6,opt,name=request_body,json=requestBody,proto3" json:"request_body,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*CustomHttpRule) Descriptor ¶
func (*CustomHttpRule) Descriptor() ([]byte, []int)
func (*CustomHttpRule) GetContentBody ¶
func (m *CustomHttpRule) GetContentBody() string
func (*CustomHttpRule) GetContentType ¶
func (m *CustomHttpRule) GetContentType() string
func (*CustomHttpRule) GetCustomHeader ¶
func (m *CustomHttpRule) GetCustomHeader() string
func (*CustomHttpRule) GetMethod ¶
func (m *CustomHttpRule) GetMethod() string
func (*CustomHttpRule) GetRequestBody ¶
func (m *CustomHttpRule) GetRequestBody() string
func (*CustomHttpRule) GetUrl ¶
func (m *CustomHttpRule) GetUrl() string
func (*CustomHttpRule) ProtoMessage ¶
func (*CustomHttpRule) ProtoMessage()
func (*CustomHttpRule) Reset ¶
func (m *CustomHttpRule) Reset()
func (*CustomHttpRule) String ¶
func (m *CustomHttpRule) String() string
func (*CustomHttpRule) XXX_DiscardUnknown ¶
func (m *CustomHttpRule) XXX_DiscardUnknown()
func (*CustomHttpRule) XXX_Marshal ¶
func (m *CustomHttpRule) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*CustomHttpRule) XXX_Merge ¶
func (m *CustomHttpRule) XXX_Merge(src proto.Message)
func (*CustomHttpRule) XXX_Size ¶
func (m *CustomHttpRule) XXX_Size() int
func (*CustomHttpRule) XXX_Unmarshal ¶
func (m *CustomHttpRule) XXX_Unmarshal(b []byte) error
type Error ¶
type HttpRule ¶
type HttpRule struct { Get string `protobuf:"bytes,1,opt,name=get,proto3" json:"get,omitempty"` Put string `protobuf:"bytes,2,opt,name=put,proto3" json:"put,omitempty"` Post string `protobuf:"bytes,3,opt,name=post,proto3" json:"post,omitempty"` Delete string `protobuf:"bytes,4,opt,name=delete,proto3" json:"delete,omitempty"` Patch string `protobuf:"bytes,5,opt,name=patch,proto3" json:"patch,omitempty"` AdditionalBindings []*CustomHttpRule `protobuf:"bytes,6,rep,name=additional_bindings,json=additionalBindings,proto3" json:"additional_bindings,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*HttpRule) Descriptor ¶
func (*HttpRule) GetAdditionalBindings ¶
func (m *HttpRule) GetAdditionalBindings() []*CustomHttpRule
func (*HttpRule) ProtoMessage ¶
func (*HttpRule) ProtoMessage()
func (*HttpRule) XXX_DiscardUnknown ¶
func (m *HttpRule) XXX_DiscardUnknown()
func (*HttpRule) XXX_Marshal ¶
func (*HttpRule) XXX_Unmarshal ¶
type ServiceOptions ¶ added in v1.2.0
type ServiceOptions struct { Rename string `protobuf:"bytes,1,opt,name=rename,proto3" json:"rename,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*ServiceOptions) Descriptor ¶ added in v1.2.0
func (*ServiceOptions) Descriptor() ([]byte, []int)
func (*ServiceOptions) GetRename ¶ added in v1.2.0
func (m *ServiceOptions) GetRename() string
func (*ServiceOptions) ProtoMessage ¶ added in v1.2.0
func (*ServiceOptions) ProtoMessage()
func (*ServiceOptions) Reset ¶ added in v1.2.0
func (m *ServiceOptions) Reset()
func (*ServiceOptions) String ¶ added in v1.2.0
func (m *ServiceOptions) String() string
func (*ServiceOptions) XXX_DiscardUnknown ¶ added in v1.2.0
func (m *ServiceOptions) XXX_DiscardUnknown()
func (*ServiceOptions) XXX_Marshal ¶ added in v1.2.0
func (m *ServiceOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ServiceOptions) XXX_Merge ¶ added in v1.2.0
func (m *ServiceOptions) XXX_Merge(src proto.Message)
func (*ServiceOptions) XXX_Size ¶ added in v1.2.0
func (m *ServiceOptions) XXX_Size() int
func (*ServiceOptions) XXX_Unmarshal ¶ added in v1.2.0
func (m *ServiceOptions) XXX_Unmarshal(b []byte) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
protoc-gen-pbgo is a plugin for the Protobuf compiler to generate rpc/rest code.
|
protoc-gen-pbgo is a plugin for the Protobuf compiler to generate rpc/rest code. |
main
protoc-gen-pbgo is a plugin for the Protobuf compiler to generate rpc/rest code.
|
protoc-gen-pbgo is a plugin for the Protobuf compiler to generate rpc/rest code. |
pbgo
Package pbgo outputs pbgo service descriptions in Go code.
|
Package pbgo outputs pbgo service descriptions in Go code. |
Click to show internal directories.
Click to hide internal directories.