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

import (
	"fmt"
黄孟柱 已提交
5 6 7 8
	"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"
Y
Your Name 已提交
9
	"net/http"
E
eoLinker API Management 已提交
10 11 12
)

func edit(w http.ResponseWriter, r *http.Request) {
Y
Your Name 已提交
13 14

	if err := r.ParseForm() ; err!= nil{
E
eoLinker API Management 已提交
15 16 17 18 19
		controller.WriteError(w, "260000", "serviceDiscovery", "[param_check] Parse form body error | 解析form表单参数错误", err)
		return
	}

	param := new(service.AddParam)
Y
Your Name 已提交
20
	err := auto.SetValues(r.PostForm, param)
E
eoLinker API Management 已提交
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
	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)
}