func (n *ng) GetServer(sk engine.ServerKey) (*engine.Server, error) { bytes, err := n.getVal(n.path("backends", sk.BackendKey.Id, "servers", sk.Id)) if err != nil { return nil, err } return engine.ServerFromJSON([]byte(bytes), sk.Id) }
func (c *Client) GetServer(sk engine.ServerKey) (*engine.Server, error) { data, err := c.Get(c.endpoint("backends", sk.BackendKey.Id, "servers", sk.Id), url.Values{}) if err != nil { return nil, err } return engine.ServerFromJSON(data) }
func (n *ng) parseBackends(node *etcd.Node, skipServers ...bool) ([]engine.BackendSpec, error) { backendSpecs := make([]engine.BackendSpec, len(node.Nodes)) for idx, node := range node.Nodes { backendId := suffix(node.Key) for _, node := range node.Nodes { switch suffix(node.Key) { case "backend": backend, err := engine.BackendFromJSON([]byte(node.Value), backendId) if err != nil { return nil, err } backendSpecs[idx].Backend = *backend case "servers": if len(skipServers) == 1 && skipServers[0] { break } servers := make([]engine.Server, len(node.Nodes)) for idx, node := range node.Nodes { serverId := suffix(node.Key) server, err := engine.ServerFromJSON([]byte(node.Value), serverId) if err != nil { return nil, err } servers[idx] = *server } backendSpecs[idx].Servers = servers } } if backendSpecs[idx].Backend.Id != backendId { return nil, fmt.Errorf("Backend %s parameters missing", backendId) } } return backendSpecs, nil }
func parseServerPack(v []byte) (*engine.Server, time.Duration, error) { var sp serverReadPack if err := json.Unmarshal(v, &sp); err != nil { return nil, 0, err } if len(sp.Server) == 0 { return nil, 0, &scroll.MissingFieldError{Field: "Server"} } s, err := engine.ServerFromJSON(sp.Server) if err != nil { return nil, 0, err } var ttl time.Duration if sp.TTL != "" { ttl, err = time.ParseDuration(sp.TTL) if err != nil { return nil, 0, err } } return s, ttl, nil }
func (n *ng) parseBackends(keyValues []*mvccpb.KeyValue, skipServers ...bool) ([]engine.BackendSpec, error) { backendSpecs := []engine.BackendSpec{} for _, keyValue := range keyValues { if backendIds := backendIdRegex.FindStringSubmatch(string(keyValue.Key)); len(backendIds) == 2 { backendId := backendIds[1] backend, err := engine.BackendFromJSON([]byte(keyValue.Value), backendId) if err != nil { return nil, err } backendSpec := engine.BackendSpec{ Backend: *backend, } if len(skipServers) != 1 || !skipServers[0] { //get all keys under this frontend subKeyValues := filterByPrefix(keyValues, string(keyValue.Key)) //Get all keys below this frontend "/vulcand/frontends/foo/*" servers := []engine.Server{} for _, subKeyValue := range subKeyValues { if serverId := suffix(string(subKeyValue.Key)); suffix(prefix(string(subKeyValue.Key))) == "servers" { server, err := engine.ServerFromJSON([]byte(subKeyValue.Value), serverId) if err != nil { return nil, err } servers = append(servers, *server) } } backendSpec.Servers = servers } backendSpecs = append(backendSpecs, backendSpec) } } return backendSpecs, nil }