Esempio n. 1
0
// takes a lvs.Service and converts it to a core.Service
func lToSvc(service lvs.Service) core.Service {
	srvs := []core.Server{}
	for i, srv := range service.Servers {
		srvs = append(srvs, lToSrv(srv))
		srvs[i].GenId()
	}
	svc := core.Service{Host: service.Host, Port: service.Port, Type: service.Type, Scheduler: service.Scheduler, Persistence: service.Persistence, Netmask: service.Netmask, Servers: srvs}
	svc.GenId()
	return svc
}
Esempio n. 2
0
func parseReqService(req *http.Request) (*core.Service, error) {
	b, err := ioutil.ReadAll(req.Body)
	if err != nil {
		config.Log.Error(err.Error())
		return nil, BodyReadFail
	}

	var svc core.Service

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

	if svc.Interface != "" {
		err = svc.GenHost()
		if err != nil {
			return nil, err
		}
	}

	svc.GenId()
	if svc.Id == "--0" {
		return nil, NoServiceError
	}

	err = checkPort(svc)
	if err != nil {
		return nil, err
	}

	for i := range svc.Servers {
		svc.Servers[i].GenId()

		// localhost doesn't work properly, use service.Host
		if svc.Servers[i].Host == "127.0.0.1" {
			svc.Servers[i].GenHost(svc.Id)
		}
	}

	config.Log.Trace("SERVICE: %+v", svc)
	return &svc, nil
}
Esempio n. 3
0
func marshalSvc(service []byte) (*core.Service, error) {
	var svc core.Service

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

	svc.GenId()
	if svc.Id == "--0" {
		return nil, NoServiceError
	}

	for i := range svc.Servers {
		svc.Servers[i].GenId()
		if svc.Servers[i].Id == "-0" {
			return nil, NoServerError
		}
	}
	return &svc, nil
}