// {"Type": "http", "BackendId": "$identifier", "Route": "Host(`$identifier.$base_domain`) && PathRegexp(`/`)", "Settings": {"TrustForwardHeader": true}} func setFrontend(etcd *store.Etcd, projectName, identifier, baseDomain string) error { key := fmt.Sprintf("%s/frontends/%s/frontend", vulcandKeyBase, identifier) frontend := Frontend{ Type: "http", BackendId: projectName, Route: fmt.Sprintf("Host(`%s.%s`) && PathRegexp(`/`)", strings.ToLower(identifier), strings.ToLower(baseDomain)), Settings: FrontendSettings{ TrustForwardHeader: true, }, } b, err := json.Marshal(frontend) if err != nil { return errors.Wrap(err, "Failed to generate vulcand frontend JSON.") } // json.Marshal generates HTML-escaped JSON string b = bytes.Replace(b, []byte("\\u0026"), []byte("&"), -1) json := string(b) if err := etcd.Set(key, json); err != nil { return err } return nil }
// {"Type": "http"} func setBackend(etcd *store.Etcd, projectName string) error { key := fmt.Sprintf("%s/backends/%s/backend", vulcandKeyBase, projectName) if err := etcd.Set(key, httpBackendJSON); err != nil { return err } return nil }
// {"URL": "http://$web_container_host_ip:$web_container_port"} func setServer(etcd *store.Etcd, projectName string, container *model.Container, baseDomain string) error { key := fmt.Sprintf("%s/backends/%s/servers/%s", vulcandKeyBase, projectName, container.ContainerId) server := Server{ URL: fmt.Sprintf("http://%s:%s", container.HostIP(), container.HostPort()), } b, err := json.Marshal(server) if err != nil { return errors.Wrap(err, "Failed to generate vulcand server JSON.") } json := string(b) if err := etcd.Set(key, json); err != nil { return err } return nil }