|
| 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 | +} |
0 commit comments