37 lines
999 B
Go
37 lines
999 B
Go
package aiagent
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/identity"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/bootstrap"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/services"
|
|
)
|
|
|
|
type Options struct {
|
|
ConfigPath string
|
|
QuerySubjects identity.QuerySubjectsFunc
|
|
Authorize identity.AuthorizeFunc
|
|
}
|
|
|
|
// New initializes the customer-service business module. Authentication and
|
|
// authorization must already have been completed by the host system.
|
|
func New(options Options) (http.Handler, error) {
|
|
if options.QuerySubjects == nil {
|
|
return nil, errors.New("ai-agent: QuerySubjects is required")
|
|
}
|
|
if options.Authorize == nil {
|
|
return nil, errors.New("ai-agent: Authorize is required")
|
|
}
|
|
if options.ConfigPath == "" {
|
|
options.ConfigPath = "config/config.yaml"
|
|
}
|
|
services.SetQuerySubjects(options.QuerySubjects)
|
|
services.SetAuthorize(options.Authorize)
|
|
if err := bootstrap.Init(options.ConfigPath); err != nil {
|
|
return nil, err
|
|
}
|
|
return bootstrap.NewServer()
|
|
}
|