strategyGroup.go 3.4 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6
package strategy

import (
	"net/http"
	"strconv"

Y
Your Name 已提交
7 8
	goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"

黄孟柱 已提交
9 10
	"github.com/eolinker/goku-api-gateway/console/controller"
	"github.com/eolinker/goku-api-gateway/console/module/strategy"
E
eoLinker API Management 已提交
11 12
)

Y
Your Name 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
const operationStrategyGroup = "strategyManagement"

//GroupHandlers 策略分组处理器
type GroupHandlers struct {
}

//Handlers handlers
func (h *GroupHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
	return map[string]http.Handler{
		"/add":     factory.NewAccountHandleFunction(operationStrategyGroup, true, AddStrategyGroup),
		"/edit":    factory.NewAccountHandleFunction(operationStrategyGroup, true, EditStrategyGroup),
		"/delete":  factory.NewAccountHandleFunction(operationStrategyGroup, true, DeleteStrategyGroup),
		"/getList": factory.NewAccountHandleFunction(operationStrategyGroup, false, GetStrategyGroupList),
	}
}

//NewGroupHandlers new groupHandlers
func NewGroupHandlers() *GroupHandlers {
	return &GroupHandlers{}
}

E
eoLinker API Management 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
// AddStrategyGroup 新建接口分组
func AddStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {

	groupName := httpRequest.PostFormValue("groupName")
	if groupName == "" {
		controller.WriteError(httpResponse,
			"300002",
			"strategyGroup",
			"[ERROR]Illegal groupName!",
			nil)
		return
	}
	flag, result, err := strategy.AddStrategyGroup(groupName)
	if !flag {
		controller.WriteError(httpResponse,
			"300000",
			"strategyGroup",
			result.(string),
			err)
		return

	}
	controller.WriteResultInfo(httpResponse, "strategyGroup", "groupID", result)
}

// EditStrategyGroup 修改接口分组
func EditStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {

	groupName := httpRequest.PostFormValue("groupName")
	groupID := httpRequest.PostFormValue("groupID")
	if groupName == "" {
		controller.WriteError(httpResponse,
			"300002",
			"strategyGroup",
			"[ERROR]Illegal groupName!",
			nil)
		return

	}
	gID, err := strconv.Atoi(groupID)
	if err != nil {
		controller.WriteError(httpResponse,
			"300001",
			"strategyGroup",
			"[ERROR]Illegal groupID",
			err)
		return
	}
	flag, result, err := strategy.EditStrategyGroup(groupName, gID)
	if !flag {
		controller.WriteError(httpResponse,
			"300000",
			"strategyGroup",
			result,
			err)
		return

	}

	controller.WriteResultInfo(httpResponse, "strategyGroup", "", nil)

}

// DeleteStrategyGroup 删除接口分组
func DeleteStrategyGroup(httpResponse http.ResponseWriter, httpRequest *http.Request) {

	groupID := httpRequest.PostFormValue("groupID")

	gID, err := strconv.Atoi(groupID)
	if err != nil {
		controller.WriteError(httpResponse,
			"300001",
			"strategyGroup",
			"[ERROR]Illegal groupID",
			err)
		return
	}
	flag, result, err := strategy.DeleteStrategyGroup(gID)
	if !flag {

		controller.WriteError(httpResponse,
			"300000",
			"strategyGroup",
			result,
			err)
		return

	}
	controller.WriteResultInfo(httpResponse, "strategyGroup", "", nil)
}

// GetStrategyGroupList 获取接口分组列表
func GetStrategyGroupList(httpResponse http.ResponseWriter, httpRequest *http.Request) {

	flag, result, err := strategy.GetStrategyGroupList()
	if !flag {
		controller.WriteError(httpResponse,
			"300000",
			"strategyGroup",
			"[ERROR]Empty strategy group list!",
			err)
		return
	}

	controller.WriteResultInfo(httpResponse, "strategyGroup", "groupList", result)

	return

}