Golang Docker API在击中ImageBuild时报告无效参数

I have the following code to build an image from a .tar file that contains a Dockerfile.

os.MkdirAll("configs/container",0755)
tar := new(archivex.TarFile)
tar.Create("configs/container/conf.tar")
tar.AddAll("configs/configdir", false)
tar.Close()

dockerBuildContext, err := os.Open("config/dns/conf.tar")
defer dockerBuildContext.Close()


buildOptions := types.ImageBuildOptions{
        Context:    dockerBuildContext,
        CPUSetCPUs:   "2",
        CPUSetMems:   "12",
        CPUShares:    20,
        CPUQuota:     10,
        CPUPeriod:    30,
        Memory:       256,
        MemorySwap:   512,
        ShmSize:      10,
        CgroupParent: "cgroup_parent",
        Dockerfile:   "Dockerfile", // optional, is the default
        Tags:   []string{"coolimage"},
    }

cli, err := client.NewEnvClient()

buildResponse, err := cli.ImageBuild(context.Background(), dockerBuildContext, buildOptions)
if err != nil {
        log.Printf("%s", err.Error())
}
if err != nil { 
    log.Fatal(err)
}
response, err := ioutil.ReadAll(buildResponse.Body) 
log.Printf(string(response))

defer buildResponse.Body.Close()

However, this is returning the following error:

2017/10/22 13:57:42 error during connect: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.34/build?buildargs=null&cachefrom=null&cgroupparent=cgroup_parent&cpuperiod=30&cpuquota=10&cpusetcpus=2&cpusetmems=12&cpushares=20&dockerfile=Dockerfile&labels=null&memory=256&memswap=512&networkmode=&rm=0&shmsize=10&t=dnsimage&target=&ulimits=null: invalid argument

I tried to remove all BuildOptions and only leave the "Dockerfile" option but same error still appears. I always get invalid argument.

I tried all ways showed on this question

I am running Docker on Mac but I also tried in an EC2 instance running CentOS and got the same result.

Client:
Version:         1.12.6
API version:     1.24
Package version: docker-1.12.6-55.gitc4618fb.el7.centos.x86_64
Go version:      go1.8.3
Git commit:      c4618fb/1.12.6
Built:           Thu Sep 21 22:33:52 2017
OS/Arch:         linux/amd64

Server:
Version:         1.12.6
API version:     1.24
Package version: docker-1.12.6-55.gitc4618fb.el7.centos.x86_64
Go version:      go1.8.3
Git commit:      c4618fb/1.12.6
Built:           Thu Sep 21 22:33:52 2017
OS/Arch:         linux/amd64

No errors appear on docker.log or journalctl I also tried with both github.com/docker/docker/client and github.com/moby/moby/client