test_router.go 1.6 KB
package routers

import (
	"github.com/beego/beego/v2/server/web"
	"github.com/beego/beego/v2/server/web/context"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers"
	"net/http"
	"strconv"
	"strings"
)

func init() {
	web.Router("/TestController/PullMaterialNewest", &controllers.TestController{}, "Get:InvokPullMaterialNewest")
	web.Router("/TestController/PullMaterialGroup", &controllers.TestController{}, "Get:InvokPullMaterialGroup")
	web.Router("/TestController/InvokPullPrdMoNewest", &controllers.TestController{}, "Get:InvokPullPrdMoNewest")

	web.Router("/test/create-device-collection", &controllers.TestController{}, "Post:CreateDeviceCollection")
	web.Get("/test/cache-key/:key", func(ctx *context.Context) {
		key := ctx.Input.Query(":key")
		if len(key) != 0 {
			keys, _ := redis.GetRedis().Keys(key).Result()
			ctx.Output.SetStatus(http.StatusOK)
			ctx.Output.JSON(keys, false, false)
		}
	})
	web.Get("/test/cache/:key", func(ctx *context.Context) {
		key := ctx.Input.Query(":key")
		if len(key) != 0 {
			value, _ := redis.GetRedis().Get(key).Result()
			ctx.Output.SetStatus(http.StatusOK)
			ctx.Output.Body([]byte(value))
		}
	})
	web.Get("/test/cache/d/:key", func(ctx *context.Context) {
		key := ctx.Input.Query(":key")
		if len(key) != 0 && !strings.Contains(key, "*") {
			value, _ := redis.GetRedis().Del(key).Result()
			ctx.Output.SetStatus(http.StatusOK)
			ctx.Output.Body([]byte(strconv.Itoa(int(value))))
		}
	})
}