Hi

I think that this is the case that "proper way" means "the one that fits 
your needs".
Some solutions you may adopt:
a) (cd /path/to/my/server/directory ; go run main.go) &
b) use absolute pathnames: os.Open("/path/to/my/server/directory/
images/my.png")
c) Load configuration from some file/db
d) command line flags, like:
.
.
.
import "flag"
.
.
.
var pathToMyServerDirectory string
.
.
.
flag.StringVar(&pathToMyServerDirectory,"path",".","Server root directory")
.
.
.


Em segunda-feira, 6 de maio de 2019 19:45:08 UTC-3, sunto...@gmail.com 
escreveu:
>
> I'm learning Go web server programming and have copied the following 
> example:
>
>
> func Image(w http.ResponseWriter, r *http.Request) {
>     f, _ := os.Open("images/my.png")
>     . . . 
>
>
> It works fine when I'm starting the Go web server with `go run main.go &`. 
> I.e., the file "images/my.png" is related to where I started "go run". 
> However, it won't be the case when the Go web server is compiled and 
> started the other way. 
>
> What's the proper way to make sure it always works, including starting 
> from docker container? 
>
> THX!
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ddfc81dc-9700-4c44-be9e-fc966aac2c79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to