func createReadClient(m *medium) (readClient, error) { // no output, no client if m == nil { return nil, nil } switch m.typ { case innkeeper: return createInnkeeperClient(m) case etcd: return etcdclient.New(etcdclient.Options{ Endpoints: urlsToStrings(m.urls), Prefix: m.path, Insecure: insecure}) case stdin: return &stdinReader{reader: os.Stdin}, nil case file: return eskipfile.Open(m.path) case inline: return &inlineReader{routes: m.eskip}, nil case inlineIds: return &idsReader{ids: m.ids}, nil default: return nil, invalidInputType } }
func createDataClients(o Options, auth innkeeper.Authentication) ([]routing.DataClient, error) { var clients []routing.DataClient if o.RoutesFile != "" { f, err := eskipfile.Open(o.RoutesFile) if err != nil { return nil, err } clients = append(clients, f) } if o.InnkeeperUrl != "" { ic, err := innkeeper.New(innkeeper.Options{ o.InnkeeperUrl, o.ProxyOptions.Insecure(), auth, o.InnkeeperPreRouteFilters, o.InnkeeperPostRouteFilters}) if err != nil { return nil, err } clients = append(clients, ic) } if len(o.EtcdUrls) > 0 { clients = append(clients, etcd.New(o.EtcdUrls, o.EtcdPrefix)) } return clients, nil }
func Example() { // create etcd data client: dataClient := etcd.New([]string{"https://etcd.example.org"}, "/skipper") // create http.Handler: proxy.New( routing.New(routing.Options{ FilterRegistry: builtin.MakeRegistry(), DataClients: []routing.DataClient{dataClient}}), proxy.OptionsNone) }
// insert/update all routes to a medium (currently only etcd). func upsertAll(routes routeList, m *medium) error { client := etcdclient.New(urlsToStrings(m.urls), m.path) for _, r := range routes { ensureId(r) err := client.Upsert(r) if err != nil { return err } } return nil }
func Example() { // create etcd data client: dataClient, err := etcd.New(etcd.Options{[]string{"https://etcd.example.org"}, "/skipper", 0}) if err != nil { log.Fatal(err) } // create http.Handler: proxy.New( routing.New(routing.Options{ FilterRegistry: builtin.MakeRegistry(), DataClients: []routing.DataClient{dataClient}}), proxy.OptionsNone) }
func createWriteClient(out *medium) (writeClient, error) { // no output, no client if out == nil { return nil, nil } switch out.typ { case innkeeper: return createInnkeeperClient(out) case etcd: return etcdclient.New(etcdclient.Options{Endpoints: urlsToStrings(out.urls), Prefix: out.path}) } return nil, invalidOutput }
// delete all items in 'routes' that fulfil 'cond'. func deleteAllIf(routes routeList, m *medium, cond routePredicate) error { client := etcdclient.New(urlsToStrings(m.urls), m.path) for _, r := range routes { if !cond(r) { continue } err := client.Delete(r.Id) if err != nil { return err } } return nil }
func createDataClients(o Options, auth innkeeper.Authentication) ([]routing.DataClient, error) { var clients []routing.DataClient if o.RoutesFile != "" { f, err := eskipfile.Open(o.RoutesFile) if err != nil { log.Error(err) return nil, err } clients = append(clients, f) } if o.InnkeeperUrl != "" { ic, err := innkeeper.New(innkeeper.Options{ o.InnkeeperUrl, o.InnkeeperInsecure, auth, o.InnkeeperPreRouteFilters, o.InnkeeperPostRouteFilters}) if err != nil { log.Error(err) return nil, err } clients = append(clients, ic) } if len(o.EtcdUrls) > 0 { etcdClient, err := etcd.New(etcd.Options{ o.EtcdUrls, o.EtcdPrefix, o.EtcdWaitTimeout, o.EtcdInsecure}) if err != nil { return nil, err } clients = append(clients, etcdClient) } if o.KubernetesURL != "" { clients = append(clients, kubernetes.New(kubernetes.Options{ KubernetesURL: o.KubernetesURL, ProvideHealthcheck: o.KubernetesHealthcheck, })) } return clients, nil }
func Example() { // create etcd data client: dataClient, err := etcd.New(etcd.Options{[]string{"https://etcd.example.org"}, "/skipper", 0, false}) if err != nil { log.Fatal(err) } // create routing object: rt := routing.New(routing.Options{ FilterRegistry: builtin.MakeRegistry(), DataClients: []routing.DataClient{dataClient}}) defer rt.Close() // create http.Handler: p := proxy.New(rt, proxy.OptionsNone) defer p.Close() }
// load and parse routes from etcd. func loadEtcd(urls []*url.URL, prefix string) (loadResult, error) { client := etcdclient.New(urlsToStrings(urls), prefix) info, err := client.LoadAndParseAll() return mapRouteInfo(info), err }