internal/ldap: use variadic options
This commit is contained in:
parent
3d431cbdf1
commit
b8cd3bb4bc
|
@ -3,15 +3,15 @@ package ldap
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
ldap "github.com/ps78674/ldapserver"
|
||||
)
|
||||
|
||||
// New returns a new ldap server instance
|
||||
func New(l hclog.Logger, nacl naClient) *server {
|
||||
func New(opts ...Option) *server {
|
||||
x := new(server)
|
||||
x.l = l.Named("ldap")
|
||||
x.c = nacl
|
||||
for _, o := range opts {
|
||||
o(x)
|
||||
}
|
||||
x.Server = ldap.NewServer()
|
||||
|
||||
x.routes = ldap.NewRouteMux()
|
||||
|
|
14
internal/ldap/option.go
Normal file
14
internal/ldap/option.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package ldap
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
// Option handle configuration of the underlying ldap.server type.
|
||||
type Option func(*server)
|
||||
|
||||
// WithLogger sets the loggers for the server.
|
||||
func WithLogger(l hclog.Logger) Option { return func(s *server) { s.l = l.Named("ldap") } }
|
||||
|
||||
// WithNetAuth sets the NetAuth client for the server.
|
||||
func WithNetAuth(n naClient) Option { return func(s *server) { s.c = n } }
|
4
main.go
4
main.go
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/netauth/ldap/internal/ldap"
|
||||
"github.com/netauth/netauth/pkg/netauth"
|
||||
"github.com/spf13/viper"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -62,7 +62,7 @@ func main() {
|
|||
os.Exit(2)
|
||||
}
|
||||
|
||||
ls := ldap.New(appLogger, nacl)
|
||||
ls := ldap.New(ldap.WithLogger(appLogger), ldap.WithNetAuth(nacl))
|
||||
|
||||
ls.SetDomain(viper.GetString("ldap.domain"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue