func NewBackend(cfg *Config, logger *zap.Logger) (*Backend, error) {
	if logger == nil {
		return nil, errors.ErrBackendConfigureLoggerNotFound
	}
	if err := cfg.validate(); err != nil {
		return nil, err
	}
	b := &Backend{
		Method: cfg.authMethod,
		logger: logger,
	}
	switch cfg.authMethod {
	case Local:
		b.driver = local.NewDatabaseBackend(cfg.Local, logger)
	case Ldap:
		b.driver = ldap.NewDatabaseBackend(cfg.Ldap, logger)
	case Saml:
		b.driver = saml.NewDatabaseBackend(cfg.Saml, logger)
	case OAuth2:
		b.driver = oauth2.NewDatabaseBackend(cfg.OAuth2, logger)
	}
	return b, nil
}
NewBackend returns Backend instance.
package backends
import (
	"encoding/json"
	"fmt"
	"github.com/greenpau/caddy-auth-portal/pkg/backends/ldap"
	"github.com/greenpau/caddy-auth-portal/pkg/backends/local"
	"github.com/greenpau/caddy-auth-portal/pkg/backends/oauth2"
	"github.com/greenpau/caddy-auth-portal/pkg/backends/saml"
	"github.com/greenpau/caddy-auth-portal/pkg/enums/operator"
	"github.com/greenpau/caddy-auth-portal/pkg/errors"
	"github.com/greenpau/go-identity/pkg/requests"
	"go.uber.org/zap"
)
type AuthMethodType int
const (
	Unknown AuthMethodType = iota
	Local
	Ldap
	Saml
	OAuth2
)
type Config struct {
	Local      *local.Config  `json:"local,omitempty" xml:"local" yaml:"local,omitempty"`
	Ldap       *ldap.Config   `json:"ldap,omitempty" xml:"ldap" yaml:"ldap,omitempty"`
	Saml       *saml.Config   `json:"saml,omitempty" xml:"saml" yaml:"saml,omitempty"`
	OAuth2     *oauth2.Config `json:"oauth2,omitempty" xml:"oauth2" yaml:"oauth2,omitempty"`
	authMethod AuthMethodType
}
type Backend struct {
	Method AuthMethodType
	driver BackendDriver
	logger *zap.Logger
}
type BackendDriver interface {
	GetRealm() string
	GetName() string
	GetMethod() string
	GetConfig() string
	Configure() error
	Validate() error
	Request(operator.Type, *requests.Request) error
}
func (b *Backend) GetRealm() string {
	return b.driver.GetRealm()
}
func (b *Backend) GetName() string {
	return b.driver.GetName()
}
func (b *Backend) GetMethod() string {
	return b.driver.GetMethod()
}
func (b *Backend) GetConfig() string {
	return b.driver.GetConfig()
}
func (b *Backend) Configure() error {
	return b.driver.Configure()
}
func (b *Backend) Request(op operator.Type, r *requests.Request) error {
	return b.driver.Request(op, r)
}
func (b *Backend) Validate() error {
	return b.driver.Validate()
}