Browse Source

修改demo目录结构

yjp 1 year ago
parent
commit
c8d3038a0a

+ 2 - 2
convenient/entity/simple.go

@@ -30,7 +30,7 @@ type Simple[I any] struct {
 	UpdateJsonBody request.WithID
 
 	// 查询使用的请求参数,注意是Query类型
-	QueryParams request.Query
+	QueryQueryParams request.Query
 
 	// 根据ID查询使用的请求参数,注意是WithID类型
 	GetByIDQueryParams request.WithID
@@ -110,7 +110,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 		binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
 			Path:          simple.DomainPath + "/query",
 			ResponseFunc:  response.SendInfosResponse[I],
-			RequestParams: simple.QueryParams,
+			RequestParams: simple.QueryQueryParams,
 			Objects:       []domain.Object{simple.Entity},
 			ServiceFunc:   Query[I](simple.TableName, options.queryCallbacks, options.queryConditionFieldCallback),
 		}, options.queryMiddlewares...)

+ 2 - 2
convenient/value_object/simple.go

@@ -27,7 +27,7 @@ type Simple[I any] struct {
 	DeleteQueryParams request.Params
 
 	// 查询使用的请求参数,注意是Query类型
-	QueryParams request.Query
+	QueryQueryParams request.Query
 
 	// 可选配置项,通过WithXXX配置
 	options *Options[I]
@@ -83,7 +83,7 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 		binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
 			Path:          simple.DomainPath + "/query",
 			ResponseFunc:  response.SendInfosResponse[I],
-			RequestParams: simple.QueryParams,
+			RequestParams: simple.QueryQueryParams,
 			Objects:       []domain.Object{simple.ValueObject},
 			ServiceFunc:   Query(simple.TableName, options.queryCallbacks, options.queryConditionFieldCallback),
 		})

+ 0 - 131
examples/binding/main.go

