Questions tagged [go]

Go is an open source programming language initially developed at Google. 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 ...

1
vote
1answer
14 views

golang ParseQuery url gives me wrong output

I have the following code: func init() { today := time.Now() // If ENDPOINT is empty, It'll use this hardcoded endpoint. The ENDPOINT variable should not contain any text after "ModifiedDate ...
0
votes
1answer
17 views

execute self unmarshal method or default unmarshal method base on condition in golang

I am a novice in golang. I have a struct Item . type Item Struct{ ... } and I know it has a default UnmarshalJSON method. Now I want to unmarshal data to it. For the data may has two different ...
-4
votes
0answers
31 views

Migrating a service from one language to another [on hold]

I'm tasked with rewriting a clunky C# package in Go. Obviously this isn't a case of just using a code translator (since the two languages encourage completely different approaches and solutions). I'...
-5
votes
0answers
18 views

golang generate image with arabic text [on hold]

I have a project that will require generating image with Arabic text embedded in the image to be pushed into an E-ink display. does Golang capable of doing that and how? Ali
1
vote
2answers
45 views

What is idiomatic way to get string representation of enum in Go?

If I have an enum: type Day int8 const ( Monday Day = iota Tuesday ... Sunday ) What is more natural Go way to get string of it? fucntion: func ToString(day Day) string { ... } ...
1
vote
0answers
21 views

How to determine the ephemeral port chosen by Go http ListenAndServe

With http.ListenAndServe(), I can start a webserver in Go. When the addr string is :0, it will, as expected, let the OS pick an ephemeral port. When I run netstat -nptl, that port shows up just fine. ...
-4
votes
1answer
15 views

How use one byte buffer as key storage for map?

How use one byte buffer as key storage for map without copy? func TestMap(t *testing.T) { testMap := make(map[string]int) //byteKey := make([]byte, 2) //byteKey[0] = 0 byteKey := ...
0
votes
2answers
34 views

go routine for range over channels

I have been working in Golang for a long time. But still I am facing this problem though I know the solution to my problem. But never figured out why is it happening. For example If I have a pipeline ...
-1
votes
0answers
8 views

Error: Unable to access goreleaser while trying to setup the environment

I am trying to build a project using GoReleaser. To do that I am following the official tutorial given in www.goreleaser.com however, I am facing issues while trying to access GoReleaser when I put ...
-1
votes
1answer
20 views

Goland can't get the correct current path when run and debug?

When I invoke the following code, func GetCurrentDirectory() string { dir, err := filepath.Abs(filepath.Dir(os.Args[0])) it returns: /private/var/folders/cg/mwzlhrjs5y55ny553g6xz9tr0000gn/T ...
-2
votes
0answers
17 views

Per-request scoped thread safe object

What is the best way to create per-request scoped(for new request - new object) thread safe object in Golang?
-1
votes
1answer
32 views

how to pass dynamic parameter in the REST API url using golang

I am getting the encoded url from postman (google api). In the url, I have the query written to fetch info from a db. In the query, I have hardcoded the date parameter for which I want to fetch the ...
-5
votes
1answer
31 views

Cannot convert time.Now() to a string

I have this struct: // Nearby whatever type Nearby struct { id int `json:"id,omitempty"` me int `json:"me,omitempty"` you int `json:"you,omitempty"` ...
-2
votes
1answer
19 views

A slice has only one element, named list, why can subslice list[1:] work?

A slice has only one element, named list, why can subslice list[1:] work? For example: list := []int{1} fmt.Println(list[1:]) fmt.Println(list[1]) The list hasn't the element with index 1, so the ...
0
votes
1answer
20 views

Assign local result to outer scope

I have this block of code. The problem is in the func, I am trying to assign to the db var in outer scope, but it ends up being declared as a local variable. var db *sqlx.DB func ...
1
vote
0answers
29 views

Golang equivalent of Java's SHA256withRSA

Is there any Golang equivalent of Java's java.security.Signature's SHA256withRSA? A couple of research is that I could not simple calculate the SHA256 hash and then signing it with RSA. I have done ...
1
vote
1answer
31 views

Export imports with Golang

Not sure if this is impossible with Golang. With Node.js, I would do it like so: import * as person from './person'; export {person}; with Golang I have models.go: package models import ( "...
-1
votes
1answer
30 views

Too many arguments to return

I have this golang file: package main import ( "log" "sync" "github.com/jmoiron/sqlx" ) var db *sqlx.DB var once sync.Once // GetDBConnection whatever func GetDBConnection() { ...
0
votes
3answers
34 views

Automatically import 3rd party go packages

I am a newbie to GO lang and was wondering if there is a way to automatically download all the imports. So let's assume I need to use github.com/gorilla/mux and several other packages in my code base. ...
0
votes
0answers
36 views

How can I reference a struct in a parent directory?

I have a file structure that goes like this: config/ config.go utils/ utils.go utils.go needs to access a struct in config.go called Lapse. When I try to import config, I get an error that ...
0
votes
1answer
30 views

Concatenating a string to a slice of structs

I'm trying to create an endpoint Go API to be consumed by front end JavaScript graphing library. What should happen: /data endpoint to get an array of JSON data. The data is just a slice of go ...
0
votes
1answer
18 views

how to pass in multiple values into a template to run a query

Options I have web app with a search bar. The search bar accepts customer_id's and runs a query to a redshift cluster with the customer_id as a filter. I need to be able to input multiple customer id'...
1
vote
2answers
43 views

How to print UTF-8 (or unicode) characters in Go (golang) on Windows

Let's have a look at this: ✓ Hello, 世界 As you can see there is a unicode checkmark and chinese/japanese characters. In go, If I use MSYS or linux environment i can easily print those characters. ...
-2
votes
0answers
26 views

How to prepare string to RFC3339 on golang? given YYYY/MM/DDDD with UTC “-10:00” or “+01:00”

I currently receive a date string like this 2018/10/22 and a UTC representation: Case A)+02:00or Case B)-10:00 So when I try: // for case A) 2018/10/22 UTC +02:00 time1, err := time.Parse(time....
1
vote
1answer
20 views

How do I add custom tracing to a second-generation App Engine application in Go?

Google App Engine now supports Go 1.11 via the new second-generation standard environment. While converting an older standard environment application to the second generation, it wasn't obvious how ...
-3
votes
1answer
21 views

How and when is the Go sdk logger flushed?

I'm trying to determine if the default/sdk logger log.PrintYYY() functions are flushed at some point in time, on exit, on panic, etc. I'm unsure if I need to find a way to flush the writer that the ...
0
votes
0answers
41 views

Run process and notify when finish

Im using the following code which works fine, Now I want to notify to when the process finish I try to add another function after the wait and it doesn't helps I need to know when all the commands ...
-2
votes
1answer
35 views

Getter in GoLang [on hold]

I have a custom type named ProtectedCustomType and I don't want the variables within that to be set or get directly by the caller, rather want a Getter / Setter methods to do that. Below is my ...
1
vote
2answers
29 views

Google Storage : how to check if a bucket exists

Using GoLang SDK for google cloud storage.... Cannot find a method to check if a bucket exists. func (c *Client) Bucket(name string) *BucketHandle Bucket returns a BucketHandle even if bucket does ...
0
votes
0answers
13 views

How can I get a PeerInfo from a Host?

I'm trying to get a PeerInfo from a libp2p.Host instance. I'm able to get a list of multiaddr.Multiaddrs by calling Host.Addrs(), but I'm unable to convert these into a valid peerstore.PeerInfo. ...
0
votes
1answer
21 views

Append new sub document to an array in the main struct

I have the following go structs in my MongoDB database: type Station struct { ID bson.ObjectId `bson:"_id" json:"id"` Name string `bson:"name" json:"name"` Sensors ...
-7
votes
2answers
137 views

Why is swapping elements of a []float64 in Go faster than swapping elements of a Vec<f64> in Rust?

I have two (equivalent?) programs, one in Go the other in Rust. The average execution time is: Go ~169ms Rust ~201ms Go package main import ( "fmt" "time" ) func main() { work := []...
-2
votes
1answer
41 views

Golang switch for a types returning boolean values [on hold]

I've the following function which works OK, But I wonder if there is cleaner way to write it in Golang the function get a flag and according to the value(string value) provide two Boolean response (...
1
vote
0answers
11 views

Automatic version bumping on Azure DevOps (like Jenkins+Maven)

In Jenkins+Maven, there is the possibility to automatically bump the version of software using a plugin. For example, the current version in the pom.xml might be 1.0.0-SNAPSHOT. When the plugin is ...
0
votes
1answer
56 views

Setter in GoLang

Sorry for the basic question. I am new to GoLang. I have a custom type named ProtectedCustomType and I don't want the variables within that to be set directly by the caller, rather want a Getter / ...
-7
votes
0answers
44 views

Go net/http package request is always nil [on hold]

My http request body is always nil. I am using POST request to send the data using postman. But my r.Body is always nil. Hence the request never gets decoded. And i am not sending my POST data through ...
-1
votes
1answer
58 views

Golang paralelism

I've been recently reading a lot about parallelism and concurrency in Go, and I can't wrap my head around it. When I was reading this article about concurrency and parallelism in Go, I've came across ...
-8
votes
0answers
35 views

Go compiled file deployment [on hold]

I have generated the compiled (.exe) file for a go web server. I wanted to know how to deploy it as a .exe file itself and not as source code. I have searched App Engine and heroku but both don't ...
-3
votes
1answer
50 views

Why finalizer is never called?

var p = &sync.Pool{ New: func() interface{} { return &serveconn{} }, } func newServeConn() *serveconn { sc := p.Get().(*serveconn) runtime.SetFinalizer(sc, (*serveconn)...
-5
votes
0answers
36 views

Defer in Golang Programming Language [duplicate]

I found the code func main() { fmt.Println("Go MySQL Tutorial") // Open up our database connection. // I've set up a database on my local machine using phpmyadmin. // The database ...
-5
votes
0answers
33 views

RabbitMq protobuf

I'm working on a project were we use GRPC. I would like to implement async events using RabbitMq. I'm looking for a Go library where I can publish to a RabbitMq broker a protobuf message, that way we ...
0
votes
1answer
26 views

How to send FulfillmentMessages as part of Dialogflow v2 WebhookResponse?

I'm trying to send back fulfillment messages as part of Dialogflow's v2 API WebhookResponse. This works: Sending only a FulfillmentText as part of my response works fine (Testing the app in the ...
0
votes
1answer
29 views

Alternate way to set credentials for GOOGLE_APPLICATION_CREDENTIALS

I've a Go app that uses the Google Vision API and Google Video intelligence API. To enter my credentials, I set the environment variable called GOOGLE_APPLICATION_CREDENTIALS. To do so, I assign a ...
-2
votes
1answer
46 views

About Map in Golang Programming Language

I found the code newMap := map[string]interface{}{ "string1" : 1, "string2" : "hello", "string3" : map[string]string{ "hello" : "hello there" } } My guess is that If we use interface ...
1
vote
1answer
60 views

Taking input when executing binary in Go

I am using below code snippet :- command:= exec.Command("./"+order) out, err := command.Output() if err != nil { log.Println(err) } fmt.Println(string(out)) here, "order" is the variable with ...
0
votes
1answer
24 views

crawl a site with jsoup and make json in golang

I wanna crawl a site (bbs.archusers.ir) for making a new post or topic notification for users. I try to write below code for a reading name, last change date, and URL every section and save into ...
-6
votes
2answers
60 views

&http.Client in Golang, Need Explanation

I found the following code client := &http.Client What does & mean? What kind of value that client var receives
-2
votes
2answers
47 views

Creating objects dynamically based on a string

I'm trying to dynamically create structs based on a string. In the below example reflect.TypeOf &c and &c1 are different because I return interface{} from makeInstance. TypeOf c and c1 are ...
0
votes
0answers
29 views

go lang tests structure- tests takes too long using ginkgo

I am new to go lang, and i have a question regarding the structure of the project. let says i have a the following project structure. myproject package1 mycode.go mycode_test.go ...
-3
votes
1answer
51 views

Goroutines run inside another function

It may be a silly question, but I just wonder, code: func sumNumber(value int){ array1 := []int{3, 6, 7) for _, v:= range array1{ go anotherFunction(v) // goroutine function is run ...