common

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package common 提供跨服务复用的 Protobuf 类型及其 Go 辅助方法。

Index

Constants

View Source
const FieldBehavior_FIELD_BEHAVIOR_UNSPECIFIED = annotations.FieldBehavior_FIELD_BEHAVIOR_UNSPECIFIED
View Source
const FieldBehavior_IDENTIFIER = annotations.FieldBehavior_IDENTIFIER
View Source
const FieldBehavior_IMMUTABLE = annotations.FieldBehavior_IMMUTABLE
View Source
const FieldBehavior_INPUT_ONLY = annotations.FieldBehavior_INPUT_ONLY
View Source
const FieldBehavior_NON_EMPTY_DEFAULT = annotations.FieldBehavior_NON_EMPTY_DEFAULT
View Source
const FieldBehavior_OPTIONAL = annotations.FieldBehavior_OPTIONAL
View Source
const FieldBehavior_OUTPUT_ONLY = annotations.FieldBehavior_OUTPUT_ONLY
View Source
const FieldBehavior_REQUIRED = annotations.FieldBehavior_REQUIRED
View Source
const FieldBehavior_UNORDERED_LIST = annotations.FieldBehavior_UNORDERED_LIST
View Source
const NullValue_NULL_VALUE = structpb.NullValue_NULL_VALUE

Variables

View Source
var (
	// NewAny 及 Any 前缀方法提供 google.protobuf.Any 的常用构造和转换能力。
	NewAny          = anypb.New
	AnyMarshalFrom  = anypb.MarshalFrom
	AnyUnmarshalNew = anypb.UnmarshalNew
	AnyUnmarshalTo  = anypb.UnmarshalTo

	// NewDuration 根据 time.Duration 构造 google.protobuf.Duration。
	NewDuration = durationpb.New

	// NewList 和 NewStruct 将普通 Go 数据转换为对应的结构化 Protobuf 值。
	NewList   = structpb.NewList
	NewStruct = structpb.NewStruct

	// NewValue 及其同组方法构造 google.protobuf.Value 及具体值类型。
	NewValue       = structpb.NewValue
	NewBoolValue   = structpb.NewBoolValue
	NewListValue   = structpb.NewListValue
	NewNullValue   = structpb.NewNullValue
	NewNumberValue = structpb.NewNumberValue
	NewStringValue = structpb.NewStringValue
	NewStructValue = structpb.NewStructValue

	// NewTimestamp 根据 time.Time 构造 google.protobuf.Timestamp。
	NewTimestamp = timestamppb.New

	// Bool 至 UInt64 提供 google.protobuf 包装类型的便捷构造方法。
	Bool   = wrapperspb.Bool
	Bytes  = wrapperspb.Bytes
	Double = wrapperspb.Double
	Float  = wrapperspb.Float
	Int32  = wrapperspb.Int32
	Int64  = wrapperspb.Int64
	String = wrapperspb.String
	UInt32 = wrapperspb.UInt32
	UInt64 = wrapperspb.UInt64
)
View Source
var DefaultLimit = 20

DefaultLimit 是未指定有效每页数量时使用的默认值。

View Source
var E_FieldBehavior = annotations.E_FieldBehavior
View Source
var FieldBehavior_name = annotations.FieldBehavior_name
View Source
var FieldBehavior_value = annotations.FieldBehavior_value
View Source
var File_common_common_proto protoreflect.FileDescriptor
View Source
var NullValue_name = structpb.NullValue_name
View Source
var NullValue_value = structpb.NullValue_value

Functions

This section is empty.

Types

type Any

type Any = anypb.Any

type Attribute