@@ -1,131 +0,0 @@
-package main
-
-import (
-	"git.sxidc.com/go-framework/baize"
-	"git.sxidc.com/go-framework/baize/application"
-	"git.sxidc.com/go-framework/baize/binding/request"
-	"git.sxidc.com/go-framework/baize/convenient/entity"
-	"git.sxidc.com/go-framework/baize/domain"
-	"git.sxidc.com/go-framework/baize/infrastructure"
-	"git.sxidc.com/go-framework/baize/infrastructure/database/operations"
-	DEATH "github.com/vrecan/death"
-	"syscall"
-	"time"
-)
-
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:10100/test/v1/class/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"1a8d5cf5c4574430903e7cfcf2f13e4f", "name":"test-new"}' "http://localhost:10100/test/v1/class/update"
-// curl -X GET "http://localhost:10100/test/v1/class/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:10100/test/v1/class/get?id=1a8d5cf5c4574430903e7cfcf2f13e4f"
-// curl -X DELETE "http://localhost:10100/test/v1/class/1a8d5cf5c4574430903e7cfcf2f13e4f/delete"
-
-type CreateClassJsonBody struct {
-	Name       string `json:"name" binding:"required" assign:"toField:Name"`
-	StudentNum int    `json:"studentNum" binding:"required" assign:"toField:StudentNum"`
-}
-
-type DeleteClassPathParams struct {
-	request.IDPath
-}
-
-type UpdateClassJsonBody struct {
-	request.IDJsonBody
-	Name       string `json:"name" assign:"toField:Name"`
-	StudentNum int    `json:"studentNum" assign:"toField:StudentNum"`
-}
-
-type QueryClassesQueryParams struct {
-	Name       string `form:"name" assign:"toField:Name"`
-	StudentNum int    `form:"studentNum" assign:"toField:StudentNum"`
-	request.BaseQuery
-}
-
-type GetClassQueryParams struct {
-	request.IDQuery
-}
-
-type Class struct {
-	domain.BaseEntity
-	Name            string `sqlmapping:"column:name"`
-	StudentNum      int    `sqlmapping:"column:student_num"`
-	CreatedTime     time.Time
-	LastUpdatedTime *time.Time
-}
-
-func (class *Class) DomainCNName() string {
-	return "班级"
-}
-
-type InfoIDField struct {
-	ID string `json:"id" sqlresult:"column:id"`
-}
-
-type ClassInfo struct {
-	*InfoIDField
-	Name            string `json:"name" sqlresult:"column:name"`
-	StudentNum      int    `json:"studentNum" sqlresult:"column:student_num"`
-	CreatedTime     string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
-	LastUpdatedTime string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
-}
-
-const (
-	tableName = "test.classes"
-)
-
-func main() {
-	app := baize.NewApplication(application.Config{
-		ApiConfig: application.ApiConfig{
-			UrlPrefix: "test",
-			Port:      "10100",
-		},
-		InfrastructureConfig: application.InfrastructureConfig{
-			Database: infrastructure.DatabaseConfig{
-				Operations: &operations.Config{
-					UserName:           "test",
-					Password:           "123456",
-					Address:            "localhost",
-					Port:               "30432",
-					Database:           "test",
-					MaxConnections:     40,
-					MaxIdleConnections: 10,
-				},
-			},
-		},
-	})
-
-	defer func() {
-		baize.DestroyApplication(app)
-	}()
-
-	app.Api().
-		PrefixRouter().
-		RegisterVersionedRouter("v1")
-
-	entity.BindSimple[ClassInfo](app.Binder("v1"), &entity.Simple[ClassInfo]{
-		Entity:             &Class{},
-		TableName:          tableName,
-		DomainPath:         "/class",
-		CreateJsonBody:     &CreateClassJsonBody{},
-		DeleteQueryParams:  &DeleteClassPathParams{},
-		UpdateJsonBody:     &UpdateClassJsonBody{},
-		QueryParams:        &QueryClassesQueryParams{},
-		GetByIDQueryParams: &GetClassQueryParams{},
-	}, entity.WithCreateTx[ClassInfo]())
-
-	go func() {
-		err := app.Start()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	defer func() {
-		err := app.Finish()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
-	_ = death.WaitForDeath()
-}

+ 0 - 130
examples/binding_ds/main.go

@@ -1,130 +0,0 @@
-package main
-
-import (
-	"git.sxidc.com/go-framework/baize"
-	"git.sxidc.com/go-framework/baize/application"
-	"git.sxidc.com/go-framework/baize/binding/request"
-	"git.sxidc.com/go-framework/baize/convenient/entity"
-	"git.sxidc.com/go-framework/baize/domain"
-	"git.sxidc.com/go-framework/baize/infrastructure"
-	"git.sxidc.com/go-framework/baize/infrastructure/database/data_service"
-	DEATH "github.com/vrecan/death"
-	"syscall"
-	"time"
-)
-
-// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:10100/test/v1/class/create"
-// curl -X PUT -H "Content-Type: application/json" -d '{"id":"92cede40e5464ff79541418a7fc738ec", "name":"test-new"}' "http://localhost:10100/test/v1/class/update"
-// curl -X GET "http://localhost:10100/test/v1/class/query?name=test-new&pageNo=1&pageSize=1"
-// curl -X GET "http://localhost:10100/test/v1/class/get?id=92cede40e5464ff79541418a7fc738ec"
-// curl -X DELETE "http://localhost:10100/test/v1/class/92cede40e5464ff79541418a7fc738ec/delete"
-
-type CreateClassJsonBody struct {
-	Name       string `json:"name" binding:"required" assign:"toField:Name"`
-	StudentNum int    `json:"studentNum" binding:"required" assign:"toField:StudentNum"`
-}
-
-type DeleteClassPathParams struct {
-	request.IDPath
-}
-
-type UpdateClassJsonBody struct {
-	request.IDJsonBody
-	Name       string `json:"name" assign:"toField:Name"`
-	StudentNum int    `json:"studentNum" assign:"toField:StudentNum"`
-}
-
-type QueryClassesQueryParams struct {
-	Name       string `form:"name" assign:"toField:Name"`
-	StudentNum int    `form:"studentNum" assign:"toField:StudentNum"`
-	request.BaseQuery
-}
-
-type GetClassQueryParams struct {
-	request.IDQuery
-}
-
-type Class struct {
-	domain.BaseEntity
-	Name            string `sqlmapping:"column:name"`
-	StudentNum      int    `sqlmapping:"column:student_num"`
-	CreatedTime     time.Time
-	LastUpdatedTime *time.Time
-}
-
-func (class *Class) DomainCNName() string {
-	return "班级"
-}
-
-type InfoIDField struct {
-	ID string `json:"id" sqlresult:"column:id"`
-}
-
-type ClassInfo struct {
-	*InfoIDField
-	Name            string `json:"name" sqlresult:"column:name"`
-	StudentNum      int    `json:"studentNum" sqlresult:"column:student_num"`
-	CreatedTime     string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
-	LastUpdatedTime string `sqlresult:"parseTime:'2006-01-02 15:04:05'"`
-}
-
-const (
-	tableName = "test.classes"
-)
-
-func main() {
-	app := baize.NewApplication(application.Config{
-		ApiConfig: application.ApiConfig{
-			UrlPrefix: "test",
-			Port:      "10100",
-		},
-		InfrastructureConfig: application.InfrastructureConfig{
-			Database: infrastructure.DatabaseConfig{
-				DataService: &data_service.Config{
-					Token:       "8qe+uPgpQ2JWxu3lSyOx5NjX+INp5WsnoD1ZWb7PBm4=",
-					BaseUrl:     "http://localhost:10000",
-					GrpcAddress: "localhost:10001",
-					Namespace:   "baize",
-					DataSource:  "baize-binding",
-					TimeoutSec:  30,
-				},
-			},
-		},
-	})
-
-	defer func() {
-		baize.DestroyApplication(app)
-	}()
-
-	app.Api().
-		PrefixRouter().
-		RegisterVersionedRouter("v1")
-
-	entity.BindSimple[ClassInfo](app.Binder("v1"), &entity.Simple[ClassInfo]{
-		Entity:             &Class{},
-		TableName:          tableName,
-		DomainPath:         "/class",
-		CreateJsonBody:     &CreateClassJsonBody{},
-		DeleteQueryParams:  &DeleteClassPathParams{},
-		UpdateJsonBody:     &UpdateClassJsonBody{},
-		QueryParams:        &QueryClassesQueryParams{},
-		GetByIDQueryParams: &GetClassQueryParams{},
-	}, entity.WithUpdateTx[ClassInfo](), entity.WithDeleteTx[ClassInfo]())
-
-	go func() {
-		err := app.Start()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	defer func() {
-		err := app.Finish()
-		if err != nil {
-			panic(err)
-		}
-	}()
-
-	death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
-	_ = death.WaitForDeath()
-}

+ 0 - 53
examples/binding_ds/resources.yaml

@@ -1,53 +0,0 @@
-kind: Namespace
-spec:
-  name: baize
-
----
-
-kind: DataSource
-spec:
-  type: database
-  namespace: baize
-  name: baize-binding
-  spec:
-    type: postgres
-    user_name: test
-    password: "123456"
-    address: "10.0.0.84"
-    port: "30432"
-    database: test
-    max_connections: 40
-    max_idle_connections: 10
-
----
-
-kind: DataContainer
-spec:
-  namespace: baize
-  data_source: baize-binding
-  name: baize-binding
-  spec:
-    table_name: test.classes
-    columns:
-      - name: id
-        type: varchar(32)
-        comment: id
-        primary_key: true
-      - name: name
-        type: varchar(128)
-        comment: 班名
-        not_null: true
-        index: true
-      - name: student_num
-        type: integer
-        comment: 学生数量
-        not_null: true
-        index: true
-      - name: created_time
-        type: "timestamp with time zone"
-        comment: 创建时间
-        not_null: true
-      - name: last_updated_time
-        type: "timestamp with time zone"
-        comment: 最近更新时间
-        not_null: true

+ 20 - 0
examples/example_domain/class/entity.go

@@ -0,0 +1,20 @@
+package class
+
+import (
+	"git.sxidc.com/go-framework/baize/domain"
+)
+
+const (
+	TableName = "test.classes"
+)
+
+type Entity struct {
+	domain.BaseEntity
+	Name       string `sqlmapping:"column:name" sqlresult:"column:name"`
+	StudentNum int    `sqlmapping:"column:student_num" sqlresult:"column:student_num"`
+	domain.TimeFields
+}
+
+func (class *Entity) DomainCNName() string {
+	return "班级"
+}

+ 10 - 0
examples/example_domain/class/info.go

@@ -0,0 +1,10 @@
+package class
+
+import "git.sxidc.com/go-framework/baize/examples/example_domain/common"
+
+type Info struct {
+	common.InfoIDField
+	Name       string `json:"name" sqlresult:"column:name"`
+	StudentNum int    `json:"studentNum" sqlresult:"column:student_num"`
+	common.InfoTimeFields
+}

+ 30 - 0
examples/example_domain/class/request_params.go

@@ -0,0 +1,30 @@
+package class
+
+import "git.sxidc.com/go-framework/baize/binding/request"
+
+type (
+	CreateJsonBody struct {
+		Name       string `json:"name" binding:"required" assign:"toField:Name"`
+		StudentNum int    `json:"studentNum" binding:"required" assign:"toField:StudentNum"`
+	}
+
+	DeletePathParams struct {
+		request.IDPath
+	}
+
+	UpdateJsonBody struct {
+		request.IDJsonBody
+		Name       string `json:"name" assign:"toField:Name"`
+		StudentNum int    `json:"studentNum" assign:"toField:StudentNum"`
+	}
+
+	QueryQueryParams struct {
+		Name       string `form:"name" assign:"toField:Name"`
+		StudentNum int    `form:"studentNum" assign:"toField:StudentNum"`
+		request.BaseQuery
+	}
+
+	GetByIDQueryParams struct {
+		request.IDQuery
+	}
+)

+ 10 - 0
examples/example_domain/common/info.go

@@ -0,0 +1,10 @@
+package common
+
+type InfoIDField struct {
+	ID string `json:"id" sqlresult:"column:id"`
+}
+
+type InfoTimeFields struct {
+	CreatedTime     string `json:"created_time" sqlresult:"column:created_time;parseTime:'2006-01-02 15:04:05'"`
+	LastUpdatedTime string `json:"last_updated_time" sqlresult:"column:last_updated_time;parseTime:'2006-01-02 15:04:05'"`
+}

+ 27 - 0
examples/example_domain/configuration/entity.go

@@ -0,0 +1,27 @@
+package configuration
+
+import (
+	"git.sxidc.com/go-tools/utils/strutils"
+	"git.sxidc.com/service-supports/fserr"
+)
+
+const (
+	TableName = "test.configurations"
+)
+
+type Entity struct {
+	Group string `sqlmapping:"column:group;key;notUpdate;" sqlresult:"column:group;"`
+	Value string `sqlmapping:"column:value;notUpdate;" sqlresult:"column:value;"`
+}
+
+func (e *Entity) DomainCNName() string {
+	return "配置"
+}
+
+func (e *Entity) CheckKeyFields() error {
+	if strutils.IsStringEmpty(e.Group) {
+		return fserr.New("没有传递配置组")
+	}
+
+	return nil
+}

+ 1 - 0
examples/example_domain/configuration/request_params.go

@@ -0,0 +1 @@
+package configuration

+ 0 - 0
examples/assign_tag/main.go → examples/examples/assign_tag/main.go


+ 76 - 0
examples/examples/binding/main.go

@@ -0,0 +1,76 @@
+package main
+
+import (
+	"git.sxidc.com/go-framework/baize"
+	"git.sxidc.com/go-framework/baize/application"
+	"git.sxidc.com/go-framework/baize/convenient/entity"
+	"git.sxidc.com/go-framework/baize/examples/example_domain/class"
+	"git.sxidc.com/go-framework/baize/infrastructure"
+	"git.sxidc.com/go-framework/baize/infrastructure/database/operations"
+	DEATH "github.com/vrecan/death"
+	"syscall"
+)
+
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:10100/test/v1/class/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"1a8d5cf5c4574430903e7cfcf2f13e4f", "name":"test-new"}' "http://localhost:10100/test/v1/class/update"
+// curl -X GET "http://localhost:10100/test/v1/class/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:10100/test/v1/class/get?id=1a8d5cf5c4574430903e7cfcf2f13e4f"
+// curl -X DELETE "http://localhost:10100/test/v1/class/1a8d5cf5c4574430903e7cfcf2f13e4f/delete"
+
+func main() {
+	app := baize.NewApplication(application.Config{
+		ApiConfig: application.ApiConfig{
+			UrlPrefix: "test",
+			Port:      "10100",
+		},
+		InfrastructureConfig: application.InfrastructureConfig{
+			Database: infrastructure.DatabaseConfig{
+				Operations: &operations.Config{
+					UserName:           "test",
+					Password:           "123456",
+					Address:            "localhost",
+					Port:               "30432",
+					Database:           "test",
+					MaxConnections:     40,
+					MaxIdleConnections: 10,
+				},
+			},
+		},
+	})
+
+	defer func() {
+		baize.DestroyApplication(app)
+	}()
+
+	app.Api().
+		PrefixRouter().
+		RegisterVersionedRouter("v1")
+
+	entity.BindSimple[class.Info](app.Binder("v1"), &entity.Simple[class.Info]{
+		Entity:             &class.Entity{},
+		TableName:          class.TableName,
+		DomainPath:         "/class",
+		CreateJsonBody:     &class.CreateJsonBody{},
+		DeleteQueryParams:  &class.DeletePathParams{},
+		UpdateJsonBody:     &class.UpdateJsonBody{},
+		QueryQueryParams:   &class.QueryQueryParams{},
+		GetByIDQueryParams: &class.GetByIDQueryParams{},
+	}, entity.WithCreateTx[class.Info]())
+
+	go func() {
+		err := app.Start()
+		if err != nil {
+			panic(err)
+		}
+	}()
+
+	defer func() {
+		err := app.Finish()
+		if err != nil {
+			panic(err)
+		}
+	}()
+
+	death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
+	_ = death.WaitForDeath()
+}

+ 75 - 0
examples/examples/binding_ds/main.go

@@ -0,0 +1,75 @@
+package main
+
+import (
+	"git.sxidc.com/go-framework/baize"
+	"git.sxidc.com/go-framework/baize/application"
+	"git.sxidc.com/go-framework/baize/convenient/entity"
+	"git.sxidc.com/go-framework/baize/examples/example_domain/class"
+	"git.sxidc.com/go-framework/baize/infrastructure"
+	"git.sxidc.com/go-framework/baize/infrastructure/database/data_service"
+	DEATH "github.com/vrecan/death"
+	"syscall"
+)
+
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:10100/test/v1/class/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"92cede40e5464ff79541418a7fc738ec", "name":"test-new"}' "http://localhost:10100/test/v1/class/update"
+// curl -X GET "http://localhost:10100/test/v1/class/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:10100/test/v1/class/get?id=92cede40e5464ff79541418a7fc738ec"
+// curl -X DELETE "http://localhost:10100/test/v1/class/92cede40e5464ff79541418a7fc738ec/delete"
+
+func main() {
+	app := baize.NewApplication(application.Config{
+		ApiConfig: application.ApiConfig{
+			UrlPrefix: "test",
+			Port:      "10100",
+		},
+		InfrastructureConfig: application.InfrastructureConfig{
+			Database: infrastructure.DatabaseConfig{
+				DataService: &data_service.Config{
+					Token:       "8qe+uPgpQ2JWxu3lSyOx5NjX+INp5WsnoD1ZWb7PBm4=",
+					BaseUrl:     "http://localhost:10000",
+					GrpcAddress: "localhost:10001",
+					Namespace:   "baize",
+					DataSource:  "baize-binding",
+					TimeoutSec:  30,
+				},
+			},
+		},
+	})
+
+	defer func() {
+		baize.DestroyApplication(app)
+	}()
+
+	app.Api().
+		PrefixRouter().
+		RegisterVersionedRouter("v1")
+
+	entity.BindSimple[class.Info](app.Binder("v1"), &entity.Simple[class.Info]{
+		Entity:             &class.Entity{},
+		TableName:          class.TableName,
+		DomainPath:         "/class",
+		CreateJsonBody:     &class.CreateJsonBody{},
+		DeleteQueryParams:  &class.DeletePathParams{},
+		UpdateJsonBody:     &class.UpdateJsonBody{},
+		QueryQueryParams:   &class.QueryQueryParams{},
+		GetByIDQueryParams: &class.GetByIDQueryParams{},
+	}, entity.WithUpdateTx[class.Info](), entity.WithDeleteTx[class.Info]())
+
+	go func() {
+		err := app.Start()
+		if err != nil {
+			panic(err)
+		}
+	}()
+
+	defer func() {
+		err := app.Finish()
+		if err != nil {
+			panic(err)
+		}
+	}()
+
+	death := DEATH.NewDeath(syscall.SIGINT, syscall.SIGTERM)
+	_ = death.WaitForDeath()
+}

+ 0 - 0
examples/quick_start/main.go → examples/examples/quick_start/main.go


+ 0 - 0
examples/sql_mapping_tag/main.go → examples/examples/sql_mapping_tag/main.go


+ 0 - 0
examples/sql_result_tag/main.go → examples/examples/sql_result_tag/main.go


+ 36 - 0
examples/examples/value_object/main.go

@@ -0,0 +1,36 @@
+package main
+
+import (
+	"git.sxidc.com/go-tools/utils/strutils"
+	"git.sxidc.com/service-supports/fserr"
+)
+
+type Configuration struct {
+	Group string `sqlmapping:"column:group;key;notUpdate;" sqlresult:"column:group;"`
+	Value string `sqlmapping:"column:value;notUpdate;" sqlresult:"column:value;"`
+}
+
+func (e *Configuration) DomainCNName() string {
+	return "配置"
+}
+
+func (e *Configuration) CheckKeyFields() error {
+	if strutils.IsStringEmpty(e.Group) {
+		return fserr.New("没有传递配置组")
+	}
+
+	return nil
+}
+
+type ConfigurationInfo struct {
+	Group string `sqlresult:"column:group;"`
+	Value string `sqlresult:"column:value;"`
+}
+
+const (
+	tableName = "test.configurations"
+)
+
+func main() {
+
+}

+ 0 - 0
examples/binding/resources.yaml → examples/resources.yaml