master
李伟乐 2 years ago
parent caf994906e
commit 41bb446812
  1. 9
      Makefile
  2. 3
      cmd/kit/main.go
  3. 104
      cmd/ts/main.go
  4. 9
      proto/buf.gen.yaml
  5. BIN
      proto/main
  6. 1187
      proto/user.proto
  7. 10
      proto/v1/auth/auth.pb.go
  8. 2
      proto/v1/user.gin.go
  9. 12383
      proto/v1/user.pb.go
  10. 16529
      proto/v1/user.pb.validate.go
  11. 856
      proto/v1/user.ts
  12. 1996
      proto/v1/user_grpc.pb.go

@ -0,0 +1,9 @@
kit:
go build -o ~/go/bin/protoc-gen-kit cmd/kit/main.go
ts:
go build -o ~/go/bin/protoc-gen-ts cmd/ts/main.go
all:
make kit
make ts
testts:
make ts

@ -5,7 +5,6 @@ import (
"google.golang.org/genproto/googleapis/api/annotations" "google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/compiler/protogen" "google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb" "google.golang.org/protobuf/types/descriptorpb"
"log"
) )
// go build && protoc --unknow_out=./proto --go_out=./proto/ --go-grpc_out=./proto proto/user.proto -I ./proto // go build && protoc --unknow_out=./proto --go_out=./proto/ --go-grpc_out=./proto proto/user.proto -I ./proto
@ -171,7 +170,7 @@ func (u *Kit) genDelete(serverName string, t *protogen.GeneratedFile, m *protoge
func (Kit) getMethod(m *protogen.Method) (method string, path string) { func (Kit) getMethod(m *protogen.Method) (method string, path string) {
if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok { if op, ok := m.Desc.Options().(*descriptorpb.MethodOptions); ok {
if opts, err := proto.GetExtension(op, annotations.E_Http); err != nil { if opts, err := proto.GetExtension(op, annotations.E_Http); err != nil {
log.Println(err) //log.Println(err)
} else { } else {
if vv, ok := opts.(*annotations.HttpRule); ok { if vv, ok := opts.(*annotations.HttpRule); ok {
if vvv, ok := vv.Pattern.(*annotations.HttpRule_Get); ok { if vvv, ok := vv.Pattern.(*annotations.HttpRule_Get); ok {

@ -0,0 +1,104 @@
package main
import (
"fmt"
"google.golang.org/protobuf/compiler/protogen"
"strings"
)
func main() {
u := &Kit{
imports: map[string]string{},
}
protogen.Options{}.Run(u.Generate)
}
type Kit struct {
imports map[string]string
}
func (u *Kit) addImports(imp string) {
u.imports[imp] = imp
}
func (u *Kit) Generate(plugin *protogen.Plugin) error {
if len(plugin.Files) < 1 {
return nil
}
for _, f := range plugin.Files {
if len(f.Services) == 0 {
continue
}
fname := f.GeneratedFilenamePrefix + ".ts"
t := plugin.NewGeneratedFile(fname, f.GoImportPath)
for _, s := range f.Messages {
t.P(`export interface `, s.Desc.Name(), ` {`)
for _, vv := range s.Fields {
common := strings.TrimSpace(vv.Comments.Leading.String())
if common != "" {
t.P(` `, common)
}
typ := []string{}
isRequired := ":"
if vv.Desc.IsMap() {
fields := vv.Desc.Message().Fields()
typ = append(typ, fmt.Sprintf(`{ [key: %s]: %s }`, getType(fields.Get(0).Kind().String()), getType(fields.Get(1).Kind().String())))
} else if vv.Desc.Kind().String() == "message" {
//t.P(vv.Desc.Message().Fields())
//t.P(vv.Desc.Message().Name())
//if vv.Desc.Message().Fields().Get(0).Name() == "value" {
// isRequired = "?:"
// //typ = append(typ, getType(vv.Desc.Message().Fields().Get(0).Kind().String()))
//} else {
fullName := fmt.Sprintf("%v", vv.Desc.Message().FullName())
if strings.HasPrefix(fullName, "google.protobuf") && strings.HasSuffix(fullName, "Value") {
isRequired = "?:"
}
typ = append(typ, getType(fmt.Sprintf("%v", vv.Desc.Message().Name())))
//}
} else {
typ = append(typ, getType(vv.Desc.Kind().String()))
}
//vtype := fmt.Sprintf("%v", vv.Desc.Kind())
//if vtype == "bytes" {
// typ = append(typ, "Uint8Array")
//} else if vtype == "message" {
// if vv.Desc.IsMap() {
// typ = append(typ, fmt.Sprintf(`{ [key: %s]: %s }`, fields.Get(0).Kind().String(), fields.Get(1).Kind().String()))
// } else {
//
// }
//
// //for _,v:=range vv.Desc.Message().Fields(){
// //
// //}
// //t.P()
// //typ = append(typ, "Uint8Array")
//} else {
// typ = append(typ, vtype)
//}
if vv.Desc.IsList() {
typ = append(typ, "[]")
}
//t.P(vv.Desc)
t.P(` `, vv.Desc.JSONName(), isRequired, ` `, strings.Join(typ, ""))
}
t.P(`}`)
t.P()
}
}
return nil
}
func getType(key string) string {
mps := map[string]string{
"int32": "number",
"bytes": "Uint8Array",
"Int32Value": "number",
"StringValue": "string",
"bool": "boolean",
}
if v, ok := mps[key]; ok {
return v
}
return key
}

@ -8,8 +8,13 @@ plugins:
out: v1 out: v1
opt: opt:
- paths=source_relative - paths=source_relative
- name: kit # - name: kit
# path: /Users/mogfee/web/protoc-gen-kit/protoc-gen-kit # path: ./main
# out: v1
# opt:
# - paths=source_relative
- name: ts
path: ./main
out: v1 out: v1
opt: opt:
- paths=source_relative - paths=source_relative

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -118,11 +118,11 @@ var file_auth_auth_proto_rawDesc = []byte{
0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f,
0x6e, 0x73, 0x18, 0xd7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x6e, 0x73, 0x18, 0xd7, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, 0x75, 0x74, 0x68,
0x2e, 0x41, 0x75, 0x74, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x42, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x61, 0x75, 0x74, 0x68, 0x42,
0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x2e, 0x65, 0x63, 0x68, 0x69, 0x6e, 0x61, 0x63, 0x69, 0x74, 0x38, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x2e, 0x64, 0x69, 0x75, 0x6c, 0x6f, 0x2e, 0x63, 0x6f, 0x6d,
0x69, 0x65, 0x73, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x6f, 0x67, 0x66, 0x65, 0x65, 0x2f, 0x70, 0x2f, 0x6d, 0x6f, 0x67, 0x66, 0x65, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67,
0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72, 0x65, 0x6e, 0x2d, 0x6b, 0x69, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x31, 0x2f,
0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x3b, 0x61, 0x75, 0x74, 0x68, 0x61, 0x75, 0x74, 0x68, 0x3b, 0x61, 0x75, 0x74, 0x68, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x33,
} }
var ( var (

@ -44,7 +44,7 @@ func httpLoginHandler(srv UserServer, m ...middleware.Middleware) func(c *gin.Co
return return
} }
h := func(ctx context.Context, a any) (any, error) { h := func(ctx context.Context, a any) (any, error) {
return srv.List(ctx, a.(*LoginRequest)) return srv.Login(ctx, a.(*LoginRequest))
} }
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post) out, err := middleware.HttpMiddleware(c, h, m...)(c, &post)
if err != nil { if err != nil {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,856 @@
export interface listCategoryRequest {
cityId: number
listType: string
}
export interface listCategoryResponseItem {
title: string
url: string
isNew: boolean
num: number
}
export interface listCategoryResponse {
list: listCategoryResponseItem[]
}
export interface listQuestionPageRequest {
questionType: string
cityId: number
categoryId: number
page: number
createDay: number
}
export interface listQuestionPageResponseItem {
userId: number
userLogo: string
userLevel: number
userName: string
title: string
url: string
lastTimeTitle: string
lastTimeTitleUrl: string
city: string
cityUrl: string
category: string
categoryUrl: string
answerCount: number
viewCount: number
commentCount: number
isNew: boolean
}
export interface listQuestionPageResponse {
list: listQuestionPageResponseItem[]
count: number
}
export interface listAnswerOfTheDayRequest {
page: number
size: number
}
export interface listAnswerOfTheDayResponseItem {
title: string
url: string
postTime: string
content: string
answeredName: string
shortContent: string
}
export interface listAnswerOfTheDayResponse {
list: listAnswerOfTheDayResponseItem[]
num: number
}
export interface userRightInfoRequest {
}
export interface userRightInfoResponse {
userId: number
userName: string
photo: string
point: number
messageCount: number
newNotice: number
newAnswer: number
newComment: number
userLevel: number
adminLevel: number
email: string
}
export interface listHotTopUserRequest {
}
export interface listHotTopUserResponseItem {
name: string
photo: string
userId: number
}
export interface listHotTopUserResponse {
hots: listHotTopUserResponseItem[]
tops: listHotTopUserResponseItem[]
guestCount: number
}
export interface listFilterQuestionRequest {
title: string
}
export interface listFilterQuestionResponseItem {
title: string
url: string
}
export interface listFilterQuestionResponse {
list: listFilterQuestionResponseItem[]
}
export interface listFilterUserRequest {
user: string
}
export interface listFilterUserResponseItem {
userId: number
userName: string
}
export interface listFilterUserResponse {
list: listFilterUserResponseItem[]
}
export interface listRelatedQuestionsRequest {
cityId: number
categoryId: number
}
export interface listRelatedQuestionsResponseItem {
title: string
url: string
postTime: string
}
export interface listRelatedQuestionsResponse {
list: listRelatedQuestionsResponseItem[]
}
export interface searchQuestionRequest {
keyword: string
page: number
}
export interface searchQuestionResponseItem {
userId: number
userLogo: string
userName: string
title: string
url: string
postTime: string
city: string
cityUrl: string
category: string
categoryUrl: string
answerCount: number
content: string
}
export interface searchQuestionResponse {
list: searchQuestionResponseItem[]
count: number
}
export interface questionDetailPageRequest {
aliasKey: string
nodeId: number
page: number
}
export interface questionDetailPageResponseItemVote {
good: number
bad: number
vote: number
// 0没有点赞 点赞过 1 good 2 bad
status: number
}
export interface questionDetailPageResponseItemUser {
logo: string
name: string
postNum: number
level: number
userId: number
isAnonymous: boolean
signature: string
}
export interface questionDetailPageResponseItemQuestionItem {
forbidden: boolean
city: string
cityUrl: string
category: string
categoryUrl: string
title: string
cityId: number
categoryId: number
}
export interface questionDetailPageResponseItem {
id: number
canManage: boolean
content: string
isDel: boolean
postTime: string
commentNum: number
vote: questionDetailPageResponseItemVote
user: questionDetailPageResponseItemUser
question: questionDetailPageResponseItemQuestionItem
comments: questionDetailPageResponseItem[]
}
export interface questionDetailPageResponse {
question: questionDetailPageResponseItem
highestVoted: questionDetailPageResponseItem
answers: questionDetailPageResponseItem[]
answerCount: number
commentCount: number
}
export interface userCenterProfilePageRequest {
userId: number
questionPage: number
answerPage: number
}
export interface userCenterProfilePageResponseItem {
title: string
postTime: string
answerNum: string
url: string
isDel: boolean
}
export interface userCenterProfilePageResponse {
online: boolean
userName: string
photo: string
point: number
registerTime: string
userLevel: number
aboutMe: string
interests: string
skype: string
email: string
google: string
questionCount: number
questions: userCenterProfilePageResponseItem[]
answerCount: number
answers: userCenterProfilePageResponseItem[]
}
export interface userCenterEditPageRequest {
userId: number
}
export interface userCenterEditPageData {
signature: string
aboutMe: string
interests: string
email: string
google: string
skype: string
isPlainText: boolean
isNotify: boolean
userId: number
}
export interface userCenterEditPageResponse {
data: userCenterEditPageData
}
export interface userCenterEditRequest {
data: userCenterEditPageData
userId: number
}
export interface userCenterEditResponse {
}
export interface userCenterInBoxPageRequest {
userId: number
page: number
}
export interface userCenterInBoxPageResponseItem {
id: number
userName: string
userId: number
isNew: boolean
subject: string
lastTime: string
}
export interface userCenterInBoxPageResponse {
list: userCenterInBoxPageResponseItem[]
count: number
}
export interface deleteInboxRequest {
userId: number
ids: number[]
}
export interface deleteInboxResponse {
}
export interface messageSendRequest {
userIds: number[]
subject: string
content: string
//消息ThreadId
threadId: number
}
export interface messageSendResponse {
id: number
}
export interface messageDetailPageRequest {
messageId: number
page: number
}
export interface messageDetailPageResponseItem {
userId: number
photo: string
userName: string
postTime: string
id: number
content: string
isNew: boolean
}
export interface messageDetailPageResponse {
list: messageDetailPageResponseItem[]
fromName: string
count: number
threadId: number
}
export interface userCenterPointsPageRequest {
userId: number
page: number
}
export interface userCenterPointsPageResponseItem {
point: number
url: string
doTime: string
pointType: string
id: number
}
export interface userCenterPointsPageResponse {
list: userCenterPointsPageResponseItem[]
count: number
allPoints: number
}
export interface userCenterNewAnswersPageRequest {
userId: number
page: number
}
export interface userCenterNewAnswersPageResponseItem {
userId: number
userName: string
logo: string
answer: string
answerTime: string
answerUrl: string
questionUrl: string
question: string
id: number
}
export interface userCenterNewAnswersPageResponse {
list: userCenterNewAnswersPageResponseItem[]
count: number
}
export interface userCenterNewCommentsPageRequest {
page: number
userId: number
}
export interface userCenterNewCommentsPageResponseItem {
userId: number
userName: string
logo: string
comment: string
commentTime: string
commentUrl: string
answer: string
answerUrl: string
answeredId: number
id: number
}
export interface userCenterNewCommentsPageResponse {
list: userCenterNewCommentsPageResponseItem[]
count: number
}
export interface captchaRequest {
}
export interface captchaResponse {
key: string
val: string
}
export interface noticesPageRequest {
page: number
}
export interface noticesPageResponseItem {
title: string
postTime: string
content: string
id: number
}
export interface noticesPageResponse {
list: noticesPageResponseItem[]
count: number
}
export interface forbiddenQuestionRequest {
questionId: number
isForbidden: boolean
}
export interface forbiddenQuestionResponse {
isForbidden: boolean
}
export interface addQuestionRequest {
title: string
content: string
categoryId: number
cityId: number
id: number
userId: number
}
export interface addQuestionResponse {
url: string
}
export interface getEditQuestionRequest {
nid: number
}
export interface getEditQuestionResponse {
title: string
content: string
categoryId: number
cityId: number
id: number
isAnswer: boolean
}
export interface editUserLogoRequest {
imageData: string
userId: number
}
export interface editUserLogoResponse {
url: string
}
export interface deleteNodeRequest {
nodeId: number
reasonTitle: string
reasonBody: string
}
export interface deleteNodeResponse {
}
export interface reportRequest {
nodeId: number
content: string
code: string
codeKey: string
type: string
}
export interface reportResponse {
}
export interface forwardQuestionRequest {
nodeId: number
content: string
originalContent: string
sendTo: string
}
export interface forwardQuestionResponse {
}
export interface addAnswerRequest {
id: number
parentId: number
title: string
content: string
}
export interface addAnswerResponse {
}
export interface voteNodeGoodRequest {
nodeId: number
isGood: boolean
}
export interface voteNodeGoodResponse {
}
export interface loginRequest {
loginType: string
userName: string
password: string
code: string
}
export interface loginResponse {
code: string
}
export interface adminRolesPageRequest {
}
export interface adminRolesPageResponseItem {
name: string
id: number
isBlock: boolean
}
export interface adminRolesPageResponse {
list: adminRolesPageResponseItem[]
count: number
}
export interface adminUpdateRoleActionRequest {
title: string
id: number
}
export interface adminUpdateRoleActionResponse {
}
export interface adminUserPageRequest {
roleId: number
status: number
createdStart: string
createdEnd: string
loginStart: string
loginEnd: string
email: string
userId: number
name: string
page: number
}
export interface adminUserPageResponseItem {
id: number
name: string
status: string
roles: number[]
registerTime: string
lastTime: string
}
export interface adminUserPageResponse {
list: adminUserPageResponseItem[]
count: number
}
export interface adminUpdateUserActionRequest {
userId: number
status?: number
roleIds?: number[]
}
export interface adminUpdateUserActionResponse {
}
export interface adminNodePageRequest {
status: number
// 1 answer 2 question
type: number
page: number
createdStart: string
createdEnd: string
title: string
name: string
userId: number
}
export interface adminNodePageResponseItem {
id: number
title: string
type: string
userId: number
userName: string
status: number
url: string
promote: number
sticky: number
reason: string
postTime: string
changedTime: string
}
export interface adminNodePageResponse {
list: adminNodePageResponseItem[]
count: number
}
export interface updateNodeRequest {
status?: number
promote?: number
sticky?: number
nodeIds: number[]
}
export interface updateNodeResponse {
}
export interface helpPageRequest {
urlKey: string
}
export interface helpPageResponseItem {
title: string
url: string
children: helpPageResponseItem[]
pid: number
}
export interface helpPageResponse {
menus: helpPageResponseItem[]
content: string
title: string
}
export interface randQuestionRequest {
}
export interface randQuestionResponse {
url: string
}
export interface exchangeRequest {
}
export interface exchangeResponseItem {
title: string
content: string
point: number
image: string
id: number
}
export interface exchangeResponse {
list: exchangeResponseItem[]
}
export interface adminExchangeRequest {
page: number
}
export interface adminExchangeResponseItem {
id: number
type: string
name: string
userId: number
points: number
email: string
addressCode: string
address: string
other: string
createdTime: string
}
export interface adminExchangeResponse {
list: adminExchangeResponseItem[]
count: number
}
export interface exchangeActionRequest {
id: number
name: string
email: string
addressCode: string
address: string
other: string
}
export interface exchangeActionResponse {
}
export interface adminPointsPageRequest {
userId: number
typeId: number
page: number
startTime: string
endTime: string
}
export interface adminPointsPageResponseItem {
id: number
userId: number
point: number
createdTime: string
typeId: number
url: string
userName: string
}
export interface adminPointsPageResponse {
list: adminPointsPageResponseItem[]
count: number
}
export interface adminAddPointActionRequest {
userId: number
point: number
typeId: number
description: string
entryId: number
}
export interface adminAddPointActionResponse {
}
export interface redirectRequest {
id: number
type: string
}
export interface redirectResponse {
url: string
}
export interface clearCheckTimeActionRequest {
typeId: number
}
export interface clearCheckTimeActionResponse {
}
export interface adminAddHelpRequest {
id: number
title: string
url: string
parentId: number
sort: number
content: string
}
export interface adminAddHelpResponse {
id: number
}
export interface adminSearchHelpRequest {
status: number
page: number
}
export interface adminSearchHelpResponseItem {
id: number
title: string
url: string
sort: number
status: number
}
export interface adminSearchHelpResponse {
list: adminSearchHelpResponseItem[]
num: number
}
export interface adminGetHelpRequest {
id: number
}
export interface adminGetHelpResponseItem {
id: number
title: string
sort: number
content: string
}
export interface adminGetHelpResponse {
id: number
title: string
url: string
sort: number
list: adminGetHelpResponseItem[]
}
export interface adminDeleteHelpRequest {
id: number
status: number
}
export interface adminDeleteHelpResponse {
}
export interface adminSearchExchangeRequest {
status: number
page: number
}
export interface adminSearchExchangeResponseItem {
id: number
title: string
content: string
picture: string
point: number
status: number
}
export interface adminSearchExchangeResponse {
list: adminSearchExchangeResponseItem[]
count: number
}
export interface adminAddExchangeRequest {
id: number
title: string
content: string
picture: string
point: number
}
export interface adminAddExchangeResponse {
}
export interface adminDeleteExchangeRequest {
id: number
status: number
}
export interface adminDeleteExchangeResponse {
a: Uint8Array[]
b: number
c: { [key: string]: number }
ad: Uint8Array
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save