type Attribute struct {

	// 名称
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// 数据
	Value *structpb.Value `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

名称和值组成的动态属性

func (*Attribute) Descriptor deprecated

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

Deprecated: Use Attribute.ProtoReflect.Descriptor instead.

func (*Attribute) GetName

func (x *Attribute) GetName() string

func (*Attribute) GetValue

func (x *Attribute) GetValue() *structpb.Value

func (*Attribute) MarshalJSON

func (msg *Attribute) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Attribute) ProtoMessage

func (*Attribute) ProtoMessage()

func (*Attribute) ProtoReflect

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

func (*Attribute) Reset

func (x *Attribute) Reset()

func (*Attribute) String

func (x *Attribute) String() string

func (*Attribute) UnmarshalJSON

func (msg *Attribute) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type BoolValue

type BoolValue = wrapperspb.BoolValue

type BytesValue

type BytesValue = wrapperspb.BytesValue

type DoubleValue

type DoubleValue = wrapperspb.DoubleValue

type Duration

type Duration = durationpb.Duration

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

空消息,用于不需要请求参数或响应数据的 RPC

func (*Empty) Descriptor deprecated

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

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) MarshalJSON

func (msg *Empty) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

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

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

func (*Empty) UnmarshalJSON

func (msg *Empty) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type FieldBehavior

type FieldBehavior = annotations.FieldBehavior

type FieldMask

type FieldMask = fieldmaskpb.FieldMask

type FloatValue

type FloatValue = wrapperspb.FloatValue

type HttpBody

type HttpBody = httpbody.HttpBody

type Id

type Id struct {

	// 资源标识
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// contains filtered or unexported fields
}

单个资源标识

func NewId

func NewId(id string) *Id

NewId 构造单个资源标识。

func (*Id) Descriptor deprecated

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

Deprecated: Use Id.ProtoReflect.Descriptor instead.

func (*Id) GetId

func (x *Id) GetId() string

func (*Id) MarshalJSON

func (msg *Id) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Id) ProtoMessage

func (*Id) ProtoMessage()

func (*Id) ProtoReflect

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

func (*Id) Reset

func (x *Id) Reset()

func (*Id) String

func (x *Id) String() string

func (*Id) UnmarshalJSON

func (msg *Id) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Ids

type Ids struct {

	// 资源标识列表
	Ids []string `protobuf:"bytes,1,rep,name=ids,proto3" json:"ids,omitempty"`
	// contains filtered or unexported fields
}

多个资源标识

func NewIds

func NewIds(ids ...string) *Ids

NewIds 构造一组资源标识。

func (*Ids) Descriptor deprecated

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

Deprecated: Use Ids.ProtoReflect.Descriptor instead.

func (*Ids) GetIds

func (x *Ids) GetIds() []string

func (*Ids) MarshalJSON

func (msg *Ids) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Ids) ProtoMessage

func (*Ids) ProtoMessage()

func (*Ids) ProtoReflect

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

func (*Ids) Reset

func (x *Ids) Reset()

func (*Ids) String

func (x *Ids) String() string

func (*Ids) UnmarshalJSON

func (msg *Ids) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Int32Value

type Int32Value = wrapperspb.Int32Value

type Int64Value

type Int64Value = wrapperspb.Int64Value

type ListValue

type ListValue = structpb.ListValue

type Metadata

type Metadata struct {

	// 创建人
	CreatedBy string `protobuf:"bytes,1,opt,name=created_by,json=createdBy,proto3" json:"created_by,omitempty"`
	// 创建时间
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
	// 更新人
	UpdatedBy string `protobuf:"bytes,3,opt,name=updated_by,json=updatedBy,proto3" json:"updated_by,omitempty"`
	// 更新时间
	UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	// 软删除时间
	DeleteAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=delete_at,json=deleteAt,proto3" json:"delete_at,omitempty"`
	// contains filtered or unexported fields
}

资源的创建、更新和软删除元数据

func (*Metadata) Descriptor deprecated

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

Deprecated: Use Metadata.ProtoReflect.Descriptor instead.

func (*Metadata) GetCreatedAt

func (x *Metadata) GetCreatedAt() *timestamppb.Timestamp

func (*Metadata) GetCreatedBy

func (x *Metadata) GetCreatedBy() string

func (*Metadata) GetDeleteAt

func (x *Metadata) GetDeleteAt() *timestamppb.Timestamp

func (*Metadata) GetUpdatedAt

func (x *Metadata) GetUpdatedAt() *timestamppb.Timestamp

func (*Metadata) GetUpdatedBy

func (x *Metadata) GetUpdatedBy() string

func (*Metadata) MarshalJSON

