This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
nginx-ldap-auth/group/service.go
Tiago Augusto Pimenta bdce35bc55 Refactor
2018-10-09 20:59:52 -03:00

40 lines
615 B
Go

package group
import (
"strings"
"github.com/tiagoapimenta/nginx-ldap-auth/ldap"
)
type Service struct {
pool *ldap.Pool
base string
filter string
attr string
}
func NewService(pool *ldap.Pool, base, filter, attr string) *Service {
return &Service{
pool: pool,
base: base,
filter: filter,
attr: attr,
}
}
func (p *Service) Find(id string) ([]string, error) {
ok, _, groups, err := p.pool.Search(
p.base,
strings.Replace(p.filter, "{0}", id, -1),
p.attr,
)
if !ok && err != nil {
return nil, err
} else if err != nil {
return []string{}, nil
}
return groups, nil
}