Category "go"

Some questions regarding $GOPATH

I'm a new golang developer and I wonder why $GOPATH environment variable is needed to be set at the root of my project. If I'm working on several projects at t

Returning JSON data as a stream per chunk to Angular2 or jQuery over HTTP2 (HTTPS)

In one of my API's I mostly return a result (let's say paged 50 results) as one whole in an json array like so: [{},{},{},{},{},...] I was wondering if there

Is there a way to update the TLS certificates in a net/http server without any downtime?

I have a simple https server serving a simple page like so (no error handling for brevity): package main import ( "crypto/tls" "fmt" "net/http" )

How to read TCP packets on a tun/tap interface?

I'm working on a simple project that listens on a tun interface and modified the packets then re-sends them to the real interface. I have tried songgao/water,

how to install a package with gvm(Go Version Manager)? go get failed

I successfully installed go1.6.2 with gvm and used global pkgset. I am trying to install gocode package with gvm, but go get not working. I guess gvm is not rea

net/rpc server stay registered when running test more than once with the 'count' flag

The program creates a rpc server and a client and expose several methods via the rpc interface. Several test functions testing one of the methods each. The firs

How do I print a 2-Dimensional array as a grid in Golang?

The 2D Array I am trying to print as a board Note: I am a complete novice at using Go and need this for a final project. I am making an attempt to make the game

How initialize the result of groupArray function of the ClickHouse to the array

In my Go application, I make a request to the ClickHouse database via clickhouse-go package. This query which I make return always only one record and it's an a

How to broadcast in gRPC from server to client?

I'm creating a small chat application in gRPC right now and I've run into the issue where if a user wants to connect to the gRPC server as a client, I'd like to

Scan from Postgres into struct with pointers

What would be the benefit of using a struct like below with pointers instead of a struct without pointers when scanning from database? type User struct {

JSON single value parsing

In python you can take a json object and grab a specific item from it without declaring a struct, saving to a struct then obtaining the value like in Go. Is the

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