edit.go 1.4 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6
package discovery

import (
	"fmt"
	"net/http"

黄孟柱 已提交
7 8 9 10
	"github.com/eolinker/goku-api-gateway/common/auto-form"
	"github.com/eolinker/goku-api-gateway/console/controller"
	"github.com/eolinker/goku-api-gateway/console/module/service"
	driver2 "github.com/eolinker/goku-api-gateway/server/driver"
E
eoLinker API Management 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
)

func edit(w http.ResponseWriter, r *http.Request) {
	_, err := controller.CheckLogin(w, r, controller.OperationLoadBalance, controller.OperationEDIT)
	if err != nil {
		return
	}
	if err != r.ParseForm() {
		controller.WriteError(w, "260000", "serviceDiscovery", "[param_check] Parse form body error | 解析form表单参数错误", err)
		return
	}

	param := new(service.AddParam)
	err = auto.SetValues(r.PostForm, param)
	if err != nil {
		controller.WriteError(w, "260000", "data", fmt.Sprintf("[param_check] %s", err.Error()), err)
		return
	}

	d, has := driver2.Get(param.Driver)
	if !has {
		controller.WriteError(w, "260000", "data", fmt.Sprintf("[param_check] invalid  [driver]"), nil)
		return
	}

	if d.Type == driver2.Discovery {

		if param.Config == "" {
			controller.WriteError(w, "260000", "data", fmt.Sprintf("[param_check] invalid  [driver]"), nil)
			return
		}
	}

	err = service.Save(param)
	if err != nil {
		controller.WriteError(w, "260000", "data", fmt.Sprintf("[mysql]:%s", err.Error()), err)
		return
	}

	controller.WriteResultInfo(w, "serviceDiscovery", "data", nil)
}