Category "go"

Trim string's suffix or extension?

For example, I have a string, consists of "sample.zip". How do I remove the ".zip" extension using strings package or other else?

"package XXX is not in GOROOT" when building a Go project

I have a weird issue that arose when I took a break from this project. Upon starting up Goland, I'm riddled with errors when trying to run my project. The spe

Go StartsWith(str string)

Is there a StartsWith(str1, str2 string) function that can check if str1 is a prefix of str2 in Go language? I want a function similar to the Java's startsWith

How to view full dependency tree for nested Go dependencies

I'm trying to debug the following build error in our CI where "A depends on B which can't build because it depends on C." I'm building my data service which doe

Go XML Marshalling and the Root Element

In Go, you can marshall a struct to XML, e.g.: package main import ( "encoding/xml" "fmt" ) type person struct { Name string Starsign str

Cannot use "a" (type string) as type in array element in go

I'm pretty new to Golang and I have an issue with adding items to Array. I use this link as a reference golang-book. I have this struct: package models type Fi

How to list installed go packages

To my knowledge go distribution comes with some sort of package manager. After go 1.4.1 installation I've run go help in order to find any sub-command capable o

"undefined" function declared in another file?

I'm trying to write a basic go program that calls a function on a different file, but a part of the same package. However, it returns: undefined: NewEmployee

How can I efficiently download a large file using Go?

Is there a way to download a large file using Go that will store the content directly into a file instead of storing it all in memory before writing it to a fil

How to use go-vcr with githubv4 ? - getting httpClient Transport

Looking at the set up for go-vcr // Start our recorder r, err := recorder.New("fixtures/etcd") if err != nil { log.Fatal(err) } defer r.

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