Category "go"

Default value in Go's method

Is there a way to specify default value in Go's function? I am trying to find this in the documentation but I can't find anything that specifies that this is ev

Go linter in VS code not working for packages across multiple files?

I have installed the Go extension (version 0.11.4) in Visual Studio Code on MacOS: However, I find that the linter does not 'pick up' functions defined in th

Increase Heap size in GO

Is there a way howto instruct GO runtime to use larger heaps? I am running GO 1.5. My GO process is currently spending 34% of time in GC but it uses unly 1/3 o

How do I reverse an array in Go?

http://play.golang.org/p/W70J4GU7nA s := []int{5, 2, 6, 3, 1, 4} sort.Reverse(sort.IntSlice(s)) fmt.Println(s) // 5, 2, 6, 3, 1, 4 It is hard to unde

Mock functions in Go

I'm puzzled with dependencies. I want to be able to replace some function calls with mock ones. Here's a snippet of my code: func get_page(url string) string {

How to correctly set Mock Row and Query for go-sqlmock

I'm setting up testing in golang. I use go-sqlmock to test mysql connection. But sqlmock.NewRows and mock.ExpectQuery does not work well with error. I want to k

How to sort map by value and if value equals then by key in Go?

I came across a situation where I want to sort a map first by value and if the values are equal then by key in GO. Here is an example of input and expected outp

chromedp - Go - Show invalid printer settings error (-32000) - When setting WithMarginTop

I'm playing around with chromedp and been trying to replicate the functionality in puppeteer node.js but in golang. I'm finding that the same JSON payload to ch

Need help on creating a UDF, returning "Unable to create a new Lua state"

I need to ask a question on creating UDF on aerospike. My configuration is as below: M1 Macbook Pro Docker using latest aerospike My application is running this

How to delete an element from a Slice in Golang

fmt.Println("Enter position to delete::") fmt.Scanln(&pos) new_arr := make([]int, (len(arr) - 1)) k := 0 for i := 0; i < (len(arr) - 1); { if i != p

Is a Go goroutine a coroutine?

In the Google I/O 2012 presentation Go Concurrency Patterns, Rob Pike mentions that several goroutines can live in one thread. Does this imply that they are imp

Chromedp with Golang has deadline exceeded if element doesnt exist. Is there a way to extend the context timeout after a deadline?

I have a function that uses chromedp to check if there is a acknowledge modal that pops up sometimes. If it pops up the function works but if the context deadli

Golang http request results in EOF errors when making multiple requests successively

I am trying to debug a very unusual error I am receiving for a simple REST library I wrote. I am using the standard net/http package to make Get, Post, Put, Del

Adding metric labels in prometheus on the fly

I have a counter metric in prometheus. I want to add lables to it dynamically for example if my request comes http://abc123.com/{p1} ,I want my custom_metric_na

How to cache the compiled regex in Go

Below is my golang code. Each time validate method is called my compile method gets executed. I want to compile only once, not each time we call validate. 1)

How do I find the size of the array in go

I have tried len() function but it gives the declared value. The size() function gives an error. Code: package main var check [100]int func main() { print