func (msg *Metadata) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Metadata) ProtoMessage

func (*Metadata) ProtoMessage()

func (*Metadata) ProtoReflect

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

func (*Metadata) Reset

func (x *Metadata) Reset()

func (*Metadata) String

func (x *Metadata) String() string

func (*Metadata) UnmarshalJSON

func (msg *Metadata) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type NullValue

type NullValue = structpb.NullValue

type Paging

type Paging struct {

	// 请求页码,从 1 开始
	Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
	// 每页请求数量
	PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	// 总记录数
	Total int32 `protobuf:"varint,3,opt,name=total,proto3" json:"total,omitempty"`
	// contains filtered or unexported fields
}

基于页码的请求和响应分页信息

func NewPaging

func NewPaging(page, limit int) *Paging

NewPaging 构造分页对象,并将非正数页码和每页数量替换为默认值。

func (*Paging) Descriptor deprecated

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

Deprecated: Use Paging.ProtoReflect.Descriptor instead.

func (*Paging) GetLimit

func (x *Paging) GetLimit() int

GetLimit 返回规范化后的每页数量。

func (*Paging) GetOffset

func (x *Paging) GetOffset() int

GetOffset 返回从零开始的分页偏移量。

func (*Paging) GetOffsetLimit

func (x *Paging) GetOffsetLimit() (int, int)

GetOffsetLimit 返回从零开始的偏移量和规范化后的每页数量。

func (*Paging) GetPage

func (x *Paging) GetPage() int32

func (*Paging) GetPageSize

func (x *Paging) GetPageSize() int32

func (*Paging) GetTotal

func (x *Paging) GetTotal() int32

func (*Paging) MarshalJSON

func (msg *Paging) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Paging) ProtoMessage

func (*Paging) ProtoMessage()

func (*Paging) ProtoReflect

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

func (*Paging) Reset

func (x *Paging) Reset()

func (*Paging) String

func (x *Paging) String() string

func (*Paging) UnmarshalJSON

func (msg *Paging) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Paging) WithTotal

func (x *Paging) WithTotal(total int64) *Paging

WithTotal 返回包含规范化页码、每页数量和总记录数的新分页对象。

type Status

type Status = status.Status

type StringValue

type StringValue = wrapperspb.StringValue

type Struct

type Struct = structpb.Struct

type TimeRange

type TimeRange struct {

	// 开始时间
	Start *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=start,proto3" json:"start,omitempty"`
	// 结束时间
	End *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=end,proto3" json:"end,omitempty"`
	// contains filtered or unexported fields
}

包含首尾边界的时间范围

func (*TimeRange) Descriptor deprecated

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

Deprecated: Use TimeRange.ProtoReflect.Descriptor instead.

func (*TimeRange) GetEnd

func (x *TimeRange) GetEnd() *timestamppb.Timestamp

func (*TimeRange) GetStart

func (x *TimeRange) GetStart() *timestamppb.Timestamp

func (*TimeRange) MarshalJSON

func (msg *TimeRange) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*TimeRange) ProtoMessage

func (*TimeRange) ProtoMessage()

func (*TimeRange) ProtoReflect

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

func (*TimeRange) Reset

func (x *TimeRange) Reset()

func (*TimeRange) String

func (x *TimeRange) String() string

func (*TimeRange) UnmarshalJSON

func (msg *TimeRange) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Timestamp

type Timestamp = timestamppb.Timestamp

type UInt32Value

type UInt32Value = wrapperspb.UInt32Value

type UInt64Value

type UInt64Value = wrapperspb.UInt64Value

type Value

type Value = structpb.Value

type Value_BoolValue

type Value_BoolValue = structpb.Value_BoolValue

type Value_ListValue

type Value_ListValue = structpb.Value_ListValue

type Value_NullValue

type Value_NullValue = structpb.Value_NullValue

type Value_NumberValue

type Value_NumberValue = structpb.Value_NumberValue

type Value_StringValue

type Value_StringValue = structpb.Value_StringValue

type Value_StructValue

type Value_StructValue = structpb.Value_StructValue

Jump to

Keyboard shortcuts

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