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

59,466 questions

0
votes
1answer
12 views

Define golang struct as type with arbitrary fields?

I'm very new to golang and the use of interfaces more generally. I've stubbed out some code here: type Alerter interface { Alert() } type AlertConfig struct{} type Alert struct { Config *...
0
votes
1answer
29 views

Simplify recurring switch cases in golang

I am trying to understand if there is a better way to simplify recurring switch cases in golang. I have a method that can return multiple errors, but I am interested in 3 specific errors where I need ...
0
votes
0answers
12 views

Alternatives to samba libnet library [closed]

We have a use case where we need to create remote users via code in linux Now, in samba theres a "libnet" API which performs those exact operations, however samba is GPLv3 and thus ...
1
vote
1answer
27 views

TypeOf with Comparable in errors.Is

I am learning how error comparison works in Go and found something I cannot understand. Function errors.Is(err, target error) checks if target is Comparable. func Is(err, target error) bool { if ...
-1
votes
0answers
33 views

What's the point of newtyping go interfaces instead of aliasing them?

In Go, interfaces are implemented by duck typing. This means two interfaces types with identical signature are assignable to one another. For example, type A interface { Foo() } type B interface { ...
-2
votes
0answers
11 views

fabric typescript to golang

Here is the link:https://hyperledger-fabric.readthedocs.io/en/release-2.4/write_first_app.html The example which you show ,it‘s suit for typescript but not golang,and fabric-samples/asset-transfer-...
0
votes
1answer
6 views

Beego NewLogger channelLens value

Can someone help me understand the significance of channelLens value in Beego NewLogger function. The documentation says channelLen means the number of messages in chan(used where asynchronous is true)...
-1
votes
1answer
22 views

Attempt to do TLS over UDP: wsarecv error about large message

I want get tls conn base on udp, just like: package main import ( "crypto/tls" "fmt" "io" "net" "time" ) func handleConn(conn ...
0
votes
0answers
15 views

protoc --go_opt=paths=source_relative vs --go-grpc_opt=paths=source_relative

I am having a hard time figuring out protoc command and go plugin. What is the different between: protoc \ # Directory where you want the compiler to write your Go output. --go_out=. # vs ? ...
2
votes
0answers
37 views

What would be the time complexity of Search Range problem solution DnC

I would appreciate some help in figuring out the time complexity of the solution for Search Range problem from leetcode which involves recursion and DnC algorithm. I am not sure whether it is O(N) or ...
-2
votes
0answers
41 views

Go - is it possible to read/extract LDFLAGS variables passed using decompiler? [closed]

I am building an offline golang application for Windows platform where I am passing a public key as a LD FLAG go build -ldflags "-X 'PUBLIC_KEY=<>'" -o app.exe . This public key is ...
0
votes
1answer
48 views

How to use ENV vars in golang to pass DB connection values dynamically when deployed in kubernetes

I am currently developing a small API in golang which will connect to a sql database. Below is the snip where I am passing the database connection string details statically ( hardcoded in the code ) . ...
1
vote
2answers
41 views

How to interact with another console application using golang?

I'd like to interact with another console application from my own go application. I don't want to write another FTP client, but I'll take the ftp application in this example as it should be available ...
0
votes
0answers
32 views

Is there a way to reload the path from within PowerShell without restarting it used by golang

func New() *PowerShell { ps, err := exec.LookPath("powershell.exe") if err != nil { panic(err) return nil } return &PowerShell{ PowerShell: ps, ...
-2
votes
1answer
37 views

How do I parse the following time in Golang?

What does the layout for parse look like for this timestamp 2021-10-07 12:44:22 +0530? I've tried all combinations and still can't seem to get it right! Thanks for all your help! Btw, this format is ...
-1
votes
1answer
39 views

Golang equivalent to Python Formatted String using F-strings

In python one can use f-string to format strings like this name1 = 'Ele' name2 = 'Ben' name3 = 'Frank' age = 45 print(f"My name is {name1} but i also get called {name2} and at times {name3}. ...
1
vote
1answer
47 views

Golang curve25519 pubkey generator

I'm trying to implement the curve25519 algo for pubkey generation. But I got stuck on how to generate pubkey from sha256 encoded string in Go? I have no problems with generation pubkey from sha256 ...
0
votes
0answers
28 views

Goloang Using Default mux, http.Fileserver producing invalid links. (similar to 46403678)

Actually I'm having exactly the same symptom/issue as question 46403678: The links returned are invalid. The solution posted there appears to require the use of the Gorilla mux: r.PathPrefix("/...
0
votes
0answers
29 views

Saving token in localStorage on Heroku

I have an app deployed on Heroku. The problem is when I run it on Heroku, the value of auth token does not store in browser's local storage (when I run it locally everything works just fine). Here is ...
1
vote
2answers
24 views

404 with http.FileServer with absolute path

I have a file C:\hello\index.go: package main import "net/http" func main() { http.Handle("/assets", http.FileServer(http.Dir("assets"))) println("...
-2
votes
0answers
32 views

Is it possible to programmatically login to a server and then directly to a custom cli interface?

This server requires you to login with a certain admin user and then it prompts you again to login to the custom command line interface. [mymachine]# ssh adminuser@<server.com> adminuser@<...
-3
votes
0answers
34 views

(How) is it possible to reference a function by filename? [duplicate]

I have a main.go file and a directory with a lot of go files in the same package. I want in the main.go file to iterate over all these files and execute a function with the same name as the filename (...
0
votes
1answer
49 views

Go: truthy condition not executing

I am using neo4j in for one of my applications. After running a query if the values are found, result.Next() returns a bool var matches []int fmt.Println(result.Next(), "<== result ...
-2
votes
0answers
89 views

what is going wrong with variable value in Go [closed]

In the belove piece of code, I am re-using podNames variable inside another if block. Initially, len(podNames) is 0, so I do re-try with time.Sleep() inside if block. When I am printing len(podNames) ...
-2
votes
0answers
47 views

Need an algorithm to generate all possible combinations for an array of characters in Golang [closed]

to clarify what i want lets say i have an array chars := []string{"a","b","c"} and i chose n (maximum length of every line of output) i want the algorithm to return all ...
0
votes
1answer
23 views

How to diagnose an ERC20 error "Error: execution reverted" on a local testnet?

I have a local testnet (represented by this Docker image) and I am trying to send some ERC20 tokens from one address to another. I use the following HardHat script for this: npx hardhat run --network ...
0
votes
0answers
22 views

Gorm cascade delete does not trigger associated items hook

Model structure: type Comment struct { BaseModel Description string `json:"description" gorm:"type:text"` PinID uint64 `json:"pin_id" gorm:"not ...
-2
votes
1answer
26 views

cannot use (returned literal) (value of type returned) as []returned value in return statement

I try to return a json object. For that i have a function that return []returned, error : type returned struct { size int64 } func Test(user string) ([]returned, error) { but when i try to return i ...
-1
votes
1answer
61 views

Why we should use a URL for the Go module name?

What is the benefit of using URL for Go module name? E.g: sample.com/learn Is it better than using just a simple name as a module name?
1
vote
1answer
43 views

Is there a simple method for square root of big.Rat?

I need to find the square root of a big.Rat. Is there a way to do it without losing (already existing) accuracy? For example, I could convert the numerator and denominator into floats, get the square ...
0
votes
1answer
36 views

Docker build for Go project with GitLab private repositories

I am having some issues getting my build to work with dependencies in private GitLab repositories. All-in-all it is a multistage build, but the stage where I am attempting to build my Go project is ...
-3
votes
1answer
40 views

How to return an array from reading a file?

I have two columns in a CSV file. I am accessing only the first column using the SearchData() function. The problem is that I want to access the data as an array but when I return an array string in ...
-1
votes
1answer
28 views

How do I analyze a bunch of profiles

I have a bunch of profiles about my application(200+ profiles per week), I want to analyze them for getting some performance information. I don't know what information can be analyzed from these files,...
0
votes
0answers
12 views

Create Android App Bundle (.aab) using gradlew outside of root directory

I'm trying build .aab using gradle. Here's the command: ./gradlew bundle But, if I run the command outside the root project, it causing error. Here's the sample command: ./AndroidProject/gradlew ...
0
votes
1answer
26 views

Golang exec command create file and capture the file output in order to upload to storage object like S3

I'm trying to exec command create file and capture the file output in order to upload to storage object like S3 using golang but I difficulty capture the output file. For specific, I'm trying to ...
0
votes
1answer
37 views

AES GCM decryption failed while decrypting data encrypted in flutter

I'm trying to decrypt the data in golang using the in-inbuild crypto library, the data is encrypted in flutter/dart using steel_crypt library. The specific message that is thrown by the golang's ...
0
votes
2answers
37 views

Cookie is not set at the POSTMAN

Am trying to set a cookie at the POSTMAN by writing the code blow using Golang sub := handlers.NewSunscribers(s) router := mux.NewRouter() router.HandleFunc("/sub/set", sub.SetCookie)....
1
vote
2answers
57 views

Embedding vs. Inheritance in Go

I'm trying to learn Go, but I keep bashing my head against some of its concepts that apply differently compared to other languages. Suppose I have a struct type Vehicle struct { Seats int } I now ...
-2
votes
1answer
44 views

Unmarshalling in-place into a slice type in Go

Often when using go, not sure why, I get the urge to write something like type data []event especially when I know I'm going to be passing the slice around without thinking too much about its ...
1
vote
1answer
47 views

Golang - split string into at most N parts?

Code & problem // parse request, parts := strings.Split(message, ",") uuid := parts[0] data := parts[1] The above code split message by ,, I actually want 2 parts. But the data part ...
0
votes
0answers
10 views

How to get Webview to work with Lantern systray on Linux?

I am trying to launch webview from a system tray icon in Go. I am using github.com/getlantern/systray and github.com/webview/webview. I am trying to create a cross-platform system tray icon that ...
1
vote
1answer
55 views

GO RSA load public key

Hello i was wondering how i could load a RSA public key via a string in GO? I've read a few docs but i cant figure out how i could go about loading it? I don't wanna load via PEM i wanna load via the -...
0
votes
1answer
72 views

Best way to instantly restart a goroutine?

I have written the following functions: func (timer *Timer) ticker() { for timer.time >= 0 { select { case <-timer.stopFlag: return default: ...
0
votes
0answers
26 views

Gin reverse proxy tests failing for interface conversion: *httptest.ResponseRecorder is not http.CloseNotifier: missing method CloseNotify

I build a Go Gin reverse proxy API using this page as a guideline: https://le-gall.bzh/author/sebastien-le-gall/ When I try to run tests, I get an error: interface conversion: *httptest....
-4
votes
0answers
36 views

How to write a basic delete method in go? [duplicate]

type Chores []item func (l *Chores) Delete(i int){ } I have tried using append by saying append(l[i-1], l[i+1]) but there is an error and I'm not sure how to account for the item at the front of the ...
3
votes
1answer
46 views

How can I set correct http.FileServer mime types?

Is there any way to overwrite the content-type used in FileServer? I have simple REST server written in golang, and now i want add some "frontend" in Vue. Html/js files are served from /...
1
vote
1answer
33 views

Golang Cookie Max-Age vs Expire

What is differencies between Expires and Max-Age in Cookie struct ? I cannot understand. type Cookie struct { Name string Value string Path string // optional Domain ...
1
vote
1answer
43 views

How to convert a map to html table in Go

I'm newbie in Go and practicing, could you please help to convert a map to an html table in GO? I have a function that fetches some data from some rest end points and return a map that can vary in ...
0
votes
1answer
23 views

Error loading Golang and Lua plugins in Kong

I'm trying to install a new instance of Kong, but I'm getting the following error trying to start the service: stat /tmp/go-plugins/lua_plugin.so: no such file or directory The installation is ...
1
vote
1answer
21 views

Setting up Neo4J with Golang

I am setting up Go with Neo4j on a live project for one of the microservices I went through the docs around setting up the same but it does not show the best practice to do the same (specifically ...

15 30 50 per page
1
2 3 4 5
1190