Most voted "golang" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the Go programming language. Go (also known as Golang) is an open source programming language initially developed in Google, high-level, with strong, secure, nominal and structural typing, manifest or inferent, essentially imperative paradigm and which has competition mechanisms.
Learn more…111 questions
Sort by count of
-
20
votes2
answers1104
viewsHow is Garbage Collection implemented in Go?
In Golang saw that this language is compiled (and indeed, the website itself tells for which architectures the compilers generate code), and, to my surprise, is Garbage Collected! Garbage Collection…
-
14
votes2
answers2381
viewsWhat is the difference between static and dynamic linkage?
Recently, searching why small Go codes have a much larger executable than the same C-generated code, I read an answer stating that the reason is because Go use linkage static, unlike C, which uses…
-
10
votes1
answer2503
viewsWhat are the main features of the Go language?
I started to hear a lot about Golang and is increasingly gaining ground among the most widely used programming languages. As far as I know, I think it’s a programming language. So, What are the main…
-
8
votes2
answers171
viewsIs there a way to execute a single command as an administrator (other than the entire program)?
Did not want to run the entire program with administrator privilege, for security reasons and for convenience. However I need to execute a command: exec.Command(`cmd`, `/c`, `CheckNetIsolation.exe`,…
-
5
votes1
answer647
viewsConnecting Go with Mongodb using Docker
I am creating a microservice in Go, using Mongodb as a database and using the library mgo. Using Mongodb in a Docker container locally and running the application on my machine, everything works…
-
4
votes2
answers185
viewsIn what order is the init() method invoked in the GO language?
I read some posts on the Internet about the implicit method call init() but I did not understand right in what order it is invoked in a program written in GO language, mainly because there can be…
-
4
votes2
answers212
viewsWeb server in Go apparently is not creating new requests
I am now starting to develop in Go, and I am currently studying Go for Web development, so through examples I started a simple server in Go: package main import ( "fmt" "log" "net/http" "time"…
-
4
votes1
answer410
viewsGolang - Doubt about pointers
I have a struct called Calculator, with two properties: version and author. To be able to instantiate this struct already initiating these methods, since Golang has no constructors, the various tips…
-
4
votes1
answer221
viewsCapacity of schools in Golang
One Slice can vary with the need and can add items to it, right? It is possible to view the size and its capacity (len and cap, respectively). In the tour by Go, there is a "lesson" from append,…
-
4
votes1
answer86
viewsWhy is creating a variable size Slice slower?
Using the make([]byte, tamanho) he has a different behavior when the tamanho is a variable or a constant. Consider the two codes: package Testes import ( "testing" ) func BenchmarkConstante(b…
-
4
votes1
answer54
viewsPayload blank return when performing return to WEB application in Golang
I am checking in the API if the user’s email is already registered and returns a warning message. Even performing the requests the payload returns empty. Even debugging and knowing that the payload…
-
4
votes1
answer49
viewsHow to know if the "Windows animations" option is disabled in Win32?
In the CSS there is the prefers-reduced-motion. This media-query says that the user prefers reduced animations (off) or not, it respects the configuration that the user chose in the Windows settings…
-
3
votes1
answer262
viewsIntegrate nodejs (frontend) and C ,Erlang, Go...(backend)
I have a system to be developed that will need to handle a lot of simultaneous requests, where each of these requests will probably involve some task that requires a lot of processing. Researching…
-
3
votes1
answer95
viewsReferencing variables in HTML
I am a beginner in web programming and I have a very simple question (I believe): I was wondering if there is any way to reference variables of a backend language (in my case I’m using Go-lang) in…
-
3
votes2
answers362
viewsCount golang number size
I have a variable int, I need to know how many houses she has and capture the number for each house, for example my number is 57890, I need you to return the house quantity of that number, 57890 =…
golangasked 7 years, 6 months ago Rodrigo Bruno de Oliveira 41 -
3
votes1
answer124
viewsWhy does Illegal Invocation occur in JS?
I’m using Gopherjs, and in it there are two ways to perform a function, via Call() or via Invoke(). Initially it was using a code similar to this:…
-
2
votes2
answers396
viewsGolang language
I’m entering the market now, and I’m doing an internship at a development company. I have some questions about the language of Google, Golang (Go), are they: Is there anything ready regarding AES…
golangasked 7 years, 6 months ago Augusto Teixeira 21 -
2
votes1
answer34
viewsCheck Unix user
To check the user name I can easily use: import ( "fmt" "os" ) fmt.Println(os.Getenv("USER")) But to make things a little easier I’d like to add a new role to struct os, so I did it this way: func…
-
2
votes1
answer173
viewsHow to pass parameters to a function all rows of an array
I need to pass all lines of an array as parameters of a function, but I can’t leave it dynamic... What I want to leave dynamic args = append(args, u.yy) args = append(args, u.xx) args = append(args,…
golangasked 6 years, 4 months ago Gabriel Souza 728 -
2
votes1
answer235
viewsAccuracy of float64
Why Go when performing the calculation: (1 * 0.09) + 0.36 returns a float64 in the following format 0.44999999999999996? I’m trying to make comparisons with tests and the calculation should be 0.45…
-
2
votes2
answers84
viewsHow to get the name of a variable as a string in Go?
Is there any way to get the name of a variable in Go as string? var progzila int As I could get variable name above, it is possible?
-
2
votes2
answers115
viewsProblem capturing the title of a URL using regular expression
I’m learning Go language in the competition part. I had the challenge of using the Generator standard to get a Channel that reads the title of a URL through a goroutine. Inside this goroutine that I…
-
2
votes1
answer79
viewsDetermine the memory consumption
Hello, I’m a beginner in Go and I’m having a hard time determining how much memory the Go code took to execute some code. I made the memory() function that even returns something, but I don’t know…
-
2
votes0
answers29
viewsLogin with GORM with intercalated return between ID and 0
Guys, I’m learning to code in the GO language, and I made an api with a login system. func Authenticate(db *gorm.DB, auth models.UserAuthForm) uint { hasher.Write([]byte(auth.Password)) pass_hash :=…
-
2
votes4
answers254
viewsSet Golang Standard Timezone
Is there any way to set a standard Timezone (Location) in Golang so you don’t have to be on time? I am currently manually setting the Timezone every time I need to work with Time using it: loc, _ :=…
-
2
votes1
answer273
viewsDo a get with optional parameters in Golang
I need to do an api where query using optional query string parameters. I tried something like: func (app *App) getFunctionarys(w http.ResponseWriter, r *http.Request) { v := r.URL.Query() Id :=…
golangasked 5 years, 5 months ago veroneseComS 2,752 -
2
votes0
answers42
viewsGolang 1.15.7: Return of a Shared library using *C.char
I’m trying to create a Shared library in go, but the return (*C.char) always comes back empty: How to do to return right? package main import ( "C" "fmt" ) //export Upper func Upper(palavra *C.char,…
golangasked 3 years, 11 months ago João Bueno 21 -
2
votes1
answer43
viewsHow to create a module for a specific folder?
opa, all right? I tried to create a module in Go language in visual studio. The module refers to a folder called "1 - Packages". but when I write the code only appears this. I’m starting in…
-
2
votes4
answers184
viewsHow to set a GET request header in Golang
I’m trying to make Golang my first mid-high level language, but I’m having some problems. I can’t set a header for an external GET request at all, I searched the documentation, forums and the only…
-
1
votes2
answers317
viewsPersist JSON Postgres / Golang
Hello, is there any way to persist a JSON in postgres with the GO language? I don’t want to do a manual Insert, I want to map my JSON with a struct and persist, similar to Hibernate in Java. found…
-
1
votes1
answer77
viewsHow to show reason for error 422 in GO
Lately I’m breaking my head too much to debug the POST and PUT requests where HTTP 422 error always occurs (Incorrect input format) In my project I am using the GIN framework to make a JSON BIND…
golangasked 7 years, 11 months ago Wilson Tamarozzi 382 -
1
votes2
answers181
viewsvscode removing Imports when saved file
I have a very simple code in GO. Using vs code, when saving the file I’m working on, the editor removes the import "math" Follows the code package main import "math" func main() { a :=…
-
1
votes2
answers114
viewsIs there any way to force you to ignore errors in Go?
Golang forces us to manually remove unused items in the code, for example: for index, item := range retorno.Threads { fmt.Fprint(w, item.Id) } If you run a go run .... he will say: index declared…
-
1
votes1
answer130
viewsWhy does this goroutin loop just repeat the last value?
This loop is always repeating the last value, consider the following: type unique struct { id, nonce uint64 } func (unique *unique) print() { fmt.Println(unique.id) } func main() { teste :=…
-
1
votes1
answer370
viewsReturn values in time format
I own a struct with 2 ints and I need to return these values in string but in time format. type Clock struct { hour int minute int } func New(hour, minute int) Clock { return Clock{hour, minute} }…
-
1
votes1
answer65
viewsUsing Fileserver to share files
I am learning Golang and to practice I am doing some small "projects", my idea is just to share a folder of my Windows or some file through my local wifi network using the net/http package of…
-
1
votes1
answer218
viewsUse function in another Golang folder
I created a pacote inside $GOPATH/src/github.com/meu-user/meupacote with a file meupacote.go who has the function main and another folder with the name productsthat holds the file products.go, in…
-
1
votes1
answer133
viewsConvert multiple nodes to XML for struct
I looked for some examples in the official documentation of golang and in some online tutorials but only find simple examples see: <data> <person> <firstname>Nic</firstname>…
-
1
votes0
answers39
viewsHow to export package documentation with css using godoc?
After writing my package I know it is possible to generate an html page with all the documentation provided through comments in my code; godoc -html github.com/user/package > index.html But the…
-
1
votes1
answer233
viewsUse same package function with Golang
Within my project I have 2 files, main.go and price.go; in my file main.go within the function main() i tried calling a file function price which is exportable (starts with uppercase letter), and…
-
1
votes1
answer44
viewsDate range by week number
With this simple function, I can get the week number. Now, with the week number, how can I get the date range, started on Sunday? import ( "fmt" "time" ) func main() { Week(time.Now().UTC()) } func…
-
1
votes1
answer146
viewsHow to accesar map coming from a JSON without creating structs?
After taking some data from an endpoint I get passes to a variable of type interface{}; var example interface{} err := json.Unmarshal(payload, &example) If I run a fmt.Println(example) have the…
-
1
votes1
answer202
viewsHow to update column for each SELECT in a given table?
I tried to create a trigger for a table using for it to be activated after each select, but researching a little I discovered that it is not possible to create triggers for selections, only for…
-
1
votes1
answer34
viewsWhy does JSON or XML not work?
I got this guy: type S struct { a string `json:"a" xml:"a"` b int `json:"b" xml:"b"` c time.Time `json:"c" xml:"c"` } But neither JSON nor XML works: s := S{a: "Olá", b: 42, c: time.Now()}…
-
1
votes2
answers306
viewsGo function with parameters
I came across the following function in a framework of Map Reduce, but I didn’t understand her syntax. func (fc *FlowContext) newNextDataset(shardSize int, dType reflect.Type) (ret *Dataset) { ret =…
-
1
votes1
answer77
viewsHow does the Deploy process in Golang work?
Situation In my company we are starting a technology exchange process. And one of the suggested was Golang. And one of the biggest obstacles is the deployment process. Experiments In PHP, even being…
-
1
votes1
answer110
viewsCapture Timeout on GET request
In my code I have an "attempt" to capture the timeout of the method Get package http but for some reason the mistake is not captured and a panic is displayed saying: Get…
-
1
votes1
answer55
viewsPass sql.DB pointer as method parameter
I have a struct that has a method save receiving as parameter a pointer for access to the seat; func (c Call) Save(db *sql.DB) error { stmt, err := db.Prepare(` INSERT INTO calls values($1, $2, $3,…
-
1
votes1
answer76
viewsReturn Dynamic Struct in Go
How could a dynamic return in Go using struct ? Example : func teste() (*struct, err){ type t struct { } return t, nil } The problem is that I would not like to create a struct for each method that…
-
1
votes1
answer139
viewsFunctions with different return in Go
I need to create an interface that contains a method decode(), but I need it to return different things to every struct that uses this method, and I don’t know how to do that. type teste interface {…