Quantcast
Channel: User Norbert - Stack Overflow
Browsing index pages (42 articles)

Comment by Norbert on Why doesn't Go have a function to calculate the...

Or use the ~ annotation to write this for all types of integer to have only one function

View Article


Answer by Norbert for Converting A struct to map using generics

While golang has generics, you are trying to make a generic map, which as far as I know will not work: The inferred type has to be one of the types only:E.g. Input 3 different types, the inference for...

View Article


Answer by Norbert for Golang Getrlimit returns the different value from ulimit

This is per design since 1.19, see https://github.com/golang/go/issues/46279 for the whole discussion.

View Article

Answer by Norbert for Best patterns for dynamic checks in Go without reflection?

3 directions, not the most straight forward, but they can reduce your check blocks:Method 1: Define your own annotationGolang has annotations in structstype bla struct { t string...

View Article

Answer by Norbert for Makefile for GoLang Cross Compilation

Not an idiomatic way. Shorter might be possiblego tool dist listGets you all builds.By now just looking for the first 2 lowercase characters of the OS in the list against the ${os}, look for the arch...

View Article


Answer by Norbert for Go-SQL-Driver causing maria-db CPU utilization very high

The go process in itself should not have any other effect on (any) database as any other language barring better driver implementations for retrieving the row data (cursor implementation of MySQL was...

View Article

Answer by Norbert for Why the NATS Golang client, if imported increases the...

It is not uncommon that this happens. The code you import is not just the interface, but also all the interface implementation, and dependencies.Golang does not treeshake the imports on usage (would be...

View Article

Answer by Norbert for How to fix unsupported relations for schema error with...

You are not using the standard gorm.Model for the keys (from the docs):type Model struct { ID uint `gorm:"primaryKey"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt...

View Article


Answer by Norbert for How to return aggregated document from MongoDB in Golang?

The error states that the category is an array instead of just a string.Your current definition:type Post struct { ID primitive.ObjectID `json:"_id" bson:"_id,omitempty"` Title *string `json:"title"...

View Article


Answer by Norbert for go build command equivalent api

Since go is build with go, the go/internal (https://pkg.go.dev/std see internal) place is where you want to start looking. It is a rabbit hole but contains all the items like environment variables...

View Article

Answer by Norbert for Protobuffers and Golang --- writing out marshal'ed...

Use proto.Marshal/Unmarshal:That way you simulate (closest) to receiving the message while avoiding side effects from other Marshal methods.Alternative: Dump it as []byte and reread it.

View Article

Answer by Norbert for Mutex not locking

You might want to write this a bit different:You start by locking, which is not the most common way to use a lock: Everything is locked unless you unlock it.A more common way is:package mainimport...

View Article

Answer by Norbert for How to use json tags in anonymously nested struct?

The issue is with the base structure. type s struct { Links struct { Self struct { Href string } } `json:"_links"` }is the correct syntax

View Article


Answer by Norbert for Go maps - pulling records based off key value. A...

Your measurement of performance contains other elements:if v, ok := itenariesMap[i]; ok { w.WriteHeader(http.StatusOK) fmt.Fprintf(w, utils.PrettyPrint(s.TravelItenariesCSV[v])) // this takes ~500.0µs...

View Article

Answer by Norbert for Building Go project from Dockerfile says package not in...

Go has a system variable set location for the build location (which is strict). This is either your home directory +go/src/ or the GOPATH.In your case you have to set your GOPATH:ENV GOPATH /myApp

View Article


Answer by Norbert for Unmarshaling nested custom same-type JSON in Go

Given your json, you can do this:type Envelope struct { Some string `json:"some"` Nested json.RawMessage `json:"nested"`}json.RawMessage is a rather hidden gem, and more people seem to go for the...

View Article

Answer by Norbert for InnoDB Select For Update

Yes, collisions can always occur. So using the design pattern:SELECT FOR UPDATE for all the resources in a given transaction first, can prevent or shorten deadlock situations.Suppose the following...

View Article


Answer by Norbert for Golang docker container doesn't start on Windows Home

The issue is the order of commands (most likely):docker run -d yourcontainer should workSome unrelated advice: This is a rewrite of your docker file (untested).As you notice it is shorter, and uses a...

View Article

Answer by Norbert for single insert statement in transaction

The use of a transaction around a single insert is not the most useful. They are however passing a function fn TxFn which could contain a complex set of (sql) statements making the given structure more...

View Article

Answer by Norbert for How do I start my android emulator with go?

Any exit status not 0 is an error from the shell. That is not equal to a golang error (the command executed, however the command internally threw an error). This is often the case by lack of...

View Article
Browsing index pages (42 articles)


Latest Images