Category "go"

How to merge multiple strings and int into a single string

I am a newbie in Go. I can't find any official docs showing how to merge multiple strings into a new string. What I'm expecting: Input: "key:", "value", "

How to pass multiple data to Go template?

I want to pass two data objects to Go Template. One is a MongoDB query result and other is an integer array. MongoDB Query:- var results []User sess, db := Ge

Validating configurations files with viper

I was looking for a configuration parser for go and https://github.com/spf13/viper seems to come highly recommended. I am very surprised to find that configura

Why is go build doing nothing?

I'm running into a bizarre problem at work. I have a project. In this project are two packages, each in its own folder. Each folder contains various .go files

Find address of constant in go

We have written one program by which we try to find an address of a constant. Is it possible to do it like that? package main func main() { const k =

Using .env files to set environment variables in Windows

I am working on a set of projects that use .env files for configuration, where each .env file exports a number of environment variables. The files are setup lik

malformed module path "xxxx/xxxx/uuid" missing dot in first path element when migrating from GOPATH based dep to go mod

$ go version 1.13.3 I have a folder structure as follows: GOPATH +---src +--- my-api-server +--- my-auth-server +--- main.g

Static global variables in Go

I am new in Go language and I need some help. I have declared a global variable but the problem is that it does not keep its value. It would be solved with a st

Checking equality of interface{}

I am searching a []interface{} slice for a given interface{} value: var v interface{} for i := 0; i < len(A); i++ { if (A[i] == v) { fmt.Println("Gotc

traefik.go: command traefik error: failed to eval New: undefined: xxx

I am trying to build a Traefik plugin and test it in local mode based on https://github.com/traefik/plugindemo#local-mode Right now this plugin does nothing and

traefik.go: command traefik error: failed to eval New: undefined: xxx

I am trying to build a Traefik plugin and test it in local mode based on https://github.com/traefik/plugindemo#local-mode Right now this plugin does nothing and

Private embedded struct when importing a struct from another package

I have a project which relies on a struct imported from another package, which I will call TheirEntity. In the example below, I (ahem) embed TheirEntity in MyE

How to remove all contents of a directory using Golang?

I'm new to Go and can't seem to find a way to delete all the contents of a directory when I don't know the contents. I've tried: os.RemoveAll("/tmp/*") os.Rem

Couldn't start dlv dap

When I launch in VSCode dlv dap debug, I get this message: Couldn't start dlv dap: Error:timed out while waiting for DAP server to start I already have launch

tls: no renegotiation error on HTTP request

I'm trying to make a simple HTTP request in Go, after directly following the guides I keep getting the same error: local error: tls: no renegotiation I don't

Google Stackdriver log entry record field logging.googleapis.com/severity vs severity

I have a general log package that wraps logs for Stackdriver- Gets context, severity etc and transform it to LogEntry i.e: func Log(ctx context.Context, severi

Golang multi-method interface and struct naming

Golang docs provide a clear guidance on how to name single-method interface (by appending "-er"). But what is the best practice to name a multi-method interface

Pointer receiver method compilation problem: Cannot call a pointer method on 'MyObj{}'

I have the following method defined: func (o *MyObj) parse(something string) string { // Do stuff } This code (1) compiles just fine: (&MyObj{}).parse(

Multiple receivers on a single channel. Who gets the data?

Unbuffered channels block receivers until data is available on the channel. It's not clear to me how this blocking behaves with multiple receivers on the same c

go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: cannot find -lgdal

I am trying to run go build on my sources. go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: cannot find -lgdal collect2: error: ld