Skip to content

Commit 162c442

Browse files
committed
[searcher] Add SearchOption and handle host error
1 parent d39e72b commit 162c442

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

internal/searcher/client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ var cachedClient *client
3131

3232
func Client() *client {
3333
if cachedClient == nil {
34-
endpoint, _ := url.JoinPath(searchHost(), "search")
35-
// TODO: how to handle error
34+
endpoint, err := url.JoinPath(searchHost(), "search")
35+
if err != nil {
36+
// TODO: better handle this error when users use invalid custom hosts
37+
panic(err)
38+
}
3639
cachedClient = &client{
3740
endpoint: endpoint,
3841
}
3942
}
4043
return cachedClient
4144
}
4245

43-
func (c *client) Search(query string, options ...func() string) (*SearchResult, error) {
46+
func (c *client) Search(query string, options ...SearchOption) (*SearchResult, error) {
4447
if query == "" {
4548
return nil, fmt.Errorf("query should not be empty")
4649
}
@@ -54,7 +57,10 @@ func (c *client) Search(query string, options ...func() string) (*SearchResult,
5457
return execSearch(searchURL)
5558
}
5659

57-
func WithVersion(version string) func() string {
60+
// SearchOption returns a string for query to be appended to the endpoint
61+
type SearchOption func() string
62+
63+
func WithVersion(version string) SearchOption {
5864
return func() string {
5965
return "&v=" + url.QueryEscape(version)
6066
}

0 commit comments

Comments
 (0)