Using Fileserver to share files

Asked

Viewed 65 times

1

I am learning Golang and to practice I am doing some small "projects", my idea is just to share a folder of my Windows or some file through my local wifi network using the net/http package of Golang. I used this small code below to "upar" a folder and then be able to access in my mobile phone or notebook through the ip address.

    import (
    "log"
    "net/http"
)

func main() {
    http.Handle("/", http.FileServer(http.Dir("C:\\VIDEOS")))
    log.Fatal(http.ListenAndServe(":8080", nil))

}

The code works and I can access the files through the browser on my PC, however I would like to know how I can "free" access to other devices in my network access the files too.

1 answer

2


When you run your go code, Windows will ask you for permission so that other devices on your private network can access that port (8080). All you have to do is allow her to be accessible.

When accessing, instead of using the address localhost + port, you will need to use the IP address of your computer on that network plus the port. To know which is the IP, just access the Command Prompt and use the command ipconfig/all.

  • Solved the problem friend thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.