init
This commit is contained in:
344
backend/pkg/consts/consts.gen.go
Normal file
344
backend/pkg/consts/consts.gen.go
Normal file
@@ -0,0 +1,344 @@
|
||||
// Code generated by go-enum DO NOT EDIT.
|
||||
// Version: -
|
||||
// Revision: -
|
||||
// Build Date: -
|
||||
// Built By: -
|
||||
|
||||
package consts
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// RoleUser is a Role of type user.
|
||||
RoleUser Role = "user"
|
||||
// RoleTenantAdmin is a Role of type tenant_admin.
|
||||
RoleTenantAdmin Role = "tenant_admin"
|
||||
// RoleSuperAdmin is a Role of type super_admin.
|
||||
RoleSuperAdmin Role = "super_admin"
|
||||
)
|
||||
|
||||
var ErrInvalidRole = fmt.Errorf("not a valid Role, try [%s]", strings.Join(_RoleNames, ", "))
|
||||
|
||||
var _RoleNames = []string{
|
||||
string(RoleUser),
|
||||
string(RoleTenantAdmin),
|
||||
string(RoleSuperAdmin),
|
||||
}
|
||||
|
||||
// RoleNames returns a list of possible string values of Role.
|
||||
func RoleNames() []string {
|
||||
tmp := make([]string, len(_RoleNames))
|
||||
copy(tmp, _RoleNames)
|
||||
return tmp
|
||||
}
|
||||
|
||||
// RoleValues returns a list of the values for Role
|
||||
func RoleValues() []Role {
|
||||
return []Role{
|
||||
RoleUser,
|
||||
RoleTenantAdmin,
|
||||
RoleSuperAdmin,
|
||||
}
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (x Role) String() string {
|
||||
return string(x)
|
||||
}
|
||||
|
||||
// IsValid provides a quick way to determine if the typed value is
|
||||
// part of the allowed enumerated values
|
||||
func (x Role) IsValid() bool {
|
||||
_, err := ParseRole(string(x))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
var _RoleValue = map[string]Role{
|
||||
"user": RoleUser,
|
||||
"tenant_admin": RoleTenantAdmin,
|
||||
"super_admin": RoleSuperAdmin,
|
||||
}
|
||||
|
||||
// ParseRole attempts to convert a string to a Role.
|
||||
func ParseRole(name string) (Role, error) {
|
||||
if x, ok := _RoleValue[name]; ok {
|
||||
return x, nil
|
||||
}
|
||||
return Role(""), fmt.Errorf("%s is %w", name, ErrInvalidRole)
|
||||
}
|
||||
|
||||
var errRoleNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *Role) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
*x = Role("")
|
||||
return
|
||||
}
|
||||
|
||||
// A wider range of scannable types.
|
||||
// driver.Value values at the top of the list for expediency
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
*x, err = ParseRole(v)
|
||||
case []byte:
|
||||
*x, err = ParseRole(string(v))
|
||||
case Role:
|
||||
*x = v
|
||||
case *Role:
|
||||
if v == nil {
|
||||
return errRoleNilPtr
|
||||
}
|
||||
*x = *v
|
||||
case *string:
|
||||
if v == nil {
|
||||
return errRoleNilPtr
|
||||
}
|
||||
*x, err = ParseRole(*v)
|
||||
default:
|
||||
return errors.New("invalid type for Role")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x Role) Value() (driver.Value, error) {
|
||||
return x.String(), nil
|
||||
}
|
||||
|
||||
// Set implements the Golang flag.Value interface func.
|
||||
func (x *Role) Set(val string) error {
|
||||
v, err := ParseRole(val)
|
||||
*x = v
|
||||
return err
|
||||
}
|
||||
|
||||
// Get implements the Golang flag.Getter interface func.
|
||||
func (x *Role) Get() interface{} {
|
||||
return *x
|
||||
}
|
||||
|
||||
// Type implements the github.com/spf13/pFlag Value interface.
|
||||
func (x *Role) Type() string {
|
||||
return "Role"
|
||||
}
|
||||
|
||||
type NullRole struct {
|
||||
Role Role
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func NewNullRole(val interface{}) (x NullRole) {
|
||||
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
_ = err // make any errcheck linters happy
|
||||
return
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *NullRole) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
x.Role, x.Valid = Role(""), false
|
||||
return
|
||||
}
|
||||
|
||||
err = x.Role.Scan(value)
|
||||
x.Valid = (err == nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullRole) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
// driver.Value accepts int64 for int values.
|
||||
return string(x.Role), nil
|
||||
}
|
||||
|
||||
type NullRoleStr struct {
|
||||
NullRole
|
||||
}
|
||||
|
||||
func NewNullRoleStr(val interface{}) (x NullRoleStr) {
|
||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullRoleStr) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return x.Role.String(), nil
|
||||
}
|
||||
|
||||
const (
|
||||
// UserStatusPendingVerify is a UserStatus of type pending_verify.
|
||||
UserStatusPendingVerify UserStatus = "pending_verify"
|
||||
// UserStatusVerified is a UserStatus of type verified.
|
||||
UserStatusVerified UserStatus = "verified"
|
||||
// UserStatusBanned is a UserStatus of type banned.
|
||||
UserStatusBanned UserStatus = "banned"
|
||||
)
|
||||
|
||||
var ErrInvalidUserStatus = fmt.Errorf("not a valid UserStatus, try [%s]", strings.Join(_UserStatusNames, ", "))
|
||||
|
||||
var _UserStatusNames = []string{
|
||||
string(UserStatusPendingVerify),
|
||||
string(UserStatusVerified),
|
||||
string(UserStatusBanned),
|
||||
}
|
||||
|
||||
// UserStatusNames returns a list of possible string values of UserStatus.
|
||||
func UserStatusNames() []string {
|
||||
tmp := make([]string, len(_UserStatusNames))
|
||||
copy(tmp, _UserStatusNames)
|
||||
return tmp
|
||||
}
|
||||
|
||||
// UserStatusValues returns a list of the values for UserStatus
|
||||
func UserStatusValues() []UserStatus {
|
||||
return []UserStatus{
|
||||
UserStatusPendingVerify,
|
||||
UserStatusVerified,
|
||||
UserStatusBanned,
|
||||
}
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (x UserStatus) String() string {
|
||||
return string(x)
|
||||
}
|
||||
|
||||
// IsValid provides a quick way to determine if the typed value is
|
||||
// part of the allowed enumerated values
|
||||
func (x UserStatus) IsValid() bool {
|
||||
_, err := ParseUserStatus(string(x))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
var _UserStatusValue = map[string]UserStatus{
|
||||
"pending_verify": UserStatusPendingVerify,
|
||||
"verified": UserStatusVerified,
|
||||
"banned": UserStatusBanned,
|
||||
}
|
||||
|
||||
// ParseUserStatus attempts to convert a string to a UserStatus.
|
||||
func ParseUserStatus(name string) (UserStatus, error) {
|
||||
if x, ok := _UserStatusValue[name]; ok {
|
||||
return x, nil
|
||||
}
|
||||
return UserStatus(""), fmt.Errorf("%s is %w", name, ErrInvalidUserStatus)
|
||||
}
|
||||
|
||||
var errUserStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *UserStatus) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
*x = UserStatus("")
|
||||
return
|
||||
}
|
||||
|
||||
// A wider range of scannable types.
|
||||
// driver.Value values at the top of the list for expediency
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
*x, err = ParseUserStatus(v)
|
||||
case []byte:
|
||||
*x, err = ParseUserStatus(string(v))
|
||||
case UserStatus:
|
||||
*x = v
|
||||
case *UserStatus:
|
||||
if v == nil {
|
||||
return errUserStatusNilPtr
|
||||
}
|
||||
*x = *v
|
||||
case *string:
|
||||
if v == nil {
|
||||
return errUserStatusNilPtr
|
||||
}
|
||||
*x, err = ParseUserStatus(*v)
|
||||
default:
|
||||
return errors.New("invalid type for UserStatus")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x UserStatus) Value() (driver.Value, error) {
|
||||
return x.String(), nil
|
||||
}
|
||||
|
||||
// Set implements the Golang flag.Value interface func.
|
||||
func (x *UserStatus) Set(val string) error {
|
||||
v, err := ParseUserStatus(val)
|
||||
*x = v
|
||||
return err
|
||||
}
|
||||
|
||||
// Get implements the Golang flag.Getter interface func.
|
||||
func (x *UserStatus) Get() interface{} {
|
||||
return *x
|
||||
}
|
||||
|
||||
// Type implements the github.com/spf13/pFlag Value interface.
|
||||
func (x *UserStatus) Type() string {
|
||||
return "UserStatus"
|
||||
}
|
||||
|
||||
type NullUserStatus struct {
|
||||
UserStatus UserStatus
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func NewNullUserStatus(val interface{}) (x NullUserStatus) {
|
||||
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
_ = err // make any errcheck linters happy
|
||||
return
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (x *NullUserStatus) Scan(value interface{}) (err error) {
|
||||
if value == nil {
|
||||
x.UserStatus, x.Valid = UserStatus(""), false
|
||||
return
|
||||
}
|
||||
|
||||
err = x.UserStatus.Scan(value)
|
||||
x.Valid = (err == nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullUserStatus) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
// driver.Value accepts int64 for int values.
|
||||
return string(x.UserStatus), nil
|
||||
}
|
||||
|
||||
type NullUserStatusStr struct {
|
||||
NullUserStatus
|
||||
}
|
||||
|
||||
func NewNullUserStatusStr(val interface{}) (x NullUserStatusStr) {
|
||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||
return
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (x NullUserStatusStr) Value() (driver.Value, error) {
|
||||
if !x.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return x.UserStatus.String(), nil
|
||||
}
|
||||
16
backend/pkg/consts/consts.go
Normal file
16
backend/pkg/consts/consts.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package consts
|
||||
|
||||
// Format
|
||||
//
|
||||
// // swagger:enum CacheKey
|
||||
// // ENUM(
|
||||
// // VerifyCode = "code:__CHANNEL__:%s",
|
||||
// // )
|
||||
|
||||
// swagger:enum Role
|
||||
// ENUM( user, tenant_admin, super_admin)
|
||||
type Role string
|
||||
|
||||
// swagger:enum UserStatus
|
||||
// ENUM(pending_verify, verified, banned, )
|
||||
type UserStatus string
|
||||
387
backend/pkg/proto/user/v1/user.pb.go
Normal file
387
backend/pkg/proto/user/v1/user.pb.go
Normal file
@@ -0,0 +1,387 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc (unknown)
|
||||
// source: user/v1/user.proto
|
||||
|
||||
package userv1
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// User represents a user entity
|
||||
type User struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
|
||||
Phone string `protobuf:"bytes,4,opt,name=phone,proto3" json:"phone,omitempty"`
|
||||
CreateTime string `protobuf:"bytes,5,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
|
||||
UpdateTime string `protobuf:"bytes,6,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *User) Reset() {
|
||||
*x = User{}
|
||||
mi := &file_user_v1_user_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *User) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*User) ProtoMessage() {}
|
||||
|
||||
func (x *User) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_v1_user_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use User.ProtoReflect.Descriptor instead.
|
||||
func (*User) Descriptor() ([]byte, []int) {
|
||||
return file_user_v1_user_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *User) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *User) GetUsername() string {
|
||||
if x != nil {
|
||||
return x.Username
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetEmail() string {
|
||||
if x != nil {
|
||||
return x.Email
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetPhone() string {
|
||||
if x != nil {
|
||||
return x.Phone
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetCreateTime() string {
|
||||
if x != nil {
|
||||
return x.CreateTime
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *User) GetUpdateTime() string {
|
||||
if x != nil {
|
||||
return x.UpdateTime
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ListUsersRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
PageSize int32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||
PageNumber int32 `protobuf:"varint,2,opt,name=page_number,json=pageNumber,proto3" json:"page_number,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ListUsersRequest) Reset() {
|
||||
*x = ListUsersRequest{}
|
||||
mi := &file_user_v1_user_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ListUsersRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListUsersRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ListUsersRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_v1_user_proto_msgTypes[1]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListUsersRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ListUsersRequest) Descriptor() ([]byte, []int) {
|
||||
return file_user_v1_user_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *ListUsersRequest) GetPageSize() int32 {
|
||||
if x != nil {
|
||||
return x.PageSize
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ListUsersRequest) GetPageNumber() int32 {
|
||||
if x != nil {
|
||||
return x.PageNumber
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type ListUsersResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Users []*User `protobuf:"bytes,1,rep,name=users,proto3" json:"users,omitempty"`
|
||||
Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *ListUsersResponse) Reset() {
|
||||
*x = ListUsersResponse{}
|
||||
mi := &file_user_v1_user_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *ListUsersResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListUsersResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ListUsersResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_v1_user_proto_msgTypes[2]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListUsersResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ListUsersResponse) Descriptor() ([]byte, []int) {
|
||||
return file_user_v1_user_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *ListUsersResponse) GetUsers() []*User {
|
||||
if x != nil {
|
||||
return x.Users
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ListUsersResponse) GetTotal() int32 {
|
||||
if x != nil {
|
||||
return x.Total
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetUserRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetUserRequest) Reset() {
|
||||
*x = GetUserRequest{}
|
||||
mi := &file_user_v1_user_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetUserRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetUserRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GetUserRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_v1_user_proto_msgTypes[3]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetUserRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetUserRequest) Descriptor() ([]byte, []int) {
|
||||
return file_user_v1_user_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *GetUserRequest) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetUserResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetUserResponse) Reset() {
|
||||
*x = GetUserResponse{}
|
||||
mi := &file_user_v1_user_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetUserResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetUserResponse) ProtoMessage() {}
|
||||
|
||||
func (x *GetUserResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_user_v1_user_proto_msgTypes[4]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetUserResponse.ProtoReflect.Descriptor instead.
|
||||
func (*GetUserResponse) Descriptor() ([]byte, []int) {
|
||||
return file_user_v1_user_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *GetUserResponse) GetUser() *User {
|
||||
if x != nil {
|
||||
return x.User
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_user_v1_user_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_user_v1_user_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x12user/v1/user.proto\x12\auser.v1\"\xa0\x01\n" +
|
||||
"\x04User\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" +
|
||||
"\busername\x18\x02 \x01(\tR\busername\x12\x14\n" +
|
||||
"\x05email\x18\x03 \x01(\tR\x05email\x12\x14\n" +
|
||||
"\x05phone\x18\x04 \x01(\tR\x05phone\x12\x1f\n" +
|
||||
"\vcreate_time\x18\x05 \x01(\tR\n" +
|
||||
"createTime\x12\x1f\n" +
|
||||
"\vupdate_time\x18\x06 \x01(\tR\n" +
|
||||
"updateTime\"P\n" +
|
||||
"\x10ListUsersRequest\x12\x1b\n" +
|
||||
"\tpage_size\x18\x01 \x01(\x05R\bpageSize\x12\x1f\n" +
|
||||
"\vpage_number\x18\x02 \x01(\x05R\n" +
|
||||
"pageNumber\"N\n" +
|
||||
"\x11ListUsersResponse\x12#\n" +
|
||||
"\x05users\x18\x01 \x03(\v2\r.user.v1.UserR\x05users\x12\x14\n" +
|
||||
"\x05total\x18\x02 \x01(\x05R\x05total\" \n" +
|
||||
"\x0eGetUserRequest\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\"4\n" +
|
||||
"\x0fGetUserResponse\x12!\n" +
|
||||
"\x04user\x18\x01 \x01(\v2\r.user.v1.UserR\x04user2\x93\x01\n" +
|
||||
"\vUserService\x12D\n" +
|
||||
"\tListUsers\x12\x19.user.v1.ListUsersRequest\x1a\x1a.user.v1.ListUsersResponse\"\x00\x12>\n" +
|
||||
"\aGetUser\x12\x17.user.v1.GetUserRequest\x1a\x18.user.v1.GetUserResponse\"\x00Bx\n" +
|
||||
"\vcom.user.v1B\tUserProtoP\x01Z!quyun/v2/pkg/proto/user/v1;userv1\xa2\x02\x03UXX\xaa\x02\aUser.V1\xca\x02\aUser\\V1\xe2\x02\x13User\\V1\\GPBMetadata\xea\x02\bUser::V1b\x06proto3"
|
||||
|
||||
var (
|
||||
file_user_v1_user_proto_rawDescOnce sync.Once
|
||||
file_user_v1_user_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_user_v1_user_proto_rawDescGZIP() []byte {
|
||||
file_user_v1_user_proto_rawDescOnce.Do(func() {
|
||||
file_user_v1_user_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_user_v1_user_proto_rawDesc), len(file_user_v1_user_proto_rawDesc)))
|
||||
})
|
||||
return file_user_v1_user_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_user_v1_user_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_user_v1_user_proto_goTypes = []any{
|
||||
(*User)(nil), // 0: user.v1.User
|
||||
(*ListUsersRequest)(nil), // 1: user.v1.ListUsersRequest
|
||||
(*ListUsersResponse)(nil), // 2: user.v1.ListUsersResponse
|
||||
(*GetUserRequest)(nil), // 3: user.v1.GetUserRequest
|
||||
(*GetUserResponse)(nil), // 4: user.v1.GetUserResponse
|
||||
}
|
||||
var file_user_v1_user_proto_depIdxs = []int32{
|
||||
0, // 0: user.v1.ListUsersResponse.users:type_name -> user.v1.User
|
||||
0, // 1: user.v1.GetUserResponse.user:type_name -> user.v1.User
|
||||
1, // 2: user.v1.UserService.ListUsers:input_type -> user.v1.ListUsersRequest
|
||||
3, // 3: user.v1.UserService.GetUser:input_type -> user.v1.GetUserRequest
|
||||
2, // 4: user.v1.UserService.ListUsers:output_type -> user.v1.ListUsersResponse
|
||||
4, // 5: user.v1.UserService.GetUser:output_type -> user.v1.GetUserResponse
|
||||
4, // [4:6] is the sub-list for method output_type
|
||||
2, // [2:4] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_user_v1_user_proto_init() }
|
||||
func file_user_v1_user_proto_init() {
|
||||
if File_user_v1_user_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_v1_user_proto_rawDesc), len(file_user_v1_user_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 5,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_user_v1_user_proto_goTypes,
|
||||
DependencyIndexes: file_user_v1_user_proto_depIdxs,
|
||||
MessageInfos: file_user_v1_user_proto_msgTypes,
|
||||
}.Build()
|
||||
File_user_v1_user_proto = out.File
|
||||
file_user_v1_user_proto_goTypes = nil
|
||||
file_user_v1_user_proto_depIdxs = nil
|
||||
}
|
||||
167
backend/pkg/proto/user/v1/user_grpc.pb.go
Normal file
167
backend/pkg/proto/user/v1/user_grpc.pb.go
Normal file
@@ -0,0 +1,167 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.0
|
||||
// - protoc (unknown)
|
||||
// source: user/v1/user.proto
|
||||
|
||||
package userv1
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
UserService_ListUsers_FullMethodName = "/user.v1.UserService/ListUsers"
|
||||
UserService_GetUser_FullMethodName = "/user.v1.UserService/GetUser"
|
||||
)
|
||||
|
||||
// UserServiceClient is the client API for UserService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// UserService provides user-related operations
|
||||
type UserServiceClient interface {
|
||||
// ListUsers returns a list of users with pagination
|
||||
ListUsers(ctx context.Context, in *ListUsersRequest, opts ...grpc.CallOption) (*ListUsersResponse, error)
|
||||
// GetUser returns detailed information about a specific user
|
||||
GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error)
|
||||
}
|
||||
|
||||
type userServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient {
|
||||
return &userServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *userServiceClient) ListUsers(ctx context.Context, in *ListUsersRequest, opts ...grpc.CallOption) (*ListUsersResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListUsersResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_ListUsers_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userServiceClient) GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUserResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_GetUser_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserServiceServer is the server API for UserService service.
|
||||
// All implementations must embed UnimplementedUserServiceServer
|
||||
// for forward compatibility.
|
||||
//
|
||||
// UserService provides user-related operations
|
||||
type UserServiceServer interface {
|
||||
// ListUsers returns a list of users with pagination
|
||||
ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error)
|
||||
// GetUser returns detailed information about a specific user
|
||||
GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedUserServiceServer struct{}
|
||||
|
||||
func (UnimplementedUserServiceServer) ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method ListUsers not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetUser not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {}
|
||||
func (UnimplementedUserServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeUserServiceServer interface {
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedUserServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&UserService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _UserService_ListUsers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListUsersRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).ListUsers(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_ListUsers_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).ListUsers(ctx, req.(*ListUsersRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_GetUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetUser(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_GetUser_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetUser(ctx, req.(*GetUserRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var UserService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "user.v1.UserService",
|
||||
HandlerType: (*UserServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "ListUsers",
|
||||
Handler: _UserService_ListUsers_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUser",
|
||||
Handler: _UserService_GetUser_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "user/v1/user.proto",
|
||||
}
|
||||
26
backend/pkg/utils/buffer.go
Normal file
26
backend/pkg/utils/buffer.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
// NewLogBuffer creates a buffer that can be used to capture output stream
|
||||
// and write to a logger in real time
|
||||
func NewLogBuffer(output func(string)) io.Writer {
|
||||
reader, writer := io.Pipe()
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
output(scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
return writer
|
||||
}
|
||||
|
||||
// NewCombinedBuffer combines multiple io.Writers
|
||||
func NewCombinedBuffer(writers ...io.Writer) io.Writer {
|
||||
return io.MultiWriter(writers...)
|
||||
}
|
||||
44
backend/pkg/utils/build_info.go
Normal file
44
backend/pkg/utils/build_info.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package utils
|
||||
|
||||
import "fmt"
|
||||
|
||||
// 构建信息变量,通过 ldflags 在构建时注入
|
||||
var (
|
||||
// Version 应用版本信息
|
||||
Version string
|
||||
|
||||
// BuildAt 构建时间
|
||||
BuildAt string
|
||||
|
||||
// GitHash Git 提交哈希
|
||||
GitHash string
|
||||
)
|
||||
|
||||
// GetBuildInfo 获取构建信息
|
||||
func GetBuildInfo() map[string]string {
|
||||
return map[string]string{
|
||||
"version": Version,
|
||||
"buildAt": BuildAt,
|
||||
"gitHash": GitHash,
|
||||
}
|
||||
}
|
||||
|
||||
// PrintBuildInfo 打印构建信息
|
||||
func PrintBuildInfo(appName string) {
|
||||
buildInfo := GetBuildInfo()
|
||||
|
||||
println("========================================")
|
||||
printf("🚀 %s\n", appName)
|
||||
println("========================================")
|
||||
printf("📋 Version: %s\n", buildInfo["version"])
|
||||
printf("🕐 Build Time: %s\n", buildInfo["buildAt"])
|
||||
printf("🔗 Git Hash: %s\n", buildInfo["gitHash"])
|
||||
println("========================================")
|
||||
println("🌟 Application is starting...")
|
||||
println()
|
||||
}
|
||||
|
||||
// 为了避免导入 fmt 包,我们使用内置的 print 和 printf 函数
|
||||
func printf(format string, args ...interface{}) {
|
||||
print(fmt.Sprintf(format, args...))
|
||||
}
|
||||
Reference in New Issue
Block a user