Questions tagged [go]
Go is an open-source programming language. It is statically-typed, with a syntax loosely derived from C, adding automatic memory management, type safety, some dynamic typing capabilities, additional built-in types such as variable-length arrays (called slices) and key-value maps, and a large standard library.
51,198
questions
0
votes
0answers
8 views
Compiling a golang binary on a non-linux OS works on AWS Lambda but not when compiled on Linux?
So I compiled a golang binary locally on a Linux system and uploaded it using the instructions from AWS. It didn't work. Then tried compiling it locally on MacOSx and uploading it and that worked.
...
1
vote
1answer
17 views
Elevating go code to root? Best practices?
I have a Golang web app on Linux that needs to manipulate the networking stack. The code to do the manipulation is in a go package and needs to be run with root privileges - e.g. if it's not sudo'd, ...
0
votes
0answers
12 views
Race-condition with errgroup?
g.Go(func() error {
result, err := makeDBCall()
if err != nil {
fmt.Println("Error 1")
return err
}
return nil
}
g.Go(func() error {
result, err := ...
-1
votes
1answer
22 views
Deadlock with multiple goroutines and os.Open
I am writing a go program that has multiple goroutines, each given a unique file in a directory to process. As such, I have the line f, err := os.Open(filename) for each goroutine, but it appears to ...
0
votes
0answers
25 views
Will a constructor that returns a struct pointer always recreate the struct similar to instantiating a class in Java?
I have a background in Java, and I have used Spring's dependency injection for many years.
In main.go of my project, I return struct pointers by way of the "New" constructor, and then I ...
-1
votes
0answers
15 views
json.Marshal converts SHA256 hash into into some other hash
I'm trying to save a SHA256 hash into a redis database, but it gets converted into some weird string like this: AAoYHZdAUjdguk/Q/NVmdcuTeAKZoAhJlP6yuFxP/XI=. I suppose it's a side effect of the json....
-3
votes
0answers
23 views
Is there a way to simulate file closing error in Go?
I have this function.
func fetch(url string) (filename string, n int64, err error) {
resp, err := http.Get(url)
if err != nil {
return "", 0, err
}
defer resp.Body....
0
votes
0answers
14 views
How use MongoDB driver in a package?
I have the following structure in my project.
main.go
go.sum
go.mode
source --------------
|
|
db ---------
...
3
votes
1answer
29 views
html file cannot work if {{ end }} is added
I am using golang to add contents to the html template files. The main file is simple
func main() {
server := http.Server{
Addr: "localhost:8080",
}
http.HandleFunc(&...
-1
votes
0answers
15 views
How to read from HDFS [closed]
Beacuse of poor documentation about apache beam go sdk, I cannot complete my pipeline that use apache beam and go sdk. Does anyone know if there is a way to read files for HDFS in Apache Beam- go sdk ...
-3
votes
0answers
17 views
Moment of threads creation
When is the moment when threads determined in runtime.GOMAXPROCS(n) will be created:
When we launch binary file amount of threads equals runtime.GOMAXPROCS(n) will be created immediately, for instance,...
0
votes
0answers
39 views
Testing websockets
I am trying to write testing for my chat API in go, but I am pretty new to testing in Go. I can't find proper examples on how to test more complex functions. For example I have this function where I ...
-1
votes
1answer
22 views
Override receiver type in test and dependency-inject into logic
Using Go v1.14.3, I'm trying to do the following:
package main
import (
"os"
"github.com/mihaigalos/go-bar/bar"
)
var progressBar bar.Bar
func (*ProgressHandler) New(...
0
votes
0answers
33 views
Postgres BIGINT value not being created or updated
I am doing this:
Note : Request is generated with squirrel
// Prepare query
qb := sq.Update(d.table).
SetMap(updates).
Where(filter).
PlaceholderFormat(sq.Dollar)
/...
0
votes
0answers
18 views
VSCode does not enable links for each Go Editor tab
I am using Visual Code for my Go development and I notice that for each .go file I open in an Editor, I don't by default can click on an imported package function.
Like, I have to open Command ...
0
votes
2answers
45 views
How this select works in goroutine?
i have been following the go tour examples, and i don't understand how this works
https://tour.golang.org/concurrency/5
package main
import "fmt"
func fibonacci(c, quit chan int) {
x, ...
-3
votes
2answers
24 views
Find out number of installs of a package [closed]
Let's say that I want to figure out how many programmers import https://github.com/golang-migrate/migrate, similar to how I can figure it out for npm package on this website.
I know that you can guess ...
0
votes
1answer
25 views
Sending Websocket messages to new clients
I am creating a chat API using Go and Gorilla websocket. I would like my users to receive the last 10 messages on establishing a websocket connection. However I can't find a simple way to do that. I ...
0
votes
0answers
14 views
Listen to FSnotify for Remove event and get the inode for the deleted file
I am trying to use fs notify to detect file creation and deletion. When the file is deleted I want to know the inode of the file deleted. Is there a way I can achieve it ?
0
votes
2answers
30 views
How do you gracefully exit a go uber fx app
How do you stop an uber fx as in shutdown the entire program. There seems to be no other way other than ctrl+c
func main() {
fx.New(
fx.Invoke(register)
).Run
}
func register() {
...
-3
votes
1answer
47 views
How break works in infinite loop? [duplicate]
In the below code:
data.WaitForGoroutine.Add(1)
go func() {
for {
select {
case msg := <-someCh:
data.DataCh <- fmt.Sprintf("Received messages: key %s, value:...
-2
votes
1answer
16 views
Writing timestamps to database - gocql vs cqlsh [closed]
Desired format to write time stamp, in cassandra database:
2021-01-17 21:51:46.195
Using cqlsh syntax for insert query:
am able to write the above format using toTimeStamp(toDate(now()))
Using ...
0
votes
0answers
13 views
*gin.Context has no field or method FromFile
I am new in golang,
I use gin ,
and i want to upload file with gin ,
but I receive this error => type *gin.Context has no field or method FromFile
my gin version is up to date(v.1.6.3)
I search a ...
-2
votes
1answer
18 views
Go testing get caller line number
Example code:
package main
import "testing"
func TestOne(t *testing.T) {
assertEq(t, "A", "B")
assertEq(t, "B", "B")
assertEq(t, "C&...
0
votes
0answers
27 views
Simple web server causing Exception 0xc0000005 windows 10
I'm a student brand new to golang and I'm trying to make a simple web app to learn. For reasons I don't understand if I write any program other than a simple "hello world" I get an Exception ...
1
vote
1answer
19 views
Go cannot connect to Mongo container when using docker
I would like to run 3 services:
My Go program which will connect to MongoDB in another container
Mongo
Mongo Express
Here's my docker-compose.yml:
version: "3.7"
services:
app:
...
0
votes
1answer
17 views
Can you have multiple working directories with github actions?
So I have a repo with multiple directories for multiple go projects. Is there a way to run github actions on multiple working directories so I don't have to have redundant yaml with github actions? To ...
0
votes
1answer
36 views
Parsing ARN from IAM Policy using Regex
I have the following IAM Policy:
{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"AWS&...
-2
votes
1answer
29 views
What is the useful usage of slice capacity in Golang? [duplicate]
Slice has capacity argument in slice short deflagration with make function.
z := make([]float64, 5, 10)
fmt.Println(len(z), cap(z))
for i := 0; i < 10; i++ {
z = append(z, 1)
...
0
votes
1answer
41 views
Big-O of my solution to finding common item in two arrays?
I have a question: my solution to the problem of finding common item in two Arrays was this one:
func commonItem2(list1 []string, list2 []string) bool {
list1 = append(list1, list2...)
sort....
-4
votes
1answer
39 views
Accessing constants using strings / variables during runtime
I am working on a cross-platform typing / key-press simulator. In this, I am trying to achieve a functionality as follows.
package main
import "fmt"
import "strings"
const (
...
0
votes
0answers
33 views
How to convert a pointer to a C array to a Go reflect.Value with kind Slice
I have a pointer to some allocated memory that contains a C array that is not managed by the garbage collector, and for which I know the size but not the type at compile time. I would like to convert ...
-4
votes
1answer
46 views
Build docker file for my HTTP goserver for loadbalancing? [closed]
I have built a load balancer in Go. I want my server to run in docker container.
I later want to send the request to my load balancer which will transfer to the server running in the container.
How ...
-2
votes
1answer
29 views
How should i deliver updates to consumers of my API framework? [closed]
I am writing an API framework which involves updates polling. I need to expose my users a way to receive and handle such updates. I considered the following:
Return a channel and stream updates ...
-2
votes
2answers
80 views
How does Go open files?
I built a Go Web Project with Iris version 12, and now there is a file named config.go, I can output config.json by shell script cat ../config.json in the folder which includes config.go, but Go note ...
-1
votes
2answers
50 views
Build excluding test modules
My project has the following structure:
āāā api
āĀ Ā āāā api.go
āĀ Ā āāā api_test.go
āĀ Ā āāā other_files...
āāā cmd
āĀ Ā āāā main.go
Under cmd/main.go I have the entrypoint of my Go project.
Since I am ...
1
vote
1answer
46 views
Cross compile a shared Library under Linux for windows
I want to get a windows-DLL, but I want to compile it under Ubuntu-Linux.
Building an Executable was simple: env GOOS=windows GOARCH=386 go build wrapper.go generates a wrapper.exe, that behaves as ...
0
votes
0answers
19 views
Using tebeka selenium in GUI borwser mode
I am trying to automate a webpage testing using selenium with golang from here. When I run this example, I don't find the browser window opening. Looks like it is running in headless mode. How do I ...
1
vote
1answer
39 views
Best practices to perform a JOIN with SQLX, Squirrel
I have this model.
// Incident is a security incident.
type Incident struct {
ID string `json:"id" bson:"_id"`
Title string `...
0
votes
1answer
48 views
What does the error “binary.Write: invalid type” mean?
The code shown below, I create a struct type and want to encode it to binary.
But it show binary.Write: invalid type main.Stu error, I had read some similar code like this,but I can't find why my code ...
0
votes
2answers
55 views
Structuring go project for this use case [closed]
I am building a Go service that communicates with multiple third-party providers. This go-service acts as an interface between these multiple providers and my internal applications consume just one ...
-2
votes
2answers
49 views
Does Go execute all the conditions in "if' if the first fails? [duplicate]
Imagine the following piece of code:
if someBool && funcReturningABool() {
// code here...
}
where someBool is a boolean and funcReturningABool returns true or false.
If someBool is equal ...
0
votes
1answer
38 views
How to make a linux executable file using gitlab (go env)?
I am very new to gitlab pipelines. I am trying to make a Linux executable file of my go language project. I have following configuration in my .config-ci.yml in my gitlab project.
demo_job_1:
tags:
...
0
votes
0answers
69 views
How to convert [8]*uint8 to **uint8
Background: using cgo to call C functions from Golang.
I want to use a C function which has this signature: int swr_convert(struct SwrContext *s, uint8_t **out, int out_count, const uint8_t **in , int ...
0
votes
2answers
41 views
cannot use address (type string) as type AccountAddress in assignment
I'm facing an issue while assignment of a string with a type of type AccountAddress [16]uint8.
type AccountAddress [16]uint8
address := c.Param("adress")
var account AccountAddress
account =...
-1
votes
0answers
29 views
Why the context.Request.Body would be dirty when many goroutine read and write the body
when using golang gin framework, the context.Request.Body would be nil if someone already read it in some place, such as
data, _ := ioutil.ReadAll(c.Request.Body)
so in my deal, I put the data into ...
-4
votes
0answers
13 views
Fallback fabrication tips during gateway development [closed]
We are developing a gateway using Go.
Among them, I would like to add fallback function, so please recommend any good data.
Or, I think it would be good if you could suggest the development direction.
0
votes
0answers
22 views
program turns off with message: signal arrived during external code execution
I'm making a product management program using Visual Studio Code on Windows 10 with Golang, html, and MariaDB, etc.
Most of them work normally, but sometimes the program ends with the following error ...
0
votes
0answers
18 views
Is it possible to assign a Javascript variable in a script in Go HTML template to a template variable? [duplicate]
I have a web page using Golang html/template module and I have a template boolean variable
{{$variable := .thing}}
and I have an if and else branch that determines what to render
{{if $variable}}
<...
-2
votes
0answers
18 views
How to decode series of json object data in golang [closed]
MLC LOG: MLC 2.7.0-rd started
MLC LOG: Fetching login bundle error
MLC LOG: Args: {"_":[],"some data about application here"}
MLC LOG: {
"time": "12:31:22 PM&...