protos

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Tag_name = map[int32]string{
		0: "GO",
		1: "RUST",
		2: "PHP",
		3: "JAVA",
	}
	Tag_value = map[string]int32{
		"GO":   0,
		"RUST": 1,
		"PHP":  2,
		"JAVA": 3,
	}
)

Enum value maps for Tag.

Functions

func Bytes

func Bytes(s string) ([]byte, error)

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 MessageToValues

func MessageToValues(msg proto.Message) url.Values

MessageToValues parses proto.Message into url.Values

func Validate

func Validate(msg proto.Message, opts ...protovalidate.ValidatorOption) error

Validate 验证消息体

func ValuesToMessage

func ValuesToMessage(msg proto.Message, values url.Values) error

ValuesToMessage parses url.Values into proto.Message

Types

type ApiResult

type ApiResult[T proto.Message] struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

ApiResult is the API response with proto.Message

type ClientOption

type ClientOption func(c *resty.Client)

ClientOption option for resty.Client

func WithRetryAfter

func WithRetryAfter(fn resty.RetryAfterFunc) ClientOption

WithRetryAfter sets a callback to calculate the wait time between retries. Default (nil) implies exponential backoff with jitter

func WithRetryCount

func WithRetryCount(n int) ClientOption

WithRetryCount enables retry on Resty client and allows you to set no. of retry count. Resty uses a Backoff mechanism.

func WithRetryMaxWaitTime

func WithRetryMaxWaitTime(d time.Duration) ClientOption

WithRetryMaxWaitTime sets the max wait time for sleep before retrying request.

Default is 2 seconds.

func WithRetryWaitTime

func WithRetryWaitTime(d time.Duration) ClientOption

WithRetryWaitTime sets the default wait time for sleep before retrying request.

Default is 100 milliseconds.

type DemoRequest

type DemoRequest struct {
	User    *User   `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
	Friends []*User `protobuf:"bytes,2,rep,name=friends,proto3" json:"friends,omitempty"`
	// contains filtered or unexported fields
}

func (*DemoRequest) Descriptor deprecated

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

Deprecated: Use DemoRequest.ProtoReflect.Descriptor instead.

func (*DemoRequest) GetFriends

func (x *DemoRequest) GetFriends() []*User

func (*DemoRequest) GetUser

func (x *DemoRequest) GetUser() *User

func (*DemoRequest) ProtoMessage

func (*DemoRequest) ProtoMessage()

func (*DemoRequest) ProtoReflect

func (x *DemoRequest) ProtoReflect() protoreflect.Message

func (*DemoRequest) Reset

func (x *DemoRequest) Reset()

func (*DemoRequest) String

func (x *DemoRequest) String() string

type DemoResponse

type DemoResponse struct {
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (*DemoResponse) Descriptor deprecated

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

Deprecated: Use DemoResponse.ProtoReflect.Descriptor instead.

func (*DemoResponse) GetMessage

func (x *DemoResponse) GetMessage() string

func (*DemoResponse) ProtoMessage

func (*DemoResponse) ProtoMessage()

func (*DemoResponse) ProtoReflect

func (x *DemoResponse) ProtoReflect() protoreflect.Message

func (*DemoResponse) Reset

func (x *DemoResponse) Reset()

func (*DemoResponse) String

func (x *DemoResponse) String() string

type RequestOption

type RequestOption func(req *resty.Request)

RequestOption option for resty.Request

func WithReqDebug

func WithReqDebug(b bool) RequestOption

WithReqDebug enables the debug mode on the current request. It logs the details current request and response.

WithReqDebug(true)

Also, it can be enabled at the request level for a particular request; see [Request.SetDebug].

  • For [Request], it logs information such as HTTP verb, Relative URL path, Host, Headers, and Body if it has one.
  • For [Response], it logs information such as Status, Response Time, Headers, and Body if it has one.

func WithReqHeader

func WithReqHeader(h http.Header) RequestOption

WithReqHeader sets multiple header fields and their values as a list of strings in the current request.

For Example: To set `Accept` as `text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8`

WithReqHeader(http.Header{
	"Accept": []string{"text/html", "application/xhtml+xml", "application/xml;q=0.9", "image/webp", "*/*;q=0.8"},
})

It overrides the header value set at the client instance level.

func WithReqQuery

func WithReqQuery(v url.Values) RequestOption

WithReqQuery appends multiple parameters with multi-value (url.Values) at one go in the current request. It will be formed as query string for the request.

For Example: `status=pending&status=approved&status=open` in the URL after the `?` mark.

WithReqQuery(url.Values{
	"status": []string{"pending", "approved", "open"},
})

It overrides the query parameter value set at the client instance level.

func WithReqRetryCondition

func WithReqRetryCondition(fn resty.RetryConditionFunc) RequestOption

WithReqRetryCondition adds a retry condition function to the request's array of functions is checked to determine if the request can be retried. The request will retry if any functions return true and the error is nil.

NOTE: The request level retry conditions are checked before all retry conditions from the client instance.

type Tag

type Tag int32
const (
	Tag_GO   Tag = 0
	Tag_RUST Tag = 1
	Tag_PHP  Tag = 2
	Tag_JAVA Tag = 3
)

func (Tag) Descriptor

func (Tag) Descriptor() protoreflect.EnumDescriptor

func (Tag) Enum

func (x Tag) Enum() *Tag

func (Tag) EnumDescriptor deprecated

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

Deprecated: Use Tag.Descriptor instead.

func (Tag) Number

func (x Tag) Number() protoreflect.EnumNumber

func (Tag) String

func (x Tag) String() string

func (Tag) Type

func (Tag) Type() protoreflect.EnumType

type User

type User struct {
	Name  string            `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Tags  []Tag             `protobuf:"varint,3,rep,packed,name=tags,proto3,enum=protos.Tag" json:"tags,omitempty"`
	Attrs map[string]string `` /* 137-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*User) Descriptor deprecated

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

Deprecated: Use User.ProtoReflect.Descriptor instead.

func (*User) GetAttrs

func (x *User) GetAttrs() map[string]string

func (*User) GetName

func (x *User) GetName() string

func (*User) GetTags

func (x *User) GetTags() []Tag

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) ProtoReflect

func (x *User) ProtoReflect() protoreflect.Message

func (*User) Reset

func (x *User) Reset()

func (*User) String

func (x *User) String() string

Jump to

Keyboard shortcuts

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