We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version go1.22.3 darwin/amd64
v2.7.0
Option Yes
I run gf-demo-grpc and use PostgresSQL for database. DDL is:
create table "user" ( id serial primary key, passport varchar(45) not null unique, password varchar(45) not null, nickname varchar(45) not null, create_at timestamp, update_at timestamp, delete_at timestamp );
When i request the GetById method, scan the zero value for google.protobuf.Timestamp of pbentity.User
{ "User": { "Id": 1, "Passport": "正团小斯", "Password": "口际严消只但", "Nickname": "进影一得华来行", "CreateAt": { "seconds": "0", "nanos": 0 }, "UpdateAt": { "seconds": "0", "nanos": 0 }, "DeleteAt": null } }
{ "User": { "Id": 1, "Passport": "正团小斯", "Password": "口际严消只但", "Nickname": "进影一得华来行", "CreateAt": { "seconds": "1715155546", "nanos": 0 }, "UpdateAt": { "seconds": "1715155546", "nanos": 0 }, "DeleteAt": null } }
The text was updated successfully, but these errors were encountered:
目前是这样实现的,不知道有没有更优雅的方式
func (s *sUser) GetById(ctx context.Context, uid uint64) (*pbentity.User, error) { var ( user *entity.User userPB *pbentity.User ) // 从数据库中获取用户信息 err := dao.User.Ctx(ctx).Where(do.User{ Id: uid, }).Scan(&user) if user == nil { return nil, gerror.NewCodef(gcode.CodeInvalidParameter, g.I18n().T(ctx, "{#user-not-found}")) } // 转换 pb 对象 if err := gconv.Struct(user, &userPB); err != nil { return nil, gerror.NewCodef(gcode.CodeInternalError, g.I18n().T(ctx, "{#system-busy}")) } // 处理 pb 时间 userPB.CreateAt = timestamppb.New(user.CreateAt.Time) userPB.UpdateAt = timestamppb.New(user.UpdateAt.Time) return userPB, err }
Sorry, something went wrong.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This is currently possible, but I don’t know if there is a more elegant way.
func (s *sUser) GetById(ctx context.Context, uid uint64) (*pbentity.User, error) { var ( user *entity.User userPB *pbentity.User ) // Get user information from the database err := dao.User.Ctx(ctx).Where(do.User{ Id: uid, }).Scan(&user) if user == nil { return nil, gerror.NewCodef(gcode.CodeInvalidParameter, g.I18n().T(ctx, "{#user-not-found}")) } // Convert pb object if err := gconv.Struct(user, &userPB); err != nil { return nil, gerror.NewCodef(gcode.CodeInternalError, g.I18n().T(ctx, "{#system-busy}")) } // Process pb time userPB.CreateAt = timestamppb.New(user.CreateAt.Time) userPB.UpdateAt = timestamppb.New(user.UpdateAt.Time) return userPB, err }
@zcyc 可以试试给字段实现一个json.Unmarshaler接口
No branches or pull requests
Go version
go version go1.22.3 darwin/amd64
GoFrame version
v2.7.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
I run gf-demo-grpc and use PostgresSQL for database.
DDL is:
When i request the GetById method, scan the zero value for google.protobuf.Timestamp of pbentity.User
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: