74,414 questions
104
votes
12
answers
133k
views
How to implement level based logging in golang?
Is there any good wrapper available for level based logging in golang?
If not, how should I go about implementing one myself?
What I want is pretty simple. I want a few functions e.g.
log.Error()
...
0
votes
2
answers
1k
views
Go program exits before goroutine workers complete
I'm having an issue understanding how to properly block and close channels. I'm starting some arbitrary number of workers and I've discovered that my main function either exits before the workers have ...
0
votes
0
answers
74
views
VS Code does not correctly indent closing parenthesis in Go import() or func(){} statement
I'm using VS Code on Nobara Linux (a Fedora-based distro) and working with the Go programming language.
When I type the following and press Enter after import(: import(⏎)
The result I get is:
import(
)...
0
votes
0
answers
56
views
What is the correct way to iterate through a JSONL reader with jsonv2
Consider this demo example:
import (
"bytes"
"io"
"log/slog"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/...
4
votes
1
answer
344
views
How to stream a dynamically created tar archive to a browser client as a single file download?
I am creating a server application to transfer many (could be 100+GB) files from discrete servers as a single tar archive to a browser client via a simple single file download.
Currently I settled on ...
0
votes
1
answer
41
views
How do I change the indent of a YAML sequence in goccy/go-yaml?
I have a YAML file which starts out like this:
additional_hostnames: []
I use goccy/go-yaml to parse it and add a new value like this:
newHostnameNode := ast.String(token.New(hostname, hostname, &...
0
votes
0
answers
20
views
runtime.AddCleanup does not run in golang [duplicate]
Due to application-specificity, I am trying to store either an object or a integer into a single int64 using the code below. However, the GC failed to release the resource. I am not sure where it went ...
23
votes
3
answers
28k
views
Start a process in Go and detach from it
I need to start a new process in Go with the following requirements:
The starting process should run even after the Go process is terminated
I need to be able to set the Unix user/group that's running ...
17
votes
3
answers
13k
views
How to fork a process
I need help understanding how to demonize a process in Go.
package main
import (
"fmt"
"os"
)
func start() {
var procAttr os.ProcAttr
procAttr.Files = []*os.File{nil, nil, nil}
_, ...
31
votes
3
answers
54k
views
How do I fork a go process?
I want to fork a go process and get back the id of the new process(es), but all I can see in the exec or os libraries is to start a new process.
2
votes
2
answers
66
views
set bubbletea program on model
I'm attempting to use the bubbletea library in Go, and one of my models needs to send a message when updated, which requires a reference to the bubbletea Program. I'm running into a chicken and egg ...
1
vote
0
answers
64
views
how i can populate struct type only in returning joined column from sql
I have a table named tasks where have relationship one-many to another table (projects), i want to query tasks with projects but only return selected column from the projects table. how i can do that ...
23
votes
5
answers
35k
views
How do I zip a directory containing sub directories or files in Golang?
I know it will have to do with the zip package I just have no idea how I would implement such a thing.
3
votes
2
answers
11k
views
How to validate allowed fields in json body in go validation
I have a go struct which I'm using for my POST of an entity
type Student struct {
ID string `json:"id" firestore:"id"`
Name string `json:"name&...
-3
votes
1
answer
90
views
UDP server in Go doesn't receive calls from Lua client [closed]
I have a UDP server set up in go, that reads from any address and then sends a response, and a client that sends the calls to the server. the client sends the calls successfully, but the server doesn'...