MCPcopy Create free account
hub / github.com/algolia/cli / searchClient

Function searchClient

pkg/cmd/factory/default.go:37–73  ·  view source on GitHub ↗
(f *cmdutil.Factory, appVersion string)

Source from the content-addressed store, hash-verified

35}
36
37func searchClient(f *cmdutil.Factory, appVersion string) func() (*search.APIClient, error) {
38 return func() (*search.APIClient, error) {
39 appID, err := f.Config.Profile().GetApplicationID()
40 if err != nil {
41 return nil, err
42 }
43 apiKey, err := f.Config.Profile().GetAPIKey()
44 if err != nil {
45 return nil, err
46 }
47
48 userAgent, err := getUserAgentInfo(appID, apiKey, appVersion)
49 if err != nil {
50 return nil, err
51 }
52 if userAgent == "" {
53 return nil, fmt.Errorf("user agent must not be empty")
54 }
55
56 clientConf := search.SearchConfiguration{
57 Configuration: transport.Configuration{
58 AppID: appID,
59 ApiKey: apiKey,
60 UserAgent: userAgent,
61 ExposeIntermediateNetworkErrors: true,
62 },
63 }
64
65 // Read custom hosts from flags, environment, or profile, or use default ones
66 hosts := GetStatefulHosts(f.Config.Profile().GetSearchHosts())
67 if len(hosts) > 0 {
68 clientConf.Configuration.Hosts = hosts
69 }
70
71 return search.NewClientWithConfig(clientConf)
72 }
73}
74
75func crawlerClient(f *cmdutil.Factory) func() (*crawler.Client, error) {
76 return func() (*crawler.Client, error) {

Callers 1

NewFunction · 0.85

Calls 7

GetStatefulHostsFunction · 0.85
GetApplicationIDMethod · 0.80
GetSearchHostsMethod · 0.80
getUserAgentInfoFunction · 0.70
ProfileMethod · 0.65
GetAPIKeyMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected