Skip to content

Commit 3c3e748

Browse files
committed
update
1 parent 89060b6 commit 3c3e748

File tree

11 files changed

+128
-43
lines changed

11 files changed

+128
-43
lines changed

cgrpc/protoc-gen-go-cgrpc/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func main() {
2424
}
2525
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2626
//pre check
27+
needfile := make(map[string]bool)
2728
for _, f := range gen.Files {
2829
if !f.Generate {
2930
continue
@@ -56,6 +57,7 @@ func main() {
5657
if !need {
5758
continue
5859
}
60+
needfile[f.Desc.Path()] = true
5961
if pbex.OneOfHasPBEX(m.Input) {
6062
panic("oneof fields should not contain pbex")
6163
}
@@ -72,10 +74,7 @@ func main() {
7274
}
7375
//gen file
7476
for _, f := range gen.Files {
75-
if !f.Generate {
76-
continue
77-
}
78-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
77+
if status, ok := needfile[f.Desc.Path()]; !ok || !status {
7978
continue
8079
}
8180
generateFile(gen, f)

codegen/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/chenjie199234/Corelib/codegen/tml/server/xraw"
3030
"github.com/chenjie199234/Corelib/codegen/tml/server/xweb"
3131
"github.com/chenjie199234/Corelib/codegen/tml/service"
32+
serviceraw "github.com/chenjie199234/Corelib/codegen/tml/service/raw"
3233
servicestatus "github.com/chenjie199234/Corelib/codegen/tml/service/status"
3334
"github.com/chenjie199234/Corelib/codegen/tml/service/sub"
3435
"github.com/chenjie199234/Corelib/codegen/tml/util"
@@ -217,13 +218,15 @@ func createBaseProject() {
217218
dao.CreatePathAndFile(*packagename)
218219

219220
subdao.CreatePathAndFile("status")
221+
subdao.CreatePathAndFile("raw")
220222

221223
mainfile.CreatePathAndFile(*packagename)
222224

223225
gomod.CreatePathAndFile(*packagename)
224226

225227
model.CreatePathAndFile(*appname)
226228
submodel.CreatePathAndFile("status")
229+
submodel.CreatePathAndFile("raw")
227230

228231
util.CreatePathAndFile()
229232

@@ -238,6 +241,7 @@ func createBaseProject() {
238241
service.CreatePathAndFile(*packagename)
239242

240243
servicestatus.CreatePathAndFile(*packagename)
244+
serviceraw.CreatePathAndFile(*packagename)
241245

242246
cmd.CreatePathAndFile(*packagename, *appname)
243247

codegen/tml/server/xraw/template_xraw.go

+8-18
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
const txt = `package xraw
99
1010
import (
11-
"context"
1211
"crypto/tls"
1312
"log/slog"
1413
1514
"{{.}}/config"
15+
"{{.}}/service"
1616
1717
"github.com/chenjie199234/Corelib/stream"
1818
)
@@ -39,13 +39,15 @@ func StartRawServer() {
3939
TcpC: &stream.TcpConfig{ConnectTimeout: c.ConnectTimeout.StdDuration(), MaxMsgLen: c.MaxMsgLen},
4040
HeartprobeInterval: c.HeartProbe.StdDuration(),
4141
GroupNum: c.GroupNum,
42-
VerifyFunc: rawVerify,
43-
OnlineFunc: rawOnline,
44-
PingPongFunc: rawPingPong,
45-
UserdataFunc: rawUser,
46-
OfflineFunc: rawOffline,
42+
VerifyFunc: service.SvcRaw.RawVerify,
43+
OnlineFunc: service.SvcRaw.RawOnline,
44+
PingPongFunc: service.SvcRaw.RawPingPong,
45+
UserdataFunc: service.SvcRaw.RawUser,
46+
OfflineFunc: service.SvcRaw.RawOffline,
4747
})
4848
49+
service.SvcRaw.SetStreamInstance(s)
50+
4951
if e := s.StartServer(":7000", tlsc); e != nil && e != stream.ErrServerClosed {
5052
slog.ErrorContext(nil, "[xraw] start server failed", slog.String("error", e.Error()))
5153
return
@@ -58,18 +60,6 @@ func StopRawServer() {
5860
if s != nil {
5961
s.Stop()
6062
}
61-
}
62-
func rawVerify(ctx context.Context, peerVerifyData []byte) (response []byte, uniqueid string, success bool) {
63-
return nil, "", false
64-
}
65-
func rawOnline(ctx context.Context, p *stream.Peer) (success bool) {
66-
return false
67-
}
68-
func rawPingPong(p *stream.Peer) {
69-
}
70-
func rawUser(p *stream.Peer, userdata []byte) {
71-
}
72-
func rawOffline(p *stream.Peer) {
7363
}`
7464

7565
func CreatePathAndFile(packagename string) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package raw
2+
3+
import (
4+
"os"
5+
"text/template"
6+
)
7+
8+
const txt = `package raw
9+
10+
import (
11+
"context"
12+
// "log/slog"
13+
14+
// "{{.}}/config"
15+
// "{{.}}/api"
16+
rawdao "{{.}}/dao/raw"
17+
// "{{.}}/ecode"
18+
19+
"github.com/chenjie199234/Corelib/stream"
20+
"github.com/chenjie199234/Corelib/util/graceful"
21+
)
22+
23+
// Service subservice for raw business
24+
type Service struct {
25+
stop *graceful.Graceful
26+
27+
rawDao *rawdao.Dao
28+
instance *stream.Instance
29+
}
30+
31+
// Start -
32+
func Start() *Service {
33+
return &Service{
34+
stop: graceful.New(),
35+
36+
//rawDao: rawdao.NewDao(config.GetMysql("raw_mysql"), config.GetRedis("raw_redis"), config.GetMongo("raw_mongo")),
37+
rawDao: rawdao.NewDao(nil, nil, nil),
38+
}
39+
}
40+
41+
func (s *Service) SetStreamInstance(instance *stream.Instance) {
42+
s.instance = instance
43+
}
44+
45+
func (s *Service) RawVerify(ctx context.Context, peerVerifyData []byte) (response []byte, uniqueid string, success bool) {
46+
return nil, "", false
47+
}
48+
49+
func (s *Service) RawOnline(ctx context.Context, p *stream.Peer) (success bool) {
50+
return false
51+
}
52+
53+
func (s *Service) RawPingPong(p *stream.Peer) {
54+
}
55+
56+
func (s *Service) RawUser(p *stream.Peer, userdata []byte) {
57+
}
58+
59+
func (s *Service) RawOffline(p *stream.Peer) {
60+
}
61+
62+
// Stop -
63+
func (s *Service) Stop() {
64+
s.stop.Close(nil, nil)
65+
}`
66+
67+
func CreatePathAndFile(packagename string) {
68+
if e := os.MkdirAll("./service/raw/", 0755); e != nil {
69+
panic("mkdir ./service/raw/ error: " + e.Error())
70+
}
71+
servicetemplate, e := template.New("./service/raw/service.go").Parse(txt)
72+
if e != nil {
73+
panic("parse ./service/raw/service.go template error: " + e.Error())
74+
}
75+
file, e := os.OpenFile("./service/raw/service.go", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644)
76+
if e != nil {
77+
panic("open ./service/raw/service.go error: " + e.Error())
78+
}
79+
if e := servicetemplate.Execute(file, packagename); e != nil {
80+
panic("write ./service/raw/service.go error: " + e.Error())
81+
}
82+
if e := file.Sync(); e != nil {
83+
panic("sync ./service/raw/service.go error: " + e.Error())
84+
}
85+
if e := file.Close(); e != nil {
86+
panic("close ./service/raw/service.go error: " + e.Error())
87+
}
88+
}

codegen/tml/service/template_service.go

+6
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,32 @@ const txt = `package service
99
1010
import (
1111
"{{.}}/dao"
12+
"{{.}}/service/raw"
1213
"{{.}}/service/status"
1314
)
1415
1516
// SvcStatus one specify sub service
1617
var SvcStatus *status.Service
1718
19+
// SvcRaw one specify sub service
20+
var SvcRaw *raw.Service
21+
1822
// StartService start the whole service
1923
func StartService() error {
2024
if e := dao.NewApi(); e != nil {
2125
return e
2226
}
2327
//start sub service
2428
SvcStatus = status.Start()
29+
SvcRaw = raw.Start()
2530
return nil
2631
}
2732
2833
// StopService stop the whole service
2934
func StopService() {
3035
//stop sub service
3136
SvcStatus.Stop()
37+
SvcRaw.Stop()
3238
}`
3339

3440
func CreatePathAndFile(packagename string) {

crpc/protoc-gen-go-crpc/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func main() {
2424
}
2525
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2626
//pre check
27+
needfile := make(map[string]bool)
2728
for _, f := range gen.Files {
2829
if !f.Generate {
2930
continue
@@ -56,6 +57,7 @@ func main() {
5657
if !need {
5758
continue
5859
}
60+
needfile[f.Desc.Path()] = true
5961
if pbex.OneOfHasPBEX(m.Input) {
6062
panic("oneof fields should not contain pbex")
6163
}
@@ -72,10 +74,7 @@ func main() {
7274
}
7375
//gen file
7476
for _, f := range gen.Files {
75-
if !f.Generate {
76-
continue
77-
}
78-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
77+
if status, ok := needfile[f.Desc.Path()]; !ok || !status {
7978
continue
8079
}
8180
generateFile(gen, f)

internal/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "fmt"
44

55
var major = 0
66
var minor = 0
7-
var patch = 122
7+
var patch = 123
88
var status = ""
99

1010
func String() string {

pbex/protoc-gen-go-pbex/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ func main() {
2020
}
2121
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2222
//pre check
23+
needfile := make(map[string]bool)
2324
for _, f := range gen.Files {
2425
if !f.Generate {
2526
continue
2627
}
28+
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
29+
continue
30+
}
2731
if *f.Proto.Syntax != "proto3" {
2832
panic("plugin only support proto3 syntax!")
2933
}
@@ -32,6 +36,7 @@ func main() {
3236
panic("oneof fields should not contain pbex")
3337
}
3438
}
39+
needfile[f.Desc.Path()] = len(f.Messages) > 0
3540
//delete old file
3641
oldfile := f.GeneratedFilenamePrefix + "_pbex.pb.go"
3742
if e := os.RemoveAll(oldfile); e != nil {
@@ -40,10 +45,7 @@ func main() {
4045
}
4146
//gen file
4247
for _, f := range gen.Files {
43-
if !f.Generate {
44-
continue
45-
}
46-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
48+
if status, ok := needfile[f.Desc.Path()]; !ok || !status {
4749
continue
4850
}
4951
generateFile(gen, f)

web/protoc-gen-browser/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
}
2626
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2727
//pre check
28+
needfile := make(map[string]bool)
2829
for _, f := range gen.Files {
2930
if !f.Generate {
3031
continue
@@ -60,6 +61,7 @@ func main() {
6061
if need == 0 {
6162
continue
6263
}
64+
needfile[f.Desc.Path()] = true
6365
if need > 1 {
6466
panic(fmt.Sprintf("method: %s in service: %s,only one http method can be setted", m.Desc.Name(), s.Desc.Name()))
6567
}
@@ -97,10 +99,7 @@ func main() {
9799
}
98100
//gen file
99101
for _, f := range gen.Files {
100-
if !f.Generate {
101-
continue
102-
}
103-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
102+
if status, ok := needfile[f.Desc.Path()]; !ok || !status {
104103
continue
105104
}
106105
generateFile(gen, f)

web/protoc-gen-go-web/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
}
2626
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2727
//pre check
28+
needfile := make(map[string]bool)
2829
for _, f := range gen.Files {
2930
if !f.Generate {
3031
continue
@@ -60,6 +61,7 @@ func main() {
6061
if need == 0 {
6162
continue
6263
}
64+
needfile[f.Desc.Path()] = true
6365
if need > 1 {
6466
panic(fmt.Sprintf("method: %s in service: %s,only one http method can be setted", m.Desc.Name(), s.Desc.Name()))
6567
}
@@ -97,10 +99,7 @@ func main() {
9799
}
98100
//gen file
99101
for _, f := range gen.Files {
100-
if !f.Generate {
101-
continue
102-
}
103-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
102+
if status, ok := needfile[f.Desc.Path()]; !ok || !status {
104103
continue
105104
}
106105
generateFile(gen, f)

web/protoc-gen-markdown/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
}
2626
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
2727
//pre check
28+
needfile := make(map[string]bool)
2829
for _, f := range gen.Files {
2930
if !f.Generate {
3031
continue
@@ -60,6 +61,7 @@ func main() {
6061
if need == 0 {
6162
continue
6263
}
64+
needfile[string(f.Desc.Path())] = true
6365
if need > 1 {
6466
panic(fmt.Sprintf("method: %s in service: %s,only one http method can be setted", m.Desc.Name(), s.Desc.Name()))
6567
}
@@ -96,10 +98,7 @@ func main() {
9698
}
9799
//gen file
98100
for _, f := range gen.Files {
99-
if !f.Generate {
100-
continue
101-
}
102-
if f.Desc.Options().(*descriptorpb.FileOptions).GetDeprecated() {
101+
if status, ok := needfile[string(f.Desc.FullName())]; !ok || !status {
103102
continue
104103
}
105104
generateFile(gen, f)

0 commit comments

Comments
 (0)