-1
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 !

Keval Bhogayata
  • 4,422
  • 3
  • 13
  • 36
  • 3
    You can specify a "local" package name in the import declaration, e.g. `dc "github.com/docker/docker/client"` and then you would reference that package as `dc`. See: https://golang.org/ref/spec#Import_declarations – mkopriva Sep 07 '21 at 12:24

1 Answers1

2

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.

aniztar
  • 2,443
  • 4
  • 18
  • 24