add web api

This commit is contained in:
ginuerzh
2022-02-08 23:46:54 +08:00
parent 0fba6d2500
commit f1eaef8d69
22 changed files with 1209 additions and 33 deletions

View File

@ -31,19 +31,28 @@ func (r *hostsRegistry) Unregister(name string) {
r.m.Delete(name)
}
func (r *hostsRegistry) IsRegistered(name string) bool {
_, ok := r.m.Load(name)
return ok
}
func (r *hostsRegistry) Get(name string) hosts.HostMapper {
if _, ok := r.m.Load(name); !ok {
return nil
}
return &hostsWrapper{name: name}
}
func (r *hostsRegistry) get(name string) hosts.HostMapper {
if v, ok := r.m.Load(name); ok {
return v.(hosts.HostMapper)
}
return nil
}
type hostsWrapper struct {
name string
}
func (w *hostsWrapper) Lookup(network, host string) ([]net.IP, bool) {
v := Hosts().Get(w.name)
v := Hosts().get(w.name)
if v == nil {
return nil, false
}