[go-nuts] Re: Simple Go web server that service files
On Tuesday, May 7, 2019 at 7:40:19 AM UTC-4, Luis Furquim wrote: > > Hi > > I think that this is the case that "proper way" means "the one that fits > your needs". > Ah, yeah, that's true -- I thought that there are some canonical ways, but you are indeed right. -- 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/0b897670-413a-4dfd-baa3-624a710c92cc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Simple Go web server that service files
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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Creating Go web server into small Docker images
Hi, I'm trying to create Go web server into small Docker images. Here is my Dockerfile: # golang:latest as build-env FROM golang:latest AS build-env RUN mkdir /app ADD . /app/ WORKDIR /app RUN cd /app && GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp . # go build -o myapp FROM scratch COPY --from=build-env /app/myapp /app/images/* / EXPOSE 8080 ENTRYPOINT /myapp It uses the Docker Builder Pattern and scratch image, which is a special docker image that's empty. It builds OK, but when I run it, I'm getting: docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown. How to fix it? 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Strange error after adding another sample code
Ah, that's 2nd condition to use tests in package with the "_test" as package, which I've forgotten. Thanks! On Monday, April 29, 2019 at 9:04:15 PM UTC-4, vaastav anand wrote: > > The issue is that you have multiple package names in the same folder. In > this specific case it is easygen and easygen_test. > You should have 1 package per folder. > The reason your test files did not raise this issue is because _test.go > files are automatically excluded when packages are being compiled. But its > not the same case with _execute.go files > > On Monday, 29 April 2019 16:18:29 UTC-7, sunto...@gmail.com wrote: >> >> What does the following error really means? >> >> can't load package: package ./.: found packages easygen (config.go) and >> easygen_test (example_execute.go) in /path/to/go-easygen/easygen >> cmd/easygen/flags.go:12:2: found packages easygen (config.go) and >> easygen_test (example_execute.go) in /path/to/src/ >> github.com/go-easygen/easygen >> >> I'm been adding example tests to my package using the "_test" >> as package without any problem. However, the one I've just added, >> >> https://github.com/go-easygen/easygen/blob/master/example_execute.g0 >> >> gives me errors now. and I have no idea why. >> >> Here is how to duplicate the problem. >> WIthin the `go-easygen/easygen` folder: >> >> >> $ go test ./... >> ok _/path/to/go-easygen/easygen (cached) >> ok _/path/to/go-easygen/easygen/cmd/easygen (cached) >> ok _/path/to/go-easygen/easygen/egCal(cached) >> ok _/path/to/go-easygen/easygen/egVar(cached) >> >> >> $ mv example_execute.g0 example_execute.go >> >> >> $ go test ./... >> can't load package: package ./.: found packages easygen (config.go) and >> easygen_test (example_execute.go) in /path/to/go-easygen/easygen >> cmd/easygen/flags.go:12:2: found packages easygen (config.go) and >> easygen_test (example_execute.go) in /path/to/src/ >> github.com/go-easygen/easygen >> >> >> $ head -1 example_test.go > /tmp/f1 >> >> >> $ head -1 example_execute.go > /tmp/f2 >> >> >> $ diff /tmp/f1 /tmp/f2 && echo same >> same >> >> >> >> Please help. 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Strange error after adding another sample code
What does the following error really means? can't load package: package ./.: found packages easygen (config.go) and easygen_test (example_execute.go) in /path/to/go-easygen/easygen cmd/easygen/flags.go:12:2: found packages easygen (config.go) and easygen_test (example_execute.go) in /path/to/src/github.com/go-easygen/easygen I'm been adding example tests to my package using the "_test" as package without any problem. However, the one I've just added, https://github.com/go-easygen/easygen/blob/master/example_execute.g0 gives me errors now. and I have no idea why. Here is how to duplicate the problem. WIthin the `go-easygen/easygen` folder: $ go test ./... ok _/path/to/go-easygen/easygen (cached) ok _/path/to/go-easygen/easygen/cmd/easygen (cached) ok _/path/to/go-easygen/easygen/egCal(cached) ok _/path/to/go-easygen/easygen/egVar(cached) $ mv example_execute.g0 example_execute.go $ go test ./... can't load package: package ./.: found packages easygen (config.go) and easygen_test (example_execute.go) in /path/to/go-easygen/easygen cmd/easygen/flags.go:12:2: found packages easygen (config.go) and easygen_test (example_execute.go) in /path/to/src/github.com/go-easygen/easygen $ head -1 example_test.go > /tmp/f1 $ head -1 example_execute.go > /tmp/f2 $ diff /tmp/f1 /tmp/f2 && echo same same Please help. 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. For more options, visit https://groups.google.com/d/optout.