goapp | An opinionated guideline to structure & develop a Go web application/service | REST library
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 ).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of goapp
goapp Key Features
goapp Examples and Code Snippets
Community Discussions
Trending Discussions on goapp
QUESTION
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:
...ANSWER
Answered 2020-Nov-16 at 15:54You 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 (glibc
, 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:
QUESTION
I have a very simple Go app that I'm trying to Dockerize.
...ANSWER
Answered 2020-Jul-22 at 18:05The CMD
is interpreted as JSON, so you need to change the single quotes to double quotes.
QUESTION
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
...ANSWER
Answered 2020-Feb-27 at 17:24From the 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:
QUESTION
I want to set a safety zone by device. My web view is set to SafeArea above
, SuperView below
. After the iPhone X
series, the value of Y
is 44
because of the notch
area. But for the iPhone 6
and iPhone 8
, 44
is too wide. How do I adjust it?
ANSWER
Answered 2019-Nov-12 at 09:14Make 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).
QUESTION
I am using go module, the file structure is like this:
...ANSWER
Answered 2019-Aug-03 at 13:51Thank @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
require
in go.mod - Missing
=>
fromreplace
in go.mod - Missing
go.mod
forfoo
package.
So to make it work:
File Structure:
QUESTION
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
...ANSWER
Answered 2019-Jul-09 at 13:48invokes 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.
QUESTION
I have a simple API written in GO using Mux.
When running locally it works, however I am trying to containerize this app.
My main.go
looks like this
ANSWER
Answered 2019-May-26 at 10:49I think you need to remove the host portion from your Addr
property.
QUESTION
I've been updating my entire go gae standard project to use go 1.11's modules.
Main directory structure
...ANSWER
Answered 2018-Dec-07 at 18:26Set git credentials before deploying:
QUESTION
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
:
GOPATH=":/home/mohammad/go:/home/mohammad/go/src/gitlab.com/gc-auth"
Also getting the same output when I run echo $GOPATH
.
Any help is appreciated.
PS: I have ubuntu 18.04 and my go version is 1.10.4
results of gcloud version
:
Google Cloud SDK 228.0.0
app-engine-go
app-engine-python 1.9.80
bq 2.0.39
cloud-datastore-emulator 2.0.2
core 2018.12.07
gsutil 4.34
ANSWER
Answered 2018-Dec-29 at 13:06GOPATH=":/home/mohammad/go:/home/mohammad/go/src/gitlab.com/gc-auth"
QUESTION
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?
...ANSWER
Answered 2018-Nov-26 at 11:06You've disabled CGO for your build, but you're not disabling CGO for your tests, which you must do:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install goapp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page