英文:
Golang | Handle duplicate declaration on import
问题
以下是要翻译的内容:
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)
在这里,关注这两个特定的库:
"github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/client"
它们都返回一个"client",我如何重写其中一个的名称并同时使用这两个库。
提前感谢!
英文:
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)
Here, focues on these 2 specific libs :
"github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/client"
both of them return a "client",
how can I override name of one of those 2 and use both the libraries at once.
Thanks in advance !
答案1
得分: 2
你可以通过以下方式为每个包命名:
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
hpclient "github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockerclient "github.com/docker/docker/client"
)
现在你可以在访问这些包时使用hpclient
或dockerclient
这些名称。你可以使用任何你感觉舒适的名称。
英文:
You can give a name to each package in the following way -
package main
import (
"context"
"encoding/json"
"fmt"
"io"
"os"
hpclient "github.com/HewlettPackard/docker/api/client"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
dockerclient "github.com/docker/docker/client"
)
Now you can use the names hpclient
or dockerclient
while accessing the packages. You can use any names which are comfortable for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论