Questions tagged [go]

Go is an open-source programming language, with a syntax loosely derived from C. It's statically typed, with limited dynamic typing capabilities; it also features automatic memory management, built-in concurrency primitives, variable-length arrays – called slices –, and a large standard library.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
6 views

Can a golang command line app install postgres and use it?

Can a golang command line app install postgres and create a database unobstrusivly without the user knowing?
  • 295
0 votes
0 answers
5 views

Algorithm to randomize output order of a short array in Go

The key difference between this question and the lots of duplicated answers is that, the input array is short, only 3 elements. -- Say I have an ordered set of int. The size of array is only 3 (or a ...
  • 19.3k
-2 votes
0 answers
10 views

Getting data from Stdout in real time in Golang

In my program, I would like to be able to monitor the execution of some console commands in real time. Here are two examples of code that displays data in real time in the console, but on the web page ...
  • 31
-2 votes
0 answers
17 views

zero-terminated byte slice

Is there a way to define zero-terminated byte slice? Now the best way I see is this: func zeroByteSlice(b []byte) []byte { return append(b, 0) } func main() { f(zeroByteSlice([]byte("...
  • 385
0 votes
0 answers
16 views

Socket.io client (nodejs) not connecting to my Socket.io server (golang)

I'm trying to connect a Socket.io nodejs client to my golang Socket.io server. I'm building an app which will have react frontend and golang backend, and I thought using sockets for the comunication ...
  • 31
1 vote
1 answer
29 views

Sort the inner array using LINQ

I have a two-layer array, the outer layer is already grouped and sorted by shopid, and I want to sort the inner layer by decreasing price without changing the order of the outer layer。 // Inner struct ...
0 votes
1 answer
15 views

Apply handler on permutation, without cache of levels?

I want to write a function that apply given handler to all permutation of input, without return the whole permutation. Code (in go) Find permutation: // apply given handler on each combination, and ...
  • 21.3k
0 votes
1 answer
29 views

casting a generic (interface) to a type when all possible types have same methods

Take the method: x509.CreateCertificate(rand.Reader, &template, &template, publicKey, privateKey) looking at the defitiniton, both publicKey and privateKey here are type 'any'. I don't know ...
  • 3,080
0 votes
0 answers
22 views

How to connect go-admin to Postgres database?

According to the docs of go-admin I have created a configuration for admin panel extension and Postgres database. I use Docker containers, so host is set to "db". The error is displayed ...
  • 71
-5 votes
0 answers
20 views

how do i "require" other script into my library in Golang? [closed]

i have problem to include lib_time inside lib_http, i can put hardcoded using import in lib_http, but because its need app name , it feels ugly. so i want more clear solution. the structure like this :...
-2 votes
0 answers
22 views

Check if typed nullptr is nil [closed]

I have a situation like this var ptr *someType if ptr == nil {} // evaluates to false I get ptr from somewhere else. I do not know if it is a nullptr. I do not know what type it is. How can I check ...
  • 6,445
0 votes
0 answers
13 views

502 Bad Gateway: net/http GET failed with IPSec Tunnel

When making remote GET requests with net/http package through IPSec Tunnel(VPN) on windows, GET request failed with response code 502 Bad Gateway. However request with same headers, uri, method sent ...
-1 votes
0 answers
37 views

I cant create a table column for my database

I need to write REST API then I need to post data to API. I also keep all the posts detail in postresql database table which includes columns such as; id, title, description and created time. But I ...
2 votes
0 answers
32 views

Getting compile error when handling oneof in proto file [closed]

My proto file looks like this: message ATMDispute { ... } message Dispute { oneof dispute_info { // ATM disputes ATMDispute atm_dispute = 1; // card dispute CardDispute card_dispute =...
  • 1,089
-1 votes
1 answer
26 views

How to troubleshoot an error message indicating that Elasticsearch client methods are not recognized in Go?

I am trying to execute a search on the Elasticsearch client in Go (olivere/elastic), using the appropriate client library for Elasticsearch version 7.x. The expected behavior is to compile the code ...
0 votes
0 answers
11 views

How to create Search Box under my pagination using Golang Echo framework

// Get page number from path `product/:page` pageNumber := c.Param("page") page, err := strconv.Atoi(pageNumber) if err != nil || page < 1 { page = 1 ...
0 votes
1 answer
20 views

Finding endpoint (server) address when sending gRPC requests

Is there anyway to get the endpoint (server) address when sending gRPC requests in client? I have a client deployment talking to a server deployment in a kubernetes cluster through gRPC. Server ...
  • 15
-1 votes
1 answer
38 views

parse nested json using struct in go language

Unable to parse nested json into structs objects using go lang I have a nested json string that I want to parse using struct in Go language. The json looks like this {"action":"add"...
  • 1
0 votes
1 answer
63 views

How to define an interface with properties?

I have a question: is it possible to set an interface for a linear space? Let me remind you that in linear space L there is an operation of adding elements and multiplying an element by a number. ...
0 votes
1 answer
35 views

How to unmarshal JSON with a generic interface as a field

I have a generic Response object with the following struct: type Response struct { Data Data `json:"data"` Error string `json:"error,omitempty"` ...
-1 votes
2 answers
48 views

Questions about golang's rand package

I've been using and reading about the Golang rand package but I can't find a resource that actually explains what it's doing in a way I can understand. First, what is really happening when you "...
2 votes
1 answer
40 views

Elements incorrectly evicted from eBPF LRU hash map

I observe that elements are improperly evicted in an eBPF LRU hash map (BPF_MAP_TYPE_LRU_HASH). In the following code I insert into an LRU hash map of size 8 and print its contents every second: ...
  • 5,678
-2 votes
0 answers
25 views

In Go, how to skip expensive evaluation for LOG_LEVEL=DEBUG? [closed]

I have an expensive operation to create logging content when the log level is DEBUG. How to skip the processing if the log level is higher (i.e. will not log debug messages)? I can check the LOG_LEVEL ...
0 votes
0 answers
25 views

How do I stop a syscall from blocking indefinitely in Go?

I'm trying to do something very simple in Go: open a file. However, the file system that contains the files I'd like to open seems to have a few bugs (ntfs-3g). My program, among other things, opens ...
  • 6,000
-2 votes
0 answers
17 views

Golang:How to access and change the value of a field in a struct inside an interface? [duplicate]

Example: type Task interface{ With() Do() *result GetCount() int } type UpdateTask struct{ ID string Assign []*otherstruct.User } type UpsertTask struct{ ID string Assign []*otherstruct.User ...
0 votes
0 answers
22 views

Changed attributes in Terraform Plugin Framework

I'm creating a custom terraform provider with the new Terraform Plugin Framework. I want to save objects like this to terraform state: "attributes": { "name_servers": { ...
  • 109
1 vote
0 answers
13 views

How to get a value from LevelDb in Go by a key ending?

I know that it's possible to get values from LevelDb in Go by only a key prefix. However, I can't find any information about getting a value by key ending (key suffix). Is it even possible? If it is, ...
1 vote
0 answers
11 views

Add a column to Apache Beam PCollection in Golang

I'm trying to add string field (date) to a PCollection on a Beam pipeline written in Go. The value of this field will ultimately be determined by a parameter passed to my pipeline, although for now I'...
  • 199
1 vote
1 answer
35 views

Not able to serialize json data properly using GO

I'm using Go for the first time and am trying to create a web application that takes in a receipt using json, and then generates a unique id for that receipt as well as allocates some "points&...
  • 23
0 votes
1 answer
19 views

gin loads templates incorrectly

I have several routes in my server: router.GET("/", func(c *gin.Context) { c.HTML(http.StatusOK, "index.html", gin.H{"title": "Главная страница"}) }) ...
  • 23
-2 votes
1 answer
45 views

Do pointer receiver intended to fail in deep generic sturctures?

1st snippet (https://go.dev/play/p/-M1Z9V3KBjx) Pointer receiver call from normal function. package main import "fmt" type C struct { GUID string } func (c *C) guid() string { ...
  • 53
0 votes
1 answer
33 views

Whats the proper way to copy data from an io.Reader directly to a destination bytes.Buffer in golang?

I have code that wants to copy data from an io.Reader directly to a bytes.Buffer struct which is intended to stay around in memory as a cache. Right now I'm just calling io.Copy(dstBytesBuffer, reader)...
  • 375
1 vote
1 answer
32 views

Go Gin: Pass Zap Logger

I'm working in a project using Gin and recently started implementing a logger through the project. I saw a couple libraries but decided to go with uber's Zap. I've got controllers that look like this: ...
  • 1,216
0 votes
0 answers
16 views

Getting "unsupported_grant_type" error when getting bearer token from Reddit API in the GoLang

I am trying to get the bearer token from the Reddit API in the Golang with the code below. But I am getting "error": "unsupported_grant_type". I tried the same configuration in the ...
  • 820
0 votes
0 answers
12 views

Openapi Generator Minimum Maximum Range integer Go

I have a go project using the OpenAPI Generator with openapi: "3.0.3". I am attempting to implement error validation using a minimum and maximum range for an int64 request body variable. I ...
  • 189
0 votes
0 answers
24 views

golang aes encrypt with "global" cipher

I am using AES/GCM in golang with the following code: func encrypt(key, data []byte) ([]byte, error) { blk, err := aes.NewCipher(key) if err != nil { return nil, err } gcm, err ...
  • 1,524
0 votes
0 answers
11 views

Avro Schema from JSON document in golang

I tried to create JSON parser which will create a AVRO schema. I was unsuccessful in implementing it I am looking for golang Code which **infers AVRO Schema from JSON **document. if I can get a python ...
-1 votes
0 answers
29 views

Can't run go script, empty pointer

I tried to solve a simple problem, but stumbled upon a runtime error, as well as less important input problems, I'll mention it after code snippet, here is the error: panic: runtime error: invalid ...
0 votes
0 answers
8 views

golang how to save traces with asyn operations

I am writing a golang service that uses jaeger for tracing. My service has sync and async function in a different order. For async I use the worker pool pattern. I have 4 sync functions in a row and ...
  • 33
1 vote
1 answer
16 views

golang datadog tracing include trace information in outgoing requests

I'm using golang and datadog for tracing and my simplified setup is as follows client -> service 1 -> service 2 in service 1 I'm using gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux so that ...
  • 7,603
0 votes
1 answer
21 views

Go ChromeDP ignores any external or internal css during printing to pdf and uses only those, that in html file ONLY

Go ChromeDP not using any css either internal or external styles (only those, that was written in html, not other file). I using method page.SetDocumentContent(frameTree.Frame.ID, string(buf.Bytes()))....
0 votes
0 answers
17 views

How to create CDKTF script in golang for creating Kubernetes Namespaces

I have Terraform script for creating Kubernetes namespaces, but can not find the import statement for package in golang which would do the same job in CKDTF for go lang. resource "...
  • 6,241
0 votes
0 answers
23 views

Serverless authorizer request does not provide methodArn, or any information about the calling lambda

I am having issues getting the methodArn from a request object in an authorizer lambda I have defined. I am using serverless with golang. Here is a redacted setup of the code that I have. main.go - ...
  • 1,406
0 votes
1 answer
22 views

How to pass `ApplyConfig` to `tf.Apply()` in `hashicorp / terraform-exec`?

I am trying to add a target to terraform apply command using golang sdk for terraform in hashicorp/terraform-exec Ideally, the equivalent command for CLI is terraform apply --auto-approve --target '...
0 votes
2 answers
30 views

run Hourly Scheduler using gocron

How to run function hourly specific minute using gocron? i tried two code one is very dirty and one is not working. the dirty code: loc, _ := time.LoadLocation("Asia/Seoul") s := ...
  • 149
0 votes
1 answer
30 views

Using *gin.Context in cron Job

I have cron job that will call function that require *gin.Context as statement, this statement will be required int other process in the other next step. Previously I had made my code like this: _,...
  • 25
-2 votes
0 answers
42 views

How I can fix "zip: not a valid zip file" issue Golang?

I have an issue trying run this code using macOS and Golang. package main import ( "fmt" docxt "github.com/legion-zver/go-docx-templates" ) type TestStruct struct { ...
0 votes
0 answers
28 views

How do I run my Go backend and React frontend together locally?

Having trouble running my full stack app locally, even when the frontend and backend appear to function on their own just fine. I created a new app using create-react-app, then added my main.go file. ...
0 votes
0 answers
27 views

the word package is underlined in vs code [closed]

I wrote a program in main.go file, and vs code underlines the word package as issue: error error obtaining VCS status: exit status 1 Use -buildvcs=false to disable VCS stamping. What does it mean ...
  • 11
1 vote
0 answers
11 views

golang excelize: how to set edit ranges in protect sheet

excelize version: 2.6.1 Here is the sample on excelize official document : err := f.ProtectSheet("Sheet1", &excelize.FormatSheetProtection{ Password: "password", ...
  • 11

1
2 3 4 5
1370