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") } } }
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 }
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 }
// 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 }