Category "go"

How to get the current timestamp in other timezones in Golang?

I need to get the current time in different time-zones. Currently I know that we can do the following: t := time.Now() fmt.Println("Location:", t.Location(),

Why isn't fallthrough allowed in a type switch?

I'm wondering why fallthrough isn't allowed in a type switch statement in golang. According to the specification: "The "fallthrough" statement is not permitted

Avoiding scientific notation

I am experimenting using Go to interact with a Database and am running into issues when dealing with Decimal fields. In this database most fields that are bas

How to combine slices into a slice of tuples in Go (implementing python `zip` function)?

Sometimes, it's convenient to combine two lists into a tuple using zip built-in function in Python. How to make this similarly in Go? For example: >>>

Golang conditional compilation

I've got a trouble with conditional compilation in Go 1. Here is my test code. Is there anything I misunderstand about the "// +build" constraint and the "-tag

Are you required to call Recv until you get io.EOF when interacting with grpc.ClientStreams?

Suppose I define the following gRPC service: service Library { rpc Search(SearchBookRequest) returns (stream SearchBookResponse) {} } message SearchBookReq

Subtracting time.Duration from time in Go

I have a time.Time value obtained from time.Now() and I want to get another time which is exactly 1 month ago. I know subtracting is possible with time.Sub()

Separating unit tests and integration tests in Go

Is there an established best practice for separating unit tests and integration tests in GoLang (testify)? I have a mix of unit tests (which do not rely on any

my-appname| /bin/sh: 1: /app/tmpmain.exe: not found | air

I'm facing an issue, am trying to run my go fiber project inside docker with air but am getting this erroruni-blog | /bin/sh: 1: /app/tmpmain.exe: not found am

golang handling kill in a process started by cmd.Start

I have two go programs. ProgA starts ProgB using cmd.Start(). From ProgA I try to kill ProgB, but ProgB shouldn't get killed immediately, it has to do some clea

Executing function upon required number of times

calculate the sum of squares of given integers, excluding any negatives. The first line of the input will be an integer N (1 <= N <= 100), indicating the

Marshal into a bson.Raw

Using gopkg.in/mgo.v2/bson, I wonder how to marshal an interface{} value into a value of type bson.Raw. The documentation for bson.Raw states: Using this t

How to debug Go tests with param "./..." in VS Code

I usually run go test ./... to run all tests in my project. How can I set up launch.json to debug every tests that normally go test ./... runs?

How to analyze golang memory?

I wrote a golang program, that uses 1.2GB of memory at runtime. Calling go tool pprof http://10.10.58.118:8601/debug/pprof/heap results in a dump with only 323

Golang : Is conversion between different struct types possible?

Let's say I have two similar types set this way : type type1 []struct { Field1 string Field2 int } type type2 []struct { Field1 string Field2 i

golang - How to convert byte slice to bool?

I have a database sql.NullBool. To unmarshal json into it, I am writing this little function. I can converty the byte array to string by simply casting it (stri

Dynamically initialize array size in go

I try to write a small application in go that takes 'x' numbers of integers from standard input, calculates the mean and gives it back. I have only gotten so fa

Creating yaml list using the go template

I am looking to create a yaml file in the following format. Using Go template Custom_listeners: Config1 : config_value Config2 : config_value

What should be the values of GOPATH and GOROOT?

I'm trying to install doozer like this: $ goinstall github.com/ha/doozer I get these errors. goinstall: os: go/build: package could not be found locally g

How to initialize a struct which has a pointer-type property?

The struct is like this: type Node struct { Stat *Stat } type Stat struct { StatInfo []string } Initialize the structure, and set properties. node :=