Go Language Collective

The official Q&A channel for Google's Go Programming Language.
The official Q&A channel for Google's Go Programming Language.

Questions

Browse questions with relevant Go Language tags

58,994 questions

0votes
0answers
3views

Custom unmarshal function for time.Time type alias

I am trying to write a unmarshal function for a custom type. Consider the below code (playground) package main import ( "encoding/json" "fmt" "strings" &...
  • 1,554
0votes
0answers
7views

Fabric: InvokeChaincode with chaincode identity

I am playing around with the ERC20 token implemented in fabric-samples. I was wondering if it is possible to not only send tokens between users but have deployed chaincodes receive/hold/send tokens as ...
-3votes
0answers
19views

I need to extract a map that will be made from keys and values of all the maps in a struct

There is a struct: type struct { a map[string][]byte b map[string][]byte . . . } I want to create a map that will hold all the keys(str) and ...
0votes
1answer
40views

Does a goroutine necessarily run on a different CPU?

The following excerpt is from https://go.dev/doc/effective_go We launch the pieces independently in a loop, one per CPU. They can complete in any order but it doesn't matter; we just count ...
2votes
0answers
22views

Getting data with Pending status from redis

Good afternoon. I am trying to solve a queue problem with radis stream. Task description: we need to implement a queue to store the data that we will send to the user's email. How it works: I have a ...
  • 309
1vote
1answer
34views

How to setup pgx to get UTC values from DB?

I'm using Ent with Pgx. The column created in Postgres is: used_at timestamp with time zone NOT NULL, The value in Postgres is saved without timezone (in UTC): 2022-06-30 22:49:03.970913+00 Using ...
0votes
1answer
19views

Building go tests from multiple packages into single file

Is there any way to build all the test files in a project located inside multiple packages into a single binary file? To build binary inside a single package, I could use go test -c. I need something ...
1vote
1answer
34views

Getting file content into a multidimensional string var

I'm trying to get this JSON file info into a multidimensional string var in GO: { "info": [ { "type": "general", "news": [ { ...
  • 185
0votes
1answer
32views

Container on same network not communicating with each other

I have a mongodb container which i name e-learning and i have a docker image which should connect to the mongodb container to update my database but it's not working i get this error: Unknown, Last ...
1vote
0answers
32views

Is it possible to configure socket connection(not web) in Nginx reverse proxy server

I have a CLI client and server written in Go Currently, they are communicating via a socket connection and it's a server streaming connection Now I want to have an Nginx proxy between these two Is it ...
0votes
0answers
18views

Incorrect Usage. flag provided but not defined: -raft

When I run the following command PRIVATE_CONFIG=ignore nohup geth --datadir node1 --nodiscover --verbosity 5 --networkid 31337 --raft --raftport 50001 --rpc --rpcaddr 0.0.0.0 --rpcport 22001 --rpcapi ...
1vote
0answers
18views

Heroku Ruby (Jekyll) & Go build packs

I'm trying to build a web app with Jekyll and Go, where I use Go to embed the generated _site file from the Jekyll build & add some HTTP handlers with the conditions I need. remote: -----> ...
1vote
0answers
35views

Getting different results with bindvars in db.Query

go version : 18.3 github.com/go-sql-driver/mysql v1.6.0 When Query string is db.Query("SELECT * FROM logs ORDER BY log_id DESC LIMIT 1,3 ") if the log_id == 8 b, _ := rawValue.([]byte) Below ...
-1votes
0answers
25views

Is restarting my Go application the only way to prevent Prepared Statements from breaking when I change the DB Schema?

My application is in Go. It talks to a PostGres database. I am using Go's Prepared SQL Statements to increase performance. While the application is running, I run the following SQL statement to modify ...
0votes
0answers
26views

GOLANG , in localhost server how to print ip ? (127.0.0.1 )

i have this code where i try to get the localhost ip 127.0.0.1 func (m *Repostory) HomeHandeler(w http.ResponseWriter, r *http.Request) { for name, values := ...
1vote
0answers
17views

Good way to notify distributor that the worker can't process any more messages

I currently have a distributor service and a worker service that communicate via SQS. The distributor searches for expired values in a postgresql database and sends them to SQS. The worker picks up ...
1vote
1answer
58views

Loop seems to be modifying a variable in Go

I have a variable decodedToken (type: struct), and I access one of its values called "Claims" through a type assertion: claims := decodedToken.Claims.(jwt.MapClaims) I then loop through the ...
  • 53
1vote
1answer
28views

Concurrently Add Nodes to Linked List golang

I'm trying to add nodes to a linked list concurrently using channels and goroutines. I seem to be doing be something wrong, however. Here's what I've written so far. Currently, my print function is ...
1vote
1answer
17views

How to Use Go With MongoDB For Group?

data userId height curry 1 curry 2 kd 3 kd 4 james 2 input: userIds=[curry,kd,james] i want curry 2 kd 4 james 2 So, i want one record ...
2votes
1answer
42views

Continue execution after recovered panic without knowing which function might panic

I was referred to this question: Program recovered from panic does not exit as expected It works fine but it relies on knowing where the panic occurs in order to place the deferred function. My code ...
  • 1,117
2votes
0answers
24views

Using a PTY without a command

I opened an issue in creack/pty for this question, but I actually think it probably belongs here as it's probably more to do with my usage of the library than anything wrong with the library. I am ...
1vote
0answers
12views

Does prometheus golang (echo-contrib) exporter saves metrics in memory?

I have a GoLang middleware for exporting metrics for prometheus, which are then served from /metrics endpoint My question is where does the data received from /metrics endpoint come from? Does it come ...
1vote
0answers
49views

Error 404 Not Found while unit testing govmomi vapi rest client using simulator

I'm working with vSphere govmomi client to interact with vCenter. I'm having problem in unit testing the govmomi vapi/rest client. The sample code for creating rest client is: var insecure bool = true ...
0votes
0answers
16views

BigCache Configure for Never Expiring

I am using bigCache in Go for caching data. Is there anyway to configure it so that it never expires?
1vote
0answers
21views

How to permanently delete associations in GORM

I want to know how to permanently delete associations in GORM. I tried all examples shown in the documentation but I cannot get associations to become permanently deleted. For example, I am confused ...
1vote
1answer
55views

Writing directly to socket vs to buffer

I have seen multiple applications write their data first to buffer, then writing that buffer to socket and not just directly to socket. I have two questions: Why is that? If writing straight to ...
2votes
1answer
33views

Jenkins scripted pipeline contains constructs that are not present in the file. Please assist what are these?

I am new to jenkins and struggling to find out what the below is? The jenkins file for my project has contents similar to the below stage("Build and push"){ def projectImage = ...
0votes
1answer
33views

PSQL queries creating multiple select queries based on condition to filter out values

WITH final AS ( SELECT 'a' AS gname, 'b' AS pname, 'c' AS name, 1 AS gid, 2 AS pid, 3 AS did, 3 AS inp UNION SELECT 'a1' AS gname, 'b1' AS pname, 'c1' AS name, 11 AS gid, 21 AS pid, 31 AS ...
2votes
0answers
22views

Representing NaN and Inf value with big.Rat in GO

I am using Avro library from here. One of the schema fields of Avro looks like this: [{"name":"Col_1", "type":["null",{"type":"bytes", "...
0votes
1answer
31views

How to install Golang on chrome os

I tried the method from https://go.dev/doc/install and I keep getting "-bash: go: command not found". I tried https://gist.github.com/conoro/4fca191fad018b6e47922a21fab499ca but I dont know ...
-1votes
0answers
23views

Unable to take space separated input from fmt.Scan() in Golang

Hi I have just started learning golang. I would to do following things using the code below:- Actions I want to do with my code :- Take input from user (let's say it is n) that will serve as the ...
0votes
1answer
57views

One byte is lost when encoding a file into base64 in Golang

package main import ( "bytes" "encoding/base64" "fmt" "io" "log" "os" ) func b(name string) { f, err := os....
1vote
0answers
44views

How to return a newly created record back from the database using gorm

I have a function that creates a new user, however the reccomended way to get the values of the user does not include the autogenerated values created by the database (id, created_at) type User struct ...
  • 15k
1vote
0answers
42views

Go context.WithTimeout does not work with exec.CommandContext sudo commands, even if I try to kill child processes. What is going on? Am on Linux

I have been using exec.CommandContext to run sudo commands in my Go packages, and it works. Nowadays, I am trying to add a timeout so that the command just terminates if it does not finish after the ...
1vote
0answers
36views

Handle Logrus and Cobra CLI in Golang

I am relatively new to the packages Cobra and Logrus in Golang and there is one little thing I would to ask for help when it comes to integrating them. I am working on a new Golang Cobra CLI which ...
1vote
0answers
22views

golang pgconnection pool - how to test if the pool was initialized or empty

I am not fully familiar with golang patterns / best practices with respect to database connections. I am trying to implement a simple web service in go, using jackc/pgx connection pool. In a file (...
0votes
0answers
18views

Nats.io, Golang: What's a `subj` parameter of a `js.PullSubscribe()` method for?

What's a subj parameter of a JetStream.PullSubscribe() method for? I observe following behavior: When a consumer is created without the FilterSubject configuration option, then no matter what I pass ...
-2votes
1answer
56views

How to avoid nested map allocations in my data structure?

I have a below struct where I have a nested map for CustomersIndex which allocates bunch of internal maps causing memory increase. I profiled it so I noticed this. I am trying to see if there is any ...
1vote
0answers
18views

How to force browser not to cache a random string

I'm writing a web app which generates a random string every time a page is requested. It's imperative that the string is different every time the page is loaded, but this isn't the case as the browser ...
0votes
0answers
20views

Heroku Deploy Gqlgen golang Unexpected token < in JSON at position 0

i tried deploying my golang server to heroku automatically, and the server runs until the playground. i use gqlgen from graphql golang but when i try to run the query and i fetch data in playground, i ...
0votes
1answer
44views

Set reflect.Value to slice in Go

I try to save a slice of integers of a field. the field is type reflect.Value. I get the error: cannot use articles (variable of type []int64) as reflect.Value value in argument to field.Set. What can ...
1vote
0answers
34views

go api webserver: total post request json data not taking as input

i made a api server to store the details of students. here the json keys are StudentName RollNo Gender Branch when i send these values in post request , only Gender and branch values are storing. ...
2votes
0answers
56views

docker go permission works on mac fails on linux

I'm trying to run go tests inside a container and want the coverage file exported to the host volume. My solution works on macOS but fails on linux. my Dockerfile looks something like this: FROM ...
0votes
0answers
37views

Purpose of deferring a closure with file.Close

While reading the source code of Go program for dealing with program memory I found this snippet of code: f, err := p.openFile("mem") if err != nil { return nil, err } defer func() { _ = ...
0votes
2answers
41views

How to mock kafka dependencies and writer in Golang?

I have a struct type Server struct { grpcServerPort int grpcServer *grpc.Server writer *kafka.Writer } this Server has lot of methods including - func NewServer(port int) *Server { ...
-1votes
2answers
51views

How to use interfaces implemented through embedding in generics

I have an interface type FooInterface interface { HasName() bool } It has a base implementation that I intend to use in other implementation of FooInterface type FooBoilerplate struct { ...
1vote
1answer
40views

GORM: How to query has many relation?

I need to find all students that belong to a school with a certain name. type School struct { gorm.Model Students []Student } type Student struct { gorm.Model name string SchoolID ...
0votes
2answers
56views

Passing variables of different types by reference as arguments to same variadic parameter

I've been struggling with golang's lack of optional parameters, so I have been using the closest workaround: variadics. Even though I got it working, it is messy attempting to pass multiple variable ...
4votes
1answer
28views

Rejected go_darwin_arm64 mismatching values: x86_64

I'm trying to get a Bazel build working on my MacBook Pro M1 on Monterey, and I'm having a difficult time. When I try to build a docker image, I get go toolchain errors (with --...
1vote
0answers
19views

How do I extract individual OPUS frames, one by one from a .webm file

I have a .webm file that contains only audio encoded in the OPUS codec (no video). I want to know how i can extract each individual OPUS frame from the file without decoding it into PCM and re-...


153050per page