Przeglądaj źródła

完成网关增删改查demo

yjp 1 rok temu
rodzic
commit
1dee00f345

+ 13 - 0
project/gateway/api/root/demo_server/configuration.go

@@ -0,0 +1,13 @@
+package demo_server
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
+
+func configurationService(builder *gateway.Builder) {
+	gwtools.CRUD(builder, &gwtools.CommonCRUDParams{
+		ServiceVersionedUrl: baseUrl,
+		DomainCamelName:     "Configuration",
+	}, gwtools.WithDisableUpdate())
+}

+ 5 - 2
project/gateway/api/root/demo_server/demo_server.go

@@ -1,11 +1,14 @@
 package demo_server
 
-import "git.sxidc.com/go-framework/baize/framework/gateway"
+import (
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
 
 const (
 	baseUrl = "http://localhost:31000/example/api"
 )
 
 func InitRouter(builder *gateway.Builder) {
-	version(builder)
+	versionService(builder)
+	configurationService(builder)
 }

+ 7 - 7
project/gateway/api/root/demo_server/version.go

@@ -1,19 +1,19 @@
 package demo_server
 
 import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
-	"net/http"
 )
 
 const (
 	versionBaseUrl = baseUrl + "/version"
 )
 
-func version(builder *gateway.Builder) {
-	builder.
-		Url(http.MethodGet, "/version").
-		Get(&gateway.GetRequest{
+func versionService(builder *gateway.Builder) {
+	gwtools.GetPassThrough(builder, &gwtools.SimplePassThroughParams{
+		RelativePath: "/version",
+		Request: &gateway.GetRequest{
 			Url: versionBaseUrl,
-		}, nil).
-		Build()
+		},
+	})
 }

+ 13 - 0
project/gateway/api/v1/demo_server/class.go

@@ -0,0 +1,13 @@
+package demo_server
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
+
+func classService(builder *gateway.Builder) {
+	gwtools.CRUD(builder, &gwtools.CommonCRUDParams{
+		ServiceVersionedUrl: baseUrl,
+		DomainCamelName:     "Class",
+	})
+}

+ 11 - 2
project/gateway/api/v1/demo_server/demo_server.go

@@ -1,7 +1,16 @@
 package demo_server
 
-import "git.sxidc.com/go-framework/baize/framework/gateway"
+import (
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
 
-func InitRouter(builder *gateway.Builder) {
+const (
+	baseUrl = "http://localhost:31000/example/api/v1"
+)
 
+func InitRouter(builder *gateway.Builder) {
+	classService(builder)
+	studentService(builder)
+	familyService(builder)
+	identityService(builder)
 }

+ 13 - 0
project/gateway/api/v1/demo_server/family.go

@@ -0,0 +1,13 @@
+package demo_server
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
+
+func familyService(builder *gateway.Builder) {
+	gwtools.CRUD(builder, &gwtools.CommonCRUDParams{
+		ServiceVersionedUrl: baseUrl,
+		DomainCamelName:     "Family",
+	})
+}

+ 13 - 0
project/gateway/api/v1/demo_server/identity.go

@@ -0,0 +1,13 @@
+package demo_server
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
+
+func identityService(builder *gateway.Builder) {
+	gwtools.CRUD(builder, &gwtools.CommonCRUDParams{
+		ServiceVersionedUrl: baseUrl,
+		DomainCamelName:     "Identity",
+	})
+}

+ 13 - 0
project/gateway/api/v1/demo_server/student.go

@@ -0,0 +1,13 @@
+package demo_server
+
+import (
+	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+)
+
+func studentService(builder *gateway.Builder) {
+	gwtools.CRUD(builder, &gwtools.CommonCRUDParams{
+		ServiceVersionedUrl: baseUrl,
+		DomainCamelName:     "Student",
+	})
+}

+ 1 - 1
project/gateway/api/v1/v1.go

@@ -9,6 +9,6 @@ import (
 type Router struct{}
 
 func (router *Router) Init(gw *gateway.Gateway) {
-	builder := gw.NewBuilder(api.RouterPrefix, "")
+	builder := gw.NewBuilder(api.RouterPrefix, "v1")
 	demo_server.InitRouter(builder)
 }

+ 33 - 0
project/gateway/main.go

@@ -9,6 +9,39 @@ import (
 // Version
 // curl -X GET "http://localhost:32000/gateway/api/version"
 
+// Configuration
+// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test", "value":"test-value"}' "http://localhost:32000/gateway/api/configuration/create"
+// curl -X GET "http://localhost:32000/gateway/api/configuration/values?scope=global&group=test&pageNo=1&pageSize=1"
+// curl -X POST -H "Content-Type: application/json" -d '{"scope": "global", "group":"test"}' "http://localhost:32000/gateway/api/configuration/delete"
+
+// Class
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "studentNum": 10}' "http://localhost:32000/gateway/api/v1/class/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"a58aec380ac243aea4e9a47bca4964e5", "name":"test-new"}' "http://localhost:32000/gateway/api/v1/class/update"
+// curl -X GET "http://localhost:32000/gateway/api/v1/class/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:32000/gateway/api/v1/class/get?id=a58aec380ac243aea4e9a47bca4964e5"
+// curl -X DELETE "http://localhost:32000/gateway/api/v1/class/delete?id=a58aec380ac243aea4e9a47bca4964e5"
+
+// Student
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:32000/gateway/api/v1/student/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"bdd469c05e244b5b91b17295a8dd221f", "name":"test-new"}' "http://localhost:32000/gateway/api/v1/student/update"
+// curl -X GET "http://localhost:32000/gateway/api/v1/student/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:32000/gateway/api/v1/student/get?id=bdd469c05e244b5b91b17295a8dd221f"
+// curl -X DELETE "http://localhost:32000/gateway/api/v1/student/delete?id=bdd469c05e244b5b91b17295a8dd221f"
+
+// Family
+// curl -X POST -H "Content-Type: application/json" -d '{"father":"father", "mother": "mother"}' "http://localhost:32000/gateway/api/v1/family/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"094cb5b08a244163b0ccf02d45c07025", "father":"new-father", "mother": "new-mother"}' "http://localhost:32000/gateway/api/v1/family/update"
+// curl -X GET "http://localhost:32000/gateway/api/v1/family/query?father=new-father&pageNo=0&pageSize=0"
+// curl -X GET "http://localhost:32000/gateway/api/v1/family/get?id=094cb5b08a244163b0ccf02d45c07025"
+// curl -X DELETE "http://localhost:32000/gateway/api/v1/family/delete?id=094cb5b08a244163b0ccf02d45c07025"
+
+// Identity
+// curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' "http://localhost:32000/gateway/api/v1/identity/create"
+// curl -X PUT -H "Content-Type: application/json" -d '{"id":"cc591981a91c412a9e20be5eec683121", "name":"test-new"}' "http://localhost:32000/gateway/api/v1/identity/update"
+// curl -X GET "http://localhost:32000/gateway/api/v1/identity/query?name=test-new&pageNo=1&pageSize=1"
+// curl -X GET "http://localhost:32000/gateway/api/v1/identity/get?id=cc591981a91c412a9e20be5eec683121"
+// curl -X DELETE "http://localhost:32000/gateway/api/v1/identity/delete?id=cc591981a91c412a9e20be5eec683121"
+
 func main() {
 	api.NewGateway()
 	defer api.DestroyGateway()