kandi X-RAY | goapp Summary
kandi X-RAY | goapp Summary
This is an opinionated guideline to structure a Go web application/service (or could be extended for any application). My opinions were formed over a span of 7+ years building web applications/services with Go, trying to implement DDD (Domain Driven Development) & Clean Architecture. Even though I've mentioned go.mod and go.sum, this guideline works for 1.4+ (i.e. since introduction of the special 'internal' directory). P.S: This guideline is not directly applicable for an independent package, as their primary use is to be consumed in other applications. In such cases, having most or all of the package code in the root is probably the best way of doing it. And that is where Go's recommendation of "no unnecessary sub packages" shines. In my effort to try and make things easier to understand, the structure is explained based on a note taking web application (with hardly any features implemented ).
Top functions reviewed by kandi - BETA
goapp Key Features
goapp Examples and Code Snippets
Trending Discussions on goapp
I'm building a multistage Docker image of a golang microservice and I want to make it very thin using busybox as base image to run the final executable. The image is correctly built, but when I run it I get this error:...
ANSWERAnswered 2020-Nov-16 at 15:54
You are building your app with
CGO_ENABLED=1 (this is Go's default setting for builds) - and transplanting that executable to a docker image where there is no compatible library support (
dns resolver etc.).
To ensure your build does not rely on any external libraries - statically binding all dependencies - and can then be deployed to a
SCRATCH docker image or
busybox - disable
CGO during your build phase:
I have a very simple Go app that I'm trying to Dockerize....
ANSWERAnswered 2020-Jul-22 at 18:05
CMD is interpreted as JSON, so you need to change the single quotes to double quotes.
Im doing a hashed password generator, i have an endpoint at the server that generates a goroutine to create the hashed password, and then send it as a response when the goroutine ends.
this is the function that is called to generate the hashed password...
ANSWERAnswered 2020-Feb-27 at 17:24
sync package docs:
Values containing the types defined in this (sync) package should not be copied.
So if something needs a reference use a pointer.
Change your function signature so
wg is a pointer reference:
I want to set a safety zone by device. My web view is set to
SuperView below. After the
iPhone X series, the value of
44 because of the
notch area. But for the
iPhone 6 and
44 is too wide. How do I adjust it?
ANSWERAnswered 2019-Nov-12 at 09:14
Make the constraint anchored to the safe area and give it the desired value. It will automatically adjust to all devices.
Here you can see a UIView with blue background, anchored top and bottom to the safe area with a 0 value (you can increase the value if you want more distance to the safe area).
The view will be automatically drawn giving the proper distance to the safe area (which is 44 for iPhone X or above, and 0 for iPhone 8 and below).
I am using go module, the file structure is like this:...
ANSWERAnswered 2019-Aug-03 at 13:51
Thank @MartinTournoij, @Peter, @DaveC very much for their help and comments which I have upvoted. After following all the directions, I finally make it work.
(Btw, I really shouldn't trust VSCode error message too much. Because I normally check errors from VSCode. Thus I didn't try
go build before asking this question. I thought they should return the same error, but they are not.
go build provides more reasonable error messages than VSCode.)
There were three problems.
- Missing version from
So to make it work:
We are running a Golang application that internally runs an autoupdate module to recieve over the air updates. At the time of a new update, the autoupdate module downloads the new version from s3 and invokes an autoupdate bash script present in the same working directory as the executable. The steps performed by the autoupdate bash script are explained in terms of process management handled with and without systemd.
Execution without Systemd
- Kills the currently running golang app via PID
- Runs the newly downloaded golang binary.
- The new version exposes an health check API which is invoked by script to makesure this version is healthy.
- If not healthy, rollback is performed. The new version is stopped and older version is started.
In golang, the script execution code is written such that when autoupdate script is invoked, it is disowned from the lifecycle of the golang application. i.e bash script (child process) continues execution even after the parent(golang app) is killed. It works fine when running from the GoLand IDE.
Issue : Execution via Systemd
We needed a cleaner system to handle the start ,stop, restart-on failure functionalities. So we decided to run the app as a systemd service.The steps are the same as above but performed using systemctl
- Kills the currently running golang app : "systemctl stop goapp.service"
- Updates the systemd service with the new executable path : "systemctl daemon-reload"
- Restarts the systemd service : "systemctl restart goapp.service"
- If not healthy, rollback is performed. The new version is stopped, systemd service file is updated with older version and older version is started.
On executing the application via systemd, the script exits as soon as the systemctl service is stopped using command "sudo systemctl stop goapp.service" during step 1 mentioned above. This means that the lifecycle of the script executed by the golang app is clearly coupled to the lifecycle of the systemd service. How can I detach it from the of scope of systemd service?
Systemd service file...
ANSWERAnswered 2019-Jul-09 at 13:48
invokes an autoupdate bash script present in the same working directory as the executable.
I would recommend running it with systemd-run. Excerpt from the man-page:
It will run in a clean and detached execution environment.
I have a simple API written in GO using Mux.
When running locally it works, however I am trying to containerize this app.
main.go looks like this
ANSWERAnswered 2019-May-26 at 10:49
I think you need to remove the host portion from your
I've been updating my entire go gae standard project to use go 1.11's modules.
Main directory structure...
ANSWERAnswered 2018-Dec-07 at 18:26
Set git credentials before deploying:
I'm tying to write tests for my google cloud app. I read the documents and it seems the only way to run the test locally is the running the command
goapp test in the test package directory. But when I run the command I get the error
go: GOPATH entry is relative; must be absolute path: "".
I'm pretty sure my GOPATH is set absolutely. Here are the results when I run the command
go env | grep GOPATH:
Also getting the same output when I run
Any help is appreciated.
PS: I have ubuntu 18.04 and my go version is 1.10.4
Google Cloud SDK 228.0.0
ANSWERAnswered 2018-Dec-29 at 13:06
I use Docker to add my project to it, now I want to run some test on it and I got errors that the test failed
Any idea what I miss here?...
ANSWERAnswered 2018-Nov-26 at 11:06
You've disabled CGO for your build, but you're not disabling CGO for your tests, which you must do:
No vulnerabilities reported
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page