Category "go"

Issue with Unmarshalling GRPC Response To Generic Type

I am trying to use generics to convert a JSON object into a GRPC response that has an enum, i.e.: type GRPCResponse { str string enu EnumType } type En

Convert func(T) to func(any) [duplicate]

I want to be able to enforce similarity between two fields of a struct but also have several of these structs in a map or slice. Here's a simp

What is the idiomatic Go equivalent of C's ternary operator?

In C/C++ (and many languages of that family), a common idiom to declare and initialize a variable depending on a condition uses the ternary conditional operator

Mixed named and unnamed function parameters

I have this function for authenticating JWT tokens (not middleware), which says: package main import ( "net/http" "log" "fmt" "github.com/dgrijalva/jwt-go" )

Converting Protobuf3 with enum to JSON in Go

How can I convert grpc/protobuf3 message to JSON where the enum is represented as string? For example, the protobuf message: enum Level { WARNING = 0;

insert decimal type to clickhouse database , there have error of unexpected type string

I am a beginner, I don't understand why insert decimal type field "money", it echo "money (Decimal(18, 2)): unexpected type string" func main() { dsn := "

How can I pretty-print JSON using Go?

Does anyone know of a simple way to pretty-print JSON output in Go? The stock http://golang.org/pkg/encoding/json/ package does not seem to include functionali

Testing gin based REST API not getting params while using net/http/httptest

I am developing a REST API based on Gin Go, the endpoint looks something like below: func carsByType(c *gin.Context) { fmt.Println("Go Request in Handler...

Why does append modify passed slice

How could I iterate through the slice and pass somewhere the slice except the current element? Seems append() function modifies the underlying slice as we could

Sqlite concurrent writing performance

I'm writing a website with Golang and Sqlite3, and I expect around 1000 concurrent writings per second for a few minutes each day, so I did the following test (

Go programs won't run after MacOS Catalina upgrade

This might be a weird question, but some programs written in Go won't run on my MacBook Pro after MacOS Catalina upgrade. However a basic "Hello World" program

remove duplicate characters immediately following one another

I am trying to remove duplicate characters that are immediately following each other. E.g. "Whyyyy sooo ssserioooouuussss" should translate to "Why so serious

Can I view external Go libraries with VSCode?

I'd like to switch to using VSCode full time, but the one thing keeping me on IntellijIDEA is its ability to view Go standard and all dependency libraries in Ex

GO storing data returns EOF

I'm new to golang and I'm trying to build rest api, So far GET endpoints are working for me fine, but I'm having difficulties with POST method(creating user): T

How can I create a index in Elasticsearch with `go-elasticsearch` library?

I am using this library in go as Elasticsearch client: https://pkg.go.dev/github.com/elastic/go-elasticsearch/esapi#IndicesCreate.WithBody I have a problem on c

Unmarshal to a interface type

I have some code I've been dumped with and am actually stumped - I've worked with RPC and the JSON side of things before but I can't seem to get it to work over

Json dynamic fields to struct issue [duplicate]

Every time I resolve one issue I get into another similar but different. I need to convert into struts below JSON, but some parts are dynamic.

Difference between any/interface{} as constraint vs. type of argument?

As generics have been released in Go 1.18 pretty recently, I've started learning them. I generally get the concept, because I have some Java experience from the

Detect 32 or 64 bits machine (Understanding `32 << (^uint(0) >> 63)` )

It is said that the 32 << (^uint(0) >> 63) expression can be used to detect whether the machine is 32 or 64 bits. How so? UPDATE: The question was c

Cannot unmarshal a post json python request in Go

Here is my python code (client side) : import requests import json import datetime headers = {'Content-type': 'application/json',"Authorization":"Bearer MYRE