You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.5 KiB
81 lines
1.5 KiB
2 years ago
|
package http
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"errors"
|
||
|
"git.diulo.com/mogfee/kit/registry"
|
||
|
"git.diulo.com/mogfee/kit/selector"
|
||
|
"net/url"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type Target struct {
|
||
|
Scheme string
|
||
|
Authority string
|
||
|
Endpoint string
|
||
|
}
|
||
|
|
||
|
func parseTarget(endpoint string, insecure bool) (*Target, error) {
|
||
|
if !strings.Contains(endpoint, "://") {
|
||
|
if insecure {
|
||
|
endpoint = "http://" + endpoint
|
||
|
} else {
|
||
|
endpoint = "https://" + endpoint
|
||
|
}
|
||
|
}
|
||
|
u, err := url.Parse(endpoint)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
target := &Target{
|
||
|
Scheme: u.Scheme,
|
||
|
Authority: u.Host,
|
||
|
Endpoint: "",
|
||
|
}
|
||
|
if len(u.Path) > 1 {
|
||
|
target.Endpoint = u.Path[1:]
|
||
|
}
|
||
|
return target, nil
|
||
|
}
|
||
|
|
||
|
type resolver struct {
|
||
|
rebalancer selector.Rebalancer
|
||
|
|
||
|
target *Target
|
||
|
watcher registry.Watcher
|
||
|
|
||
|
insecure bool
|
||
|
}
|
||
|
|
||
|
func newResolver(ctx context.Context, discovery registry.Discovery, target *Target, rebalancer selector.Rebalancer, block, insecure bool) (*resolver, error) {
|
||
|
//watcher, err := discovery.Watch(ctx, target.Endpoint)
|
||
|
//if err != nil {
|
||
|
// return nil, err
|
||
|
//}
|
||
|
//r := &resolver{
|
||
|
// rebalancer: rebalancer,
|
||
|
// target: target,
|
||
|
// watcher: watcher,
|
||
|
// insecure: insecure,
|
||
|
//}
|
||
|
//if block {
|
||
|
// done := make(chan error, 1)
|
||
|
// go func() {
|
||
|
// for {
|
||
|
// services, err := watcher.Next()
|
||
|
// if err != nil {
|
||
|
// done <- err
|
||
|
// return
|
||
|
// }
|
||
|
// }
|
||
|
// }()
|
||
|
//}
|
||
|
return nil, errors.New("un impl")
|
||
|
}
|
||
|
func (r *resolver) update() {
|
||
|
|
||
|
}
|
||
|
func (r *resolver) Close() error {
|
||
|
return r.watcher.Stop()
|
||
|
}
|