示例#1
0
文件: server.go 项目: nanopack/portal
func srvValidate(server *core.Server) {
	if server.Id == "" {
		server.GenId()
		if server.Host == "" || int(server.Port) == 0 {
			fail("Must enter host and port combo or id of server")
		}
	}
}
示例#2
0
func marshalSrv(server []byte) (*core.Server, error) {
	var srv core.Server

	if err := json.Unmarshal(server, &srv); err != nil {
		return nil, BadJson
	}

	srv.GenId()
	if srv.Id == "-0" {
		return nil, NoServerError
	}

	return &srv, nil
}
示例#3
0
文件: server.go 项目: nanopack/portal
func parseReqServer(req *http.Request) (*core.Server, error) {
	b, err := ioutil.ReadAll(req.Body)
	if err != nil {
		config.Log.Error(err.Error())
		return nil, BodyReadFail
	}

	var srv core.Server

	if err := json.Unmarshal(b, &srv); err != nil {
		return nil, BadJson
	}

	srv.GenId()
	if srv.Id == "-0" {
		return nil, NoServerError
	}

	config.Log.Trace("SERVER: %+v", srv)
	return &srv, nil
}
示例#4
0
文件: lvs.go 项目: nanopack/portal
// conversion functions
// takes a lvs.Server and converts it to a core.Server
func lToSrv(server lvs.Server) core.Server {
	srv := core.Server{Host: server.Host, Port: server.Port, Forwarder: server.Forwarder, Weight: server.Weight, UpperThreshold: server.UpperThreshold, LowerThreshold: server.LowerThreshold}
	srv.GenId()
	return srv
}