Category "go"

Is there a way in Golang Generics to create something like "extends" in Typescript?

I am trying to create a function using Go Generics that accepts any structs that meet minimum struct criteria. Something like <T extends {name: string, age:

Simplifying AWS SDK GO v2 testing/mocking

Amazon has a super useful article describing how to unit test AWS SDK Go v2. I understand their motivation to depart from the "old" way of unit testing the v1

Go test not running specific test despite flag inclusion

Folder structure: ./test ├── abc │ └── abc_test.go └── run_test.go run_test.go package test impo

Strange issue with terminal getting messed up: vim/coc-nvim/golang/gopls/zsh/gpg

I am having a very annoying issue and I don't know exactly what's the problem. It could have loads of possible causes, so please bear with me trying to fix this

aws-sdk-go-v2 set custom header on PutObjectInput

I am in a situation where i need to set a custom header on putting an object to an s3 compatible storage system. _, err := uploader.Upload(ctx, &s3.PutO

aws-sdk-go-v2 set custom header on PutObjectInput

I am in a situation where i need to set a custom header on putting an object to an s3 compatible storage system. _, err := uploader.Upload(ctx, &s3.PutO

How to unmarshal an escaped JSON string

I am using Sockjs with Go, but when the JavaScript client send json to the server it escapes it, and send's it as a []byte. I'm trying to figure out how to pars

How are the checksums in go.sum computed?

I looked at https://go.dev/doc/modules/gomod-ref and https://go.dev/ref/mod#go-mod-tidy, and on neither page could I find any documentation that explains how th

Correctly log protobuf messages as unescaped JSON with zap logger

I have a Go project where I'm using Zap structured logging to log the contents of structs. That's how I initialise the logger: zapLog, err := zap.NewProductionC

Are function variables concurrency-safe in golang?

I have following types declared type TestFn func(id int, ctx context.Context) error var Func1 = TestFn(func(id int, ctx context.Context) error { // do some w

Why do I get "undeclared name: any (requires version go1.18 or later)" when using any instead of interface{}? I am using Go 1.18

When trying to use any instead of interface{} with the Go 1.18 toolchain, you can get the error: undeclared name: any (requires version go1.18 or later) Why is

Generic Structs with Go

What is the equivalent of this C# code in Go, how can I build it class ModelX<T> { public T Data { get; set; } } ModelX<int>

Sarama Cluster Admin - Broker Connected method return false

Versions Sarama - v1.32.0 Kafka - 5.4.6-2.12 Go - v1.16.2 sarama.Logger = log.New(os.Stderr, "[Sarama] ", log.LstdFlags) brokers := []string{ "kafka1

Why does GCP Cloud Functions log two blank lines?

I created a trivial GoLang 1.16 GCP CloudFunction and deployed it. When I make a request to the endpoint, I see two blank lines in the log output. I can't figur

golang webapp package structure [duplicate]

I've a simple golang web application, everything in main package, where http handlers are methods of an App struct embedding a DB pointer type

How can I represent map[string][]byte? [closed]

I would like to create a map, but I am unsure of the syntax. The map[string][]byte data type is giving me trouble, because I think that the e

Why does Go not allow assigning one generic to another?

Following code throws a compilation error cannot use ExampleProps (variable of type Props[Example]) as Props[Generic] value in return statement // Abstract ty

How to Unmarshall data to JSON with unknown field types

I have these 'structures' type Results struct { Gender string `json:"gender"` Name struct { First string `json:"first"` Last string `

Golang TLS handshake error - "first record does not look like a TLS handshake"?

Client-side code tlsconf := &tls.Config{InsecureSkipVerify: true} creds := credentials.NewTLS(tlsconf) opts = append(opts, grpc.WithTransportCredentials(cre

Channel frequency counter

I have a channel that emits events. I'd like to set up an "oscillometer" on top of this channel, i.e. some sort of a "frequency counter" that gets constantly up