Documentation
¶
Index ¶
- Variables
- func BuildPredeclaredProtoFiles(fds ...protoreflect.FileDescriptor) (*protoregistry.Files, error)
- func ConstPayload(m proto.Message) func() []byte
- func DefaultSlice[V any](v *[]V, defaultValue []V)
- func DefaultVal[V comparable](v *V, defaultValue V)
- func DefaultValPtr[V any](v **V, defaultValue V)
- func Duration(d **durationpb.Duration, defaultValue time.Duration)
- func HeaderKVToHTTPHeader(from []*HeaderKV) http.Header
- func MarshalAny(m Marshaler, msg proto.Message) ([]byte, error)
- func NewAny(m Marshaler, msg proto.Message) (*anypb.Any, error)
- func NotNil[T any](field **T)
- func ParseYAMLToProto[M Message[T], T any](rawYAML []byte) (M, error)
- func QueryKVToURLValues(from []*QueryKV) url.Values
- func ShallowClone[M Message[T], T any](msg M) M
- func UnmarshalAny(m Marshaler, data []byte) (proto.Message, error)
- func UnmarshalAnyNew(m Marshaler, a *anypb.Any) (proto.Message, error)
- func UnmarshalAnyTo(m Marshaler, a *anypb.Any, dst proto.Message) error
- func UnmarshalProto(opts proto.UnmarshalOptions, data mem.BufferSlice, v any) error
- func UnmarshalTyped[O Message[T], T any](m Marshaler, data []byte) (O, error)
- type HeaderKV
- type HeaderValues
- type HttpRequest
- func (*HttpRequest) Descriptor() ([]byte, []int)deprecated
- func (x *HttpRequest) GetHeader() []*HeaderKV
- func (x *HttpRequest) GetMethod() string
- func (x *HttpRequest) GetQuery() []*QueryKV
- func (x *HttpRequest) GetUrlPath() string
- func (x *HttpRequest) HTTPHeader() http.Header
- func (x *HttpRequest) IsUpgrade() bool
- func (*HttpRequest) ProtoMessage()
- func (x *HttpRequest) ProtoReflect() protoreflect.Message
- func (x *HttpRequest) Reset()
- func (x *HttpRequest) String() string
- func (x *HttpRequest) URLQuery() url.Values
- type HttpResponse
- func (*HttpResponse) Descriptor() ([]byte, []int)deprecated
- func (x *HttpResponse) GetHeader() []*HeaderKV
- func (x *HttpResponse) GetStatus() string
- func (x *HttpResponse) GetStatusCode() int32
- func (x *HttpResponse) HTTPHeader() http.Header
- func (*HttpResponse) ProtoMessage()
- func (x *HttpResponse) ProtoReflect() protoreflect.Message
- func (x *HttpResponse) Reset()
- func (x *HttpResponse) String() string
- type Marshaler
- type Message
- type MessageNameValidator
- type NopValidator
- type ProtoErrMarshaler
- type ProtoJSONMarshaler
- type ProtoMarshaler
- type QueryKV
- type QueryValues
- type ValidatingMarshaler
- func (v *ValidatingMarshaler) Marshal(m proto.Message) ([]byte, error)
- func (v *ValidatingMarshaler) MarshalOptions() proto.MarshalOptions
- func (v *ValidatingMarshaler) MarshalOpts(m proto.Message, o proto.MarshalOptions) ([]byte, error)
- func (v *ValidatingMarshaler) MarshalProtoJSON(m proto.Message) ([]byte, error)
- func (v *ValidatingMarshaler) MarshalProtoJSONOpts(m proto.Message, o protojson.MarshalOptions) ([]byte, error)
- func (v *ValidatingMarshaler) Unmarshal(b []byte, m proto.Message) error
- func (v *ValidatingMarshaler) UnmarshalOptions() proto.UnmarshalOptions
- func (v *ValidatingMarshaler) UnmarshalOpts(b []byte, m proto.Message, o proto.UnmarshalOptions) error
- func (v *ValidatingMarshaler) UnmarshalProtoJSON(b []byte, m proto.Message) error
- func (v *ValidatingMarshaler) UnmarshalProtoJSONOpts(b []byte, m proto.Message, o protojson.UnmarshalOptions) error
Constants ¶
This section is empty.
Variables ¶
var File_internal_tool_prototool_prototool_proto protoreflect.FileDescriptor
Functions ¶
func BuildPredeclaredProtoFiles ¶ added in v19.1.0
func BuildPredeclaredProtoFiles(fds ...protoreflect.FileDescriptor) (*protoregistry.Files, error)
func ConstPayload ¶ added in v19.4.0
ConstPayload marshals a message whose contents are fixed, producing the bytes once on first use rather than on every call. Deferring the marshal is what makes the result safe to hold in a package-level variable of the package that generated m's type: those types register themselves in an init function, which runs after that package's variables are initialized. A marshal failure is a build-time mistake rather than a runtime condition, so it panics.
The returned bytes are shared by every caller and must not be modified.
func DefaultSlice ¶
func DefaultSlice[V any](v *[]V, defaultValue []V)
func DefaultVal ¶
func DefaultVal[V comparable](v *V, defaultValue V)
func DefaultValPtr ¶
func DefaultValPtr[V any](v **V, defaultValue V)
func HeaderKVToHTTPHeader ¶
HeaderKVToHTTPHeader converts the internal []*HeaderKV type to http.Header. The returned http.Header has canonicalized keys.
func MarshalAny ¶ added in v19.5.0
MarshalAny marshals msg packed into an Any, so that UnmarshalAny can instantiate a message of the same type. msg is packed with NewAny. The Any itself is not validated, only marshaled with m's options.
func NewAny ¶ added in v19.5.0
NewAny packs msg into an Any, validating it through m and marshaling it with m's options. protovalidate does not look inside an Any, so this is what validates the packed message.
func QueryKVToURLValues ¶
func ShallowClone ¶ added in v19.6.0
ShallowClone returns a copy of msg whose message, list and map fields, and unknown fields, are those of msg rather than copies, so neither may be modified in place while the other is in use. Setting a field of either leaves the other as it was. An invalid msg, such as a nil one, yields nil.
It copies through reflection: copying the struct would copy its internal state, and naming the fields would drop any the message gains.
func UnmarshalAny ¶ added in v19.5.0
UnmarshalAny reverses MarshalAny. The Any itself is not validated, only unmarshaled with m's options. The message it holds is unpacked with UnmarshalAnyNew.
func UnmarshalAnyNew ¶ added in v19.5.0
UnmarshalAnyNew unpacks the message a holds into a new message of the type a names, unmarshaling it with m's options and validating it through m.
func UnmarshalAnyTo ¶ added in v19.5.0
UnmarshalAnyTo unpacks the message a holds into dst, unmarshaling it with m's options and validating it through m. It fails if a holds a message of a type other than that of dst.
func UnmarshalProto ¶
func UnmarshalProto(opts proto.UnmarshalOptions, data mem.BufferSlice, v any) error
Types ¶
type HeaderKV ¶
type HeaderKV struct {
Key []byte `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
Value *HeaderValues `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
// contains filtered or unexported fields
}
func HTTPHeaderToHeaderKV ¶
func (*HeaderKV) Descriptor
deprecated
func (*HeaderKV) GetValue ¶
func (x *HeaderKV) GetValue() *HeaderValues
func (*HeaderKV) ProtoMessage ¶
func (*HeaderKV) ProtoMessage()
func (*HeaderKV) ProtoReflect ¶
func (x *HeaderKV) ProtoReflect() protoreflect.Message
type HeaderValues ¶
type HeaderValues struct {
Value [][]byte `protobuf:"bytes,1,rep,name=value" json:"value,omitempty"`
// contains filtered or unexported fields
}
func (*HeaderValues) Descriptor
deprecated
func (*HeaderValues) Descriptor() ([]byte, []int)
Deprecated: Use HeaderValues.ProtoReflect.Descriptor instead.
func (*HeaderValues) GetValue ¶
func (x *HeaderValues) GetValue() [][]byte
func (*HeaderValues) ProtoMessage ¶
func (*HeaderValues) ProtoMessage()
func (*HeaderValues) ProtoReflect ¶
func (x *HeaderValues) ProtoReflect() protoreflect.Message
func (*HeaderValues) Reset ¶
func (x *HeaderValues) Reset()
func (*HeaderValues) String ¶
func (x *HeaderValues) String() string
type HttpRequest ¶
type HttpRequest struct {
Method string `protobuf:"bytes,1,opt,name=method" json:"method,omitempty"`
Header []*HeaderKV `protobuf:"bytes,2,rep,name=header" json:"header,omitempty"`
UrlPath string `protobuf:"bytes,3,opt,name=url_path,json=urlPath" json:"url_path,omitempty"`
Query []*QueryKV `protobuf:"bytes,4,rep,name=query" json:"query,omitempty"`
// contains filtered or unexported fields
}
func (*HttpRequest) Descriptor
deprecated
func (*HttpRequest) Descriptor() ([]byte, []int)
Deprecated: Use HttpRequest.ProtoReflect.Descriptor instead.
func (*HttpRequest) GetHeader ¶
func (x *HttpRequest) GetHeader() []*HeaderKV
func (*HttpRequest) GetMethod ¶
func (x *HttpRequest) GetMethod() string
func (*HttpRequest) GetQuery ¶
func (x *HttpRequest) GetQuery() []*QueryKV
func (*HttpRequest) GetUrlPath ¶
func (x *HttpRequest) GetUrlPath() string
func (*HttpRequest) HTTPHeader ¶
func (x *HttpRequest) HTTPHeader() http.Header
func (*HttpRequest) IsUpgrade ¶
func (x *HttpRequest) IsUpgrade() bool
func (*HttpRequest) ProtoMessage ¶
func (*HttpRequest) ProtoMessage()
func (*HttpRequest) ProtoReflect ¶
func (x *HttpRequest) ProtoReflect() protoreflect.Message
func (*HttpRequest) Reset ¶
func (x *HttpRequest) Reset()
func (*HttpRequest) String ¶
func (x *HttpRequest) String() string
func (*HttpRequest) URLQuery ¶
func (x *HttpRequest) URLQuery() url.Values
type HttpResponse ¶
type HttpResponse struct {
StatusCode int32 `protobuf:"varint,1,opt,name=status_code,json=statusCode" json:"status_code,omitempty"`
Status string `protobuf:"bytes,2,opt,name=status" json:"status,omitempty"`
Header []*HeaderKV `protobuf:"bytes,3,rep,name=header" json:"header,omitempty"`
// contains filtered or unexported fields
}
func (*HttpResponse) Descriptor
deprecated
func (*HttpResponse) Descriptor() ([]byte, []int)
Deprecated: Use HttpResponse.ProtoReflect.Descriptor instead.
func (*HttpResponse) GetHeader ¶
func (x *HttpResponse) GetHeader() []*HeaderKV
func (*HttpResponse) GetStatus ¶
func (x *HttpResponse) GetStatus() string
func (*HttpResponse) GetStatusCode ¶
func (x *HttpResponse) GetStatusCode() int32
func (*HttpResponse) HTTPHeader ¶
func (x *HttpResponse) HTTPHeader() http.Header
func (*HttpResponse) ProtoMessage ¶
func (*HttpResponse) ProtoMessage()
func (*HttpResponse) ProtoReflect ¶
func (x *HttpResponse) ProtoReflect() protoreflect.Message
func (*HttpResponse) Reset ¶
func (x *HttpResponse) Reset()
func (*HttpResponse) String ¶
func (x *HttpResponse) String() string
type Marshaler ¶ added in v19.5.0
type Marshaler interface {
protovalidate.Validator
ProtoMarshaler
ProtoJSONMarshaler
}
Marshaler can marshal, unmarshal, and validate protobuf messages, in the binary and in the protojson wire format.
var NonValidatingMarshaler Marshaler = &ValidatingMarshaler{Validator: NopValidator{}}
NonValidatingMarshaler marshals and unmarshals with the default options and validates nothing. It is for messages that are validated at a later point, or that have no one to validate them.
type Message ¶ added in v19.6.0
Message constrains a type parameter to *T for a proto message T, so generic code can allocate a message with new(T) rather than through protoreflect. Declare the constrained parameter before T: T is then inferred from it, so a caller passes one type argument, f[*pb.Msg](), even from generic code that holds only the pointer type. With T first, generic code has to pass both.
type MessageNameValidator ¶ added in v19.6.0
type MessageNameValidator struct {
Delegate protovalidate.Validator
}
MessageNameValidator validates with Delegate and prefixes the errors with the full name of the message.
func (MessageNameValidator) Validate ¶ added in v19.6.0
func (v MessageNameValidator) Validate(m proto.Message, opts ...protovalidate.ValidationOption) error
type NopValidator ¶
type NopValidator struct{}
func (NopValidator) Validate ¶
func (NopValidator) Validate(proto.Message, ...protovalidate.ValidationOption) error
type ProtoErrMarshaler ¶
type ProtoErrMarshaler struct {
Marshaler Marshaler
}
ProtoErrMarshaler marshals errors that are protobuf messages. The error is packed into an Any so that Unmarshal can restore its type.
type ProtoJSONMarshaler ¶ added in v19.6.0
type ProtoJSONMarshaler interface {
MarshalProtoJSON(proto.Message) ([]byte, error)
MarshalProtoJSONOpts(proto.Message, protojson.MarshalOptions) ([]byte, error)
UnmarshalProtoJSON([]byte, proto.Message) error
UnmarshalProtoJSONOpts([]byte, proto.Message, protojson.UnmarshalOptions) error
}
ProtoJSONMarshaler can marshal and unmarshal protobuf messages in the protojson wire format.
type ProtoMarshaler ¶ added in v19.6.0
type ProtoMarshaler interface {
Marshal(proto.Message) ([]byte, error)
MarshalOpts(proto.Message, proto.MarshalOptions) ([]byte, error)
Unmarshal([]byte, proto.Message) error
UnmarshalOpts([]byte, proto.Message, proto.UnmarshalOptions) error
// MarshalOptions returns the options Marshal uses.
MarshalOptions() proto.MarshalOptions
// UnmarshalOptions returns the options Unmarshal uses.
UnmarshalOptions() proto.UnmarshalOptions
}
ProtoMarshaler can marshal and unmarshal protobuf messages, in the binary wire format.
type QueryKV ¶
type QueryKV struct {
Key []byte `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
Value *QueryValues `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
// contains filtered or unexported fields
}
func URLValuesToQueryKV ¶
func (*QueryKV) Descriptor
deprecated
func (*QueryKV) GetValue ¶
func (x *QueryKV) GetValue() *QueryValues
func (*QueryKV) ProtoMessage ¶
func (*QueryKV) ProtoMessage()
func (*QueryKV) ProtoReflect ¶
func (x *QueryKV) ProtoReflect() protoreflect.Message
type QueryValues ¶
type QueryValues struct {
Value [][]byte `protobuf:"bytes,1,rep,name=value" json:"value,omitempty"`
// contains filtered or unexported fields
}
func (*QueryValues) Descriptor
deprecated
func (*QueryValues) Descriptor() ([]byte, []int)
Deprecated: Use QueryValues.ProtoReflect.Descriptor instead.
func (*QueryValues) GetValue ¶
func (x *QueryValues) GetValue() [][]byte
func (*QueryValues) ProtoMessage ¶
func (*QueryValues) ProtoMessage()
func (*QueryValues) ProtoReflect ¶
func (x *QueryValues) ProtoReflect() protoreflect.Message
func (*QueryValues) Reset ¶
func (x *QueryValues) Reset()
func (*QueryValues) String ¶
func (x *QueryValues) String() string
type ValidatingMarshaler ¶ added in v19.5.0
type ValidatingMarshaler struct {
protovalidate.Validator
DefaultMarshalOpts proto.MarshalOptions
DefaultUnmarshalOpts proto.UnmarshalOptions
DefaultJSONMarshalOpts protojson.MarshalOptions
DefaultJSONUnmarshalOpts protojson.UnmarshalOptions
}
ValidatingMarshaler validates a message before marshaling it and after unmarshaling it. Marshal and Unmarshal use the default options, MarshalOpts and UnmarshalOpts use the supplied ones. The ProtoJSON methods do the same with the JSON options.
func (*ValidatingMarshaler) Marshal ¶ added in v19.5.0
func (v *ValidatingMarshaler) Marshal(m proto.Message) ([]byte, error)
func (*ValidatingMarshaler) MarshalOptions ¶ added in v19.5.0
func (v *ValidatingMarshaler) MarshalOptions() proto.MarshalOptions
func (*ValidatingMarshaler) MarshalOpts ¶ added in v19.5.0
func (v *ValidatingMarshaler) MarshalOpts(m proto.Message, o proto.MarshalOptions) ([]byte, error)
func (*ValidatingMarshaler) MarshalProtoJSON ¶ added in v19.6.0
func (v *ValidatingMarshaler) MarshalProtoJSON(m proto.Message) ([]byte, error)
func (*ValidatingMarshaler) MarshalProtoJSONOpts ¶ added in v19.6.0
func (v *ValidatingMarshaler) MarshalProtoJSONOpts(m proto.Message, o protojson.MarshalOptions) ([]byte, error)
func (*ValidatingMarshaler) Unmarshal ¶ added in v19.5.0
func (v *ValidatingMarshaler) Unmarshal(b []byte, m proto.Message) error
func (*ValidatingMarshaler) UnmarshalOptions ¶ added in v19.5.0
func (v *ValidatingMarshaler) UnmarshalOptions() proto.UnmarshalOptions
func (*ValidatingMarshaler) UnmarshalOpts ¶ added in v19.5.0
func (v *ValidatingMarshaler) UnmarshalOpts(b []byte, m proto.Message, o proto.UnmarshalOptions) error
func (*ValidatingMarshaler) UnmarshalProtoJSON ¶ added in v19.6.0
func (v *ValidatingMarshaler) UnmarshalProtoJSON(b []byte, m proto.Message) error
func (*ValidatingMarshaler) UnmarshalProtoJSONOpts ¶ added in v19.6.0
func (v *ValidatingMarshaler) UnmarshalProtoJSONOpts(b []byte, m proto.Message, o protojson.UnmarshalOptions) error