How to import and use different packages with the same name in Go?
Hello everyone! I'm new to Go and encountered a problem when importing packages. I have a project where I use two libraries: one for working with Redis (`github.com/go-redis/redis`) and another for working with REST API (`github.com/go-resty/resty`). Both export structures and functions under the names `redis` and `resty` respectively, but that's not the problem. The problem arose when I tried to use two different packages that have the same name, for example, `crypto/md5` and a third-party package `github.com/user/md5`.
I wrote this code:
```go
package main
import (
"crypto/md5"
"github.com/user/md5"
)
func main() {
h := md5.New()
// ...
}
```
The compiler gives an error: `md5 redeclared as imported package name`. I understand that Go does not allow importing two
No answers yet.
Log in to leave an answer
Blogs
WebSocket in C++: Building Real-Time Applications from Scratch
Top Mistakes of Beginner Rust Developers: Advanced Level
C++ in 2025: New Features and Code Examples in Practice
JavaScript for Machine Learning: Capabilities and Limitations in Practice