How to use ImageSearch by go sdk?

I use go sdk to search image as follow:

    ctx    = context.Background()
    cli, _ = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    items, _ := cli.ImageSearch(ctx, "mysql", types.ImageSearchOptions{})

but items is nil
why?

Here is a working example:

package main

import (
	"context"
	"fmt"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	"log"
)

func main() {
	ctx := context.Background()
	cli, _ := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
	items, err := cli.ImageSearch(ctx, "mysql", types.ImageSearchOptions{Limit: 10})

	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Length: %d", len(items))
	for key, item := range items {
		fmt.Println(key, item.Name)
	}

}

I used a slightly different syntax, but the problem was that you didn’t define any limit. Since you also ignored the returned error message, you just saw that the list was empty. I included a little error handling in my example. Try to remove the limit from ImageSearchOptions and you will see something like this:

Error response from daemon: Limit 0 is outside the range of [1, 100]