better pool and changed schema
This commit is contained in:
parent
6d4e4c31f3
commit
249d7c6844
4 changed files with 82 additions and 21 deletions
47
pool.go
47
pool.go
|
|
@ -72,3 +72,50 @@ func (c *PoolClient) Delete(ctx context.Context, name string) (err error) {
|
|||
_, err = c.client.Do(req, nil)
|
||||
return
|
||||
}
|
||||
|
||||
type pool struct {
|
||||
members ServerList `json:"members"`
|
||||
}
|
||||
|
||||
func (c *PoolClient) List(ctx context.Context, name string) (sl ServerList, err error) {
|
||||
var p pool
|
||||
req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/pools/%s", name), nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.client.Do(req, &p)
|
||||
sl = p.members
|
||||
return
|
||||
}
|
||||
|
||||
func (c *PoolClient) FindServer(ctx context.Context, poolname, servername, id string) (s *Server, err error) {
|
||||
sl, err := c.List(ctx, poolname)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, srv := range sl {
|
||||
if id != "" && srv.ID == id {
|
||||
return srv, nil
|
||||
}
|
||||
if servername != "" && srv.Name == servername {
|
||||
return srv, nil
|
||||
}
|
||||
}
|
||||
return nil, ErrServerNotFound
|
||||
}
|
||||
|
||||
func (c *PoolClient) FindServerByName(ctx context.Context, poolname, servername string) (s *Server, err error) {
|
||||
return c.FindServer(ctx, poolname, servername, "")
|
||||
}
|
||||
|
||||
func (c *PoolClient) FindServerByID(ctx context.Context, poolname, id string) (s *Server, err error) {
|
||||
return c.FindServer(ctx, poolname, "", id)
|
||||
}
|
||||
|
||||
func (c *PoolClient) FindServerByURL(ctx context.Context, url string) (s *Server, err error) {
|
||||
pool, id, err := ParseURL(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return c.FindServerByID(ctx, pool, id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue