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 and key-value maps, and a large standard library.

0
votes
1answer
11 views

(goroutine leaks) http.TimeoutHandler does not kill respective ServeHTTP goroutine

Timeout handler moves ServeHTTP execution on a new goroutine, but not able to kill that goroutine after the timer ends. On every request, it creates two goroutines, but ServeHTTP goroutines never kill ...
0
votes
0answers
6 views

How to update DNS records using GO

I need to write some code in GO that dynamically updates DNS entries. I've tried to follow this documentation: https://godoc.org/github.com/miekg/dns#hdr-DYNAMIC_UPDATES I have little experience with ...
0
votes
0answers
5 views

apache kafka consumer resume behaviour

I am currently working on Apache Kafka using go/golang confluent library. I have some doubts regarding consumer and its APIs. I am using pause and resume APIs of the library and doing manual commits. ...
0
votes
0answers
10 views

Creating a dynamic filter with mongo-go-driver

I want create a dynamic filter with the mongo-go-driver. For example, I have this documents: { "_id":"5d1231380a2a2b39a99c3ed1"}, "name":"flower.png", "colors":["#ffffff","#212121","#999999","#...
0
votes
0answers
26 views

Logging SQL queries

Our go code is organized like this. We have MySQL struct type MySQL struct { mysqlDB *sql.DB db sqlbuilder.Database logger service.logger } Our repository type ServiceRepo ...
0
votes
0answers
11 views

Golang add excel sheet to PDF file

I did not find libraries on golang, I tried to first convert to xps using go-ole cwd, _ := os.Getwd() ole.CoInitialize(0) unknown, _ := oleutil.CreateObject("Excel.Application") excel,...
0
votes
1answer
20 views

How do I run a .msi file using golang?

I'm writing a function that will run an msi file by taking in the applications path as a parameter. Right now the function is returning an error code stating that the application's path is not a valid ...
0
votes
1answer
54 views

How to access a JavaScript object as an array

In GopherJS, members of an object are themselves objects (just as js handles things under the hood, ttbomk). So when accessing a member, one gets back a *js.Object: func makeRID(o *js.Object) string ...
0
votes
0answers
20 views

Goland IDE - Tests Coverage

I'm recently using the Goland IDE and I'm having trouble getting the test code coverage. In the package, I right-click and click on 'Run with coverage'. The tests are run but I always get as a result: ...
-1
votes
1answer
17 views

Viper is not considering the yaml tags in my structs on unmarshalling

when I use the Unmarshal method of viper to fill my config structs with the values in my yaml file, some of the struct fields became empty! I do it in this way: viper.SetConfigType("yaml") viper....
-1
votes
1answer
27 views

How should I avoid multiple implementation of my methods in a micro service architecture

I am working in a microservice architecture ( my first one ), in Golang, and I find myself duplicating Models definition over several services. What can I do to avoid this? I can only think to ...
0
votes
0answers
22 views

generate otp code not working in different pc

I try to generate and validate otp code, this is my current code : package main import ( "github.com/pquerna/otp/totp" "bufio" "fmt" "time" "os" ) var SecretCode string = "...
0
votes
1answer
27 views

Mocking MongoDB response in Go

I'm fetching a document from MongoDB and passing it into function transform, e.g. var doc map[string]interface{} err := collection.FindOne(context.TODO(), filter).Decode(&doc) result := ...
-3
votes
0answers
34 views

Golang closing a reader channel [duplicate]

In this article about implementing Worker pool using channels and goroutine. I was able use this as a base for my own worker pool implementation which makes http calls to a remote service. The code ...
-3
votes
1answer
47 views

Deserializing JSON numbers returning incorrect values

I want to deserialize json strings with the go language. The value types of different keys are different. for example,in string {\"category\":\"6\",\"cid\":2511993760745787586},category type is string,...
0
votes
2answers
38 views

omit type of array in a function argument with golang [duplicate]

I'm writing a write method, to write an array of value to InfluxDB What I would like is to be able to have something like: func (influxClient *InfluxClient) Write(myArray []interface{}) (error) { ...
-1
votes
0answers
28 views

Transfer large file via gRPC Streaming

I am getting nil pointer dereference error while transferring file more than 1MB in receiver side. panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: ...
-2
votes
1answer
29 views

What is the proper style and usage of golang Context?

I am new to golang and trying to get a better understanding of context. In the below snippet, it appears to me that I've instantiated my computeService with a context. why do I have to pass it again ...
0
votes
0answers
33 views

How to backup the one row from the sql database?

I want to make a backup sql data function in golang. I have written a sample code which will backup the sql database and a command for table too. But I don't know that how to dump the one row data ...
-2
votes
0answers
11 views

How to set golang.http.Header with chromedp.network.Headers into?

Chromedp use network.Headers to strore response headers as keys / values of JSON object : type Headers map[string]interface{} I would like to store the network.Headers values into http.Header. ...
3
votes
0answers
28 views

Deserializing ObjectMeta Regardless of Kind

TL;DR: How can I flexibly decode a k8s API object and inspect its top-level metav1.ObjectMeta struct without knowing the object's Kind in advance? I'm writing an admission controller endpoint that ...
-5
votes
0answers
35 views

why there call `next.ServeHTTP`?

there is a middleware. I can't understand ,why call the next.ServeHTTP function after log.Pritnf func loggingHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http....
-5
votes
0answers
56 views

panic: runtime error: index out of range in Golang

I have a function, which has to assign the index corresponding to rune of character to 1. I have a slice of alphabet, another slice of bytes with length of alphabet and for example, word "adel" will ...
-4
votes
0answers
30 views

Is there any go tutorials or documents about inferencing tensorflow model? [on hold]

I'm trying to serve tensorflow model in golang. But cannot find any tutorials or docs about it. I wrote model in tensorflow 2.0.
-2
votes
1answer
37 views

golang find first element smaller or equal to given element using sort.Search

golang find first element smaller or equal to given element using sort.Search() if the array is sorted in ascending order. Note: I do not want to sort the array in descending order to use the sort....
0
votes
0answers
28 views

InfluxDB recipe for Yocto Fails with devtool workflow in Rocko

I wish to add InfluxDB version 1.7.6 to my Single Board Computer from PHYTEC and did the following initially: create initial recipe using devtool devtool add influxdb https://github.com/influxdata/...
0
votes
1answer
14 views

Artifactory jfrog cli unable to authenticate

Attempting to use the jfrog cli to integrate with an artifactory server, when I get this error jfrog rt config example-company --url=$ARTIFACTORY_URL --user=$ARTIFACTORY_USER --password=$...
0
votes
0answers
26 views

Bitbucket Cloud `go get` support? [duplicate]

I want to use go get with a project hosted on private Bitbucket cloud. I have ssh configured so that the following works without manually entering credentials: git clone [email protected]:<team-...
1
vote
1answer
21 views

Deploying services in GKE k8s cluster using Golang k8s client

I'm able to create a GKE cluster using the golang container lib here. Now for my golang k8s client to be able to deploy my k8s deployment files there, I need to get the kubeconfig from the GKE ...
0
votes
2answers
22 views

How do I create a text index in mongodb with golang and the mongo-go-driver?

I'm trying to do a full text search on a collection, but in order to do that I need to create a text index. How can I create a text index on two fields? I know that I must use a thing as this: opts :...
1
vote
1answer
26 views

Where should i store the endpoint of the service registry server?

I'm learning about microservices recently. I tried using consul for service discovery. I wonder if I deploy the consul server, so where should i store endpoint of that server? Is it good to hard code ...
0
votes
1answer
76 views

go http.Request.Conn.ActiveConn is a map, so will it have concurrent map problem?

go http.Request.Context.ActiveConn is a map, will it have concurrent map problem? If there are many connections, I print the request.Context which is including a ActiveConn(map), will it have ...
-2
votes
0answers
30 views

What is GoModule basically and does it help import my custom packages outside/inside my GOPATH?

So, I am a newcomer in Golang. I have so far been using vendoring strategy for maintaining package dependencies. Now, I came to know about Go Modules, watched a few videos on youtube, seemed quite ...
0
votes
1answer
54 views

Marshal json file into map

I have a largish (10mb) JSON file which I am attempting to unmarshal into a map so I can read it from memory when required. My problem is that I can't figure out how to key the map by the id of each ...
0
votes
1answer
24 views

Is it possible for stackdriver to recognise syslog input from k8s?

Unable to get stack driver to recognize syslog levels. Everything appears as an error despite specifying DEBUG logwriter, e := syslog.New(syslog.LOG_DEBUG, "myprog") if e == nil { log.SetOutput(...
-1
votes
0answers
25 views

Simulate Regex Lookaround in Golang

How can I get anything that doesn't match a specific sequence with regex in Golang? The character class [^abc], for example, match anything that is not a, b or c. I would like to know if there is a ...
1
vote
1answer
38 views

Getting an exception when calling Syscall function

I am using Go's syscall package to call a DLL that is written in C++. C++ method signature looks like this. init(int* buffer, int argc, char* argv[], const char* fileName, const char* key, const ...
0
votes
1answer
29 views

How to pass flags as argument of urface/cli command?

I am using urfave/cli to build a CLI application in Go. What I would like is options given after the first command to be treated as arguments and not flags (so that I can handle them myself or pass ...
0
votes
0answers
18 views

Managing interrelated goroutines death? [duplicate]

I am pretty sure that this is a common problem. Assume there is some dieChan := chan struct{} that is used to signal death of some gorutine A. So it might select, where one of the cases is case <-...
-2
votes
0answers
14 views

How can i send nested json in response api using go and gorilla? [duplicate]

I receive data from apis, I parse it and I try to send json response from nested structure with gorilla. But when i build the response json, it's like empty field : { "data": [ {}, ...
0
votes
1answer
41 views

Why this function can not exit? [duplicate]

I try to run the main function but it can not end. I don't know why. func main() { tick := time.Tick(1 * time.Second) done := make(chan bool) go func() { for { select {...
-1
votes
0answers
45 views

net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

I am trying to scrape a list of urls which are stored in a file separately. I am using goroutine for every url visit, but I am passing the same http.Client to all the requests, thereby creating a ...
0
votes
1answer
23 views

Getting fork/exec /var/task/main: permission denied: PathError while accessing Lambda function [on hold]

I have created a lambda function and an Api Gateway integrated with it. While accessing the Lamda Function created, I am getting "fork/exec /var/task/main: permission denied: PathError" error. I am ...
1
vote
1answer
47 views

Why mongo-go-driver aggregation result object keys returned as “Key”

I want to group some data with mongo-go-driver using aggregate, but the json result confused me, because the row key replaced with "Key" and and the real key become the "Key"s value var result ...
-3
votes
1answer
43 views

golang io.writer new line after finished writing string

I have the following code that uses a package to draw a progress bar type tmpStruct struct { } func (t *tmpStruct) Write(p []byte) (n int, err error) { fmt.Fprintf(os.Stdout, "%s", string(p)) ...
-4
votes
0answers
39 views

How to use html templates in golang [on hold]

i want to use html templates in golang like login and registration forms and also the website home page but can't. There is any tutorial about this
0
votes
0answers
129 views

generate rsa key valid for dkim validation

I am tring to generate dkim key using golang, my current code is : package appdkim import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/asn1" "encoding/pem" "fmt" "...
-1
votes
0answers
29 views

A process stops if there is looping in goroutines [duplicate]

If I execute the below code, the process will stop after the repetitive print process. Why does the program stop? GC stops that? I'm a beginner of golang. Thank you for any help you can provide. ...
1
vote
1answer
31 views

How to fix concurrent merge sort in go

I am trying to learn go lang and facing problems in implementing merge sort concurrently. It is not sorting the array properly I have tried finding any race conditions and also tried printing at ...
-1
votes
0answers
26 views

Questions with golang exec.Command()

I am running an endpoint to receive and execute Windows command sent via post request. The main codes are as follows: glog.Infofln("command: %s\n", cmd) --cmd is the command to be executed. ...