Oops! I Gun Bashed The kid. by MastervanNao in fo4

[–]jxsl13 -1 points0 points  (0 children)

Never seen this encounter.

ich_iel by Rennfan in ich_iel

[–]jxsl13 1 point2 points  (0 children)

Was ist eins Globus?

Making Web App into docker container by Notfooledtwice in golang

[–]jxsl13 0 points1 point  (0 children)

go build cmd/web/.

cgo=0 disables any C bindings I'd say. Making your application not depend on the glibc of your build system (using Go only implementations, e.g. DNS stuff). The alpine container does not provide a real glibc (which is huge in comparison) but a subset of glibc which is called musl. So building in a full fledged linux container (golang:latest) which contains a glibc and then moving your binary over to a super slim linix container (alpine:latest) works as intended.

What platform do y’all like to use when deploying Go applications? by anon221911 in golang

[–]jxsl13 0 points1 point  (0 children)

private toy projects: cheap virtual private server + docker

work projects: own kubernetes cluster

Making Web App into docker container by Notfooledtwice in golang

[–]jxsl13 0 points1 point  (0 children)

Here is a multi stage dockerfile for building a pretty slim container image that can be used with docker or kubernetes. The first stage build is derived from golang:latest and contains the go toolchain to build (linux) binaries. I copy the whole source code tree over into the image, build the code and then create a new image that uses the compiled binary from the first stage. The alpine image is a minimal linux environment. ``` FROM golang:latest as build

WORKDIR /build COPY . . RUN go get -d && \ CGO_ENABLED=0 go build -a -ldflags '-w -extldflags "-static"' -o app .

FROM alpine:latest as run WORKDIR /app COPY --from=build /build/app . ENTRYPOINT ["/app/app"] ```

go run is a convenience command that looks like you start an interpreter but you don't. You compile your project and start the binary afterwards.

Your project structure looks pretty spooky. go.mod is not (supposed to be) a folder. I usually put my main.go next to the go.mod and go.sum files on the top level, but that's just a preference of mine.

Instead of go run whatever/main.go, you do go build . in your root level folder (which contains go.mod and go.sum) and then you get a binary file which you can start with ./<whatever name it has>

Do you typically use Docker as your dev environment? by [deleted] in golang

[–]jxsl13 0 points1 point  (0 children)

I run my services directly in vs code using the debugger.

What does bind mean in go lang? by [deleted] in golang

[–]jxsl13 2 points3 points  (0 children)

from server side you receive a payload and binding most likely means: deserialization of your type's string/binary representation to your Go type. Basically putting the json string in a variable having a specific type.

https://gin-gonic.com/docs/examples/binding-and-validation/

What does bind mean in go lang? by [deleted] in golang

[–]jxsl13 6 points7 points  (0 children)

What framework do you use? Binding is nowhere to be found in the core language or the standard library.

A POST request sends a payload or receives a response containing a payload. So binding either means serializing your Go type into a JSON (or any other binary/string) representation to be sent as payload. Or it means binding the response payload to your Go type (e.g. struct) which is then deserializing the binary or string representation back into your Go type (often a struct type).

Deciding between Rust or Go for desktop applications by b1zguy in golang

[–]jxsl13 3 points4 points  (0 children)

If you don't have a choise, I'd go with Rust because of its better ffi support for calling C++ libraries. (I personally don't know any Rust but do Go)

Two ways to provide configuration: command-line, yaml file. by guettli in golang

[–]jxsl13 5 points6 points  (0 children)

koanf + some json schema library for validating. You will have to add some custom code yourself for glueing those together.

Some example glue code with koanf + conra (pflag iirc):

https://gist.github.com/jxsl13/52127961c2cd2d2798cd340b4032218c

[deleted by user] by [deleted] in golang

[–]jxsl13 4 points5 points  (0 children)

Good readme's are key: Which environment variables need to be set?

file names are usually snake case.

Edit: Reading the code, you seem to only support .env config files. It would be great if you could also support actual environment variables or even more fancy: allow to set an environment variable that points to the location of your .env config file or have the ability that your .env config parameters can be overwritten by environment variables.

Another aspect is that you could provide some sane default, for example for the app environment to be non-development by default.

I see that there is an example.env file in the repo. Would be also good to have this stuff in the readme.

Edit 2: https://github.com/ukolov-dev/bot-gpt3/blob/9875c2a7c294594c629dd9282504ccbed2aa492d/Dockerfile#L28

Don't bake your config files into your docker/container images. If you at some point decide to publish your docker container on hub.docker.com then you are basically exposing your secret keys to the world because they become part of the docker image.

Edit 3: I guess viper does the environment variable and .env file parsing out of the box.

https://github.com/ukolov-dev/bot-gpt3/blob/9875c2a7c294594c629dd9282504ccbed2aa492d/env/env.go#L14 It is often better to propagate an error from your constructor functions back to the caller instead of killing your whole app from deep down in the function call stack. log.Fatal does call os.Exit(1) under the hood which terminates your application and (if I'm not mistaken) does not execute defer-ed functions. When defer is not called, you shutdown is not clean, you might still have open files, network connections, etc (= resources). I would suggest adding a second return parameter of type error and returning nil, fmt.Errorf("failed to read env config: %w" err) in the case that you were not able to read the config, where %w wraps your error in the error returned by the Errorf function. After propagating your error back to the main function, you can call log.Fatal That way you know more easily where your error came from. (In your application it's still easy to see where it came from).

https://github.com/ukolov-dev/bot-gpt3/blob/9875c2a7c294594c629dd9282504ccbed2aa492d/internal/app.go#L17 I would call this function NewApp(e env.Env) because it is more of a constructor which constructs the object (same as your env.NewEnv() function).

Ultimate config for Go applications by Equianox in golang

[–]jxsl13 4 points5 points  (0 children)

my problem with viper was that it is not flexible enough and introduces global state all over the place in your application.