Skip to content

Commit

Permalink
feat: beta2
Browse files Browse the repository at this point in the history
  • Loading branch information
2637309949 committed Nov 7, 2019
1 parent 60261cc commit 5a8f56e
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 18 deletions.
1 change: 1 addition & 0 deletions cli/gen/pipes/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type App struct {
func (app *App) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, error) {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
"Application": node,
}
return []*gen.TmplCfg{
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Auto struct {
func (auto *Auto) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, error) {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
"Controllers": node.Controllers,
"Tables": node.Tables,
}
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (m *Bean) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, erro
for _, bean := range node.Beans {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
"Bean": bean,
}
tmplCfg := &gen.TmplCfg{
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (ctr *Ctr) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
for _, c := range node.Controllers {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
"Controller": c,
}
tmplCfg := &gen.TmplCfg{
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Main struct {
func (m *Main) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, error) {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
}
return []*gen.TmplCfg{
&gen.TmplCfg{
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (m *Model) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, err
for _, table := range node.Tables {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
"Table": table,
}
tmplCfg := &gen.TmplCfg{
Expand Down
1 change: 1 addition & 0 deletions cli/gen/pipes/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Tools struct {
func (tool *Tools) Build(dir string, node *schema.Application) ([]*gen.TmplCfg, error) {
data := map[string]interface{}{
"PackageName": node.PackageName,
"Name": node.Name,
}
return []*gen.TmplCfg{
&gen.TmplCfg{
Expand Down
14 changes: 9 additions & 5 deletions cli/platform/app/app.engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ func (e *Engine) Group(relativePath string, handlers ...gin.HandlerFunc) *Router

// Migration models
func (e *Engine) Migration() error {
e.MSets.ForEach(func(m interface{}) {
for _, db := range e.BusinessDBSet {
db.Sync2(m)
e.MSets.ForEach(func(n string, m interface{}) {
if n != Name {
for _, db := range e.BusinessDBSet {
db.Sync2(m)
}
} else {
e.PlatformDB.Sync2(m)
}
e.PlatformDB.Sync2(m)

})
return nil
}
Expand Down Expand Up @@ -136,7 +140,7 @@ func BuildEngine(build func(*Engine)) func(*Engine) {
func NewEngine() *Engine {
gin.SetMode(gin.ReleaseMode)
e := &Engine{}
e.MSets = &MSets{m: []interface{}{}}
e.MSets = &MSets{m: map[string][]interface{}{}}
e.Gin = gin.New()
e.Gin.Use(gin.Logger())
e.Gin.Use(nice.Recovery(func(ctx *gin.Context, err interface{}) {
Expand Down
1 change: 1 addition & 0 deletions cli/platform/app/app.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions cli/platform/app/app.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@ package app

// MSeti model template
type MSeti interface {
Add(m interface{})
Get(func(interface{}) bool) interface{}
ForEach(func(interface{}))
Add(string, interface{})
Get(func(string, interface{}) bool) interface{}
ForEach(func(string, interface{}))
}

// MSets struct
type MSets struct {
m []interface{}
m map[string][]interface{}
}

// Get defined get models
func (s *MSets) Get(cb func(interface{}) bool) interface{} {
func (s *MSets) Get(cb func(string, interface{}) bool) interface{} {
var model interface{}
s.ForEach(func(m interface{}) {
if cb(m) {
s.ForEach(func(name string, m interface{}) {
if cb(name, m) {
model = m
}
})
return model
}

// Add defined add models
func (s *MSets) Add(m interface{}) {
s.m = append(s.m, m)
func (s *MSets) Add(n string, m interface{}) {
s.m[n] = append(s.m[n], m)
}

// ForEach defined foreach models
func (s *MSets) ForEach(cb func(m interface{})) {
for index := 0; index < len(s.m); index++ {
cb(s.m[index])
func (s *MSets) ForEach(cb func(name string, m interface{})) {
for name, m := range s.m {
for index := 0; index < len(m); index++ {
cb(name, m[index])
}
}
}
5 changes: 4 additions & 1 deletion cli/tempalte/auto.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import (
"github.com/2637309949/dolphin/srv/cli"
)
// Name project
var Name = "{{.Name}}"
// Sync models
var _ = cli.Invoke(BuildEngine(func(e *Engine) {
{{- range .Tables}}
e.MSets.Add(new(model.{{.ToUpperCase .Name}}))
e.MSets.Add(Name, new(model.{{.ToUpperCase .Name}}))
{{- end}}
}))
{{range .Controllers}}
Expand Down
1 change: 1 addition & 0 deletions srv/demo/app.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
port:8082

0 comments on commit 5a8f56e

Please sign in to comment.