1 answer

Golang mgo result into simple slice

I'm fairly new to both Go and MongoDB. Trying to select a single field from the DB and save it in an int slice without any avail. userIDs := []int64{} coll.Find(bson.M{"isdeleted": ...

1 answers | 22 mins ago by khuderm on Stack Overflow
1 answer

how to create bson map based on input

I am building a bson map in golang using mgo library. I want to refactor some code to be able to avoid duplication. Consider this: bson.M { "$match" : bson.M{ "xyz" : ...

1 answers | 29 mins ago by Gaurav Sinha on Stack Overflow
1 answer

Distributed microservices using Kite and Kontrol

I am able to register my kite microservice to kontrol but unable to discover it, kites, err := k.GetKites(&protocol.KontrolQuery{ Username: k.Config.Username, ...

1 answers | 31 mins ago by Shishir on Stack Overflow
3 answers

Correct approach to global logging in Golang

What's the pattern for application logging in Go? If I've got, say, 5 goroutines I need to log from, should I... Create a single log.Logger and pass it around? Pass around a pointer to that ...

3 answers | 1 hour ago by Carson on Stack Overflow
1 answer

Function declaration syntax: things in parenthesis before function name

I'm sorry I couldn't be more specific in the question title, but I was reading some go code and I encountered function declarations of this form: func (h handler) ServeHTTP(w http.ResponseWriter, r ...

1 answers | 2 hours ago by Marcus Vinícius Monteiro on Stack Overflow
2 answers

Whats the difference of functions and methods in Go?

I am trying to get started with Go and the documentation is very good. What I did not find in the documentation is the difference between functions and methods. As far as I understand at the moment: ...

1 answer

Unmarshalling a json array in golang

I have a question regarding the golang unmarshalling . I was trying to unmarshal Json array but it is giving nil result for one decoding while it is successful in the other. I don't understand the ...

1 answer

Parsing JSON Time error

I am trying to parse a timestamp that is generated in python and posted over to here to be stored in cassandra and I am getting a weird error. parsing time ""2015-11-05 14:14:32-0700"" as ...

1 answers | 2 hours ago by electrometro on Stack Overflow
1 answer

Testing constructors in Go

How I can test my NewClient constructor for my Client struct ? package busybus import ( "bufio" "net" ) type Client struct { counter integer conn net.Conn bufin ...

1 answers | 2 hours ago by astropanic on Stack Overflow
1 answer

http HandleFunc argument in golang

I want to use a rate limiting or throttler library to limit the number of client requests. I use a vendor library in my code base. I want to pass in a ResponseWriter, Request and a third variable ...

1 answer

golang struct for unmarshal

I need to create a struct to unmarshal and access key "name" and receive its value. { "product":"car", "spec":[ { "name":"bla_bla", "info":{ ...

1 answers | 4 hours ago by user3398940 on Stack Overflow
0 answers

Can't get go exec command to execute git config command properly

I have am trying to execute a git command from a golang program to get the url of git's remote. Below is the code. It keeps throwing an "exit status 1" error. func main() { var out bytes.Buffer ...

4 hours ago by Konoha on Stack Overflow
3 answers

Why do floats and ints = Nan? in go

package main import ( "fmt" "math" ) func main() { // x= +- sqrtB-4ac/2a cal() } func cal() { b := 3 a := 4 c := 2 b2 := float64(b*b) ac := ...

3 answers | 4 hours ago by liam on Stack Overflow
4 answers

golang why don't we have a set datastructure

I'm trying to solve "The go programming lanaguage" exercise #1.4 which requires me to have a set. I can create a set type but why doesn't the language come with one ? go, having come from google, ...

4 answers | 5 hours ago by anjanb on Stack Overflow
1 answer

Golang - Could not expire a cookie

I'm currently playing with the Go App Engine SDK and I'm trying to set/expires Cookies. There is no problem by setting a Cookie, but it is impossible to make it expiring in the browser. The app is a ...

1 answers | 6 hours ago by yageek on Stack Overflow
1 answer

How does modular code work in Go?

Not having come from a C/compiled languages background, I'm finding it hard to get to grips with using Go's packages mechanism to create modular code. In Python, to import a module and get access to ...

1 answer

Why strings.HasPrefix is faster than bytes.HasPrefix?

In my code, I have such benchmark: const STR = "abcd" const PREFIX = "ab" var STR_B = []byte(STR) var PREFIX_B = []byte(PREFIX) func BenchmarkStrHasPrefix(b *testing.B) { for i := 0; i < b.N; ...

1 answers | 8 hours ago by gobwas on Stack Overflow
2 answers

Go lang json.Marshall() ignores omitempty in ByteArray Fields

Please see below. My expected value is: {"Byte2":0,"Name":"bob"} But Actual: {"ByteArray":[0,0,0,0],"Byte2":0,"Name":"bob"} According to the document ...

2 answers | 9 hours ago by Takahiro Ikeuchi on Stack Overflow
1 answer

golang with fastcgi how to read REMOTE_USER

Short: How can I read the CGI var REMOTE_USER on golang using fastcgi? Long: I'm trying to write a program in go to work behind a httpd using fcgi over a socket. The httpd does the ssl termination ...

1 answer

How to enable autoimport in GoClipse?

According to this post autoimport could be enabled in GoClipse: 1) install goimports: go get 2) in eclipse goto: Preferences -> Go -> Go Formatter and ...

1 answers | 10 hours ago by Alfred on Stack Overflow
1 answer

Unmarshal json to a array from post request

see below my main.go type Data struct { unit []string `json:"unit"` } func receive(w http.ResponseWriter, r *http.Request) { dec := json.NewDecoder(r.Body) for { var d Data ...

1 answers | 10 hours ago by Mr.AgiTheMan on Stack Overflow
1 answer

Log 404 on http.FileServer

I'm serving jpeg images from dirPath using http.FileServer with: http.Handle("/o/", http.StripPrefix( path.Join("/o", dirPath), http.FileServer(http.Dir(dirPath)))) What I don't understand is ...

1 answers | 10 hours ago by hendry on Stack Overflow
0 answers

Verify signature of SAML assertion in Go?

My SAML assertion looks like this: <saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_" Issuer="" IssueInstant="" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"> ...

1 answer

Custom MarshalJSON() never gets called in Go

I've written custom versions of MarshalJSON and UnmarshalJSON. My UnmarshalJSON gets called the way I want it to, but I can't get it to work with MarshalJSON. Here's code that summarizes my problem: ...

1 answers | 12 hours ago by Anders Sjöqvist on Stack Overflow
1 answer

Connection pooling with SQL driver in Go

What is the best practice for storing a connection to a database in Go language? In Java for example you can use singletons, some IoC containers like Spring. What is the best practice in it's ...

1 answers | 15 hours ago by Andre Minov on Stack Overflow
2 answers

go/golang + redis too many open files error

I'm using redis in Golang with the Redigo connector ( suggested by the Redis website. I have: After every Dial() I defer a Close() Set fs.file-max = 100000 Set ...

2 answers | 15 hours ago by Allison A on Stack Overflow
1 answer

How to parse nested JSON into structs in Go?

How can I map a nested JSON to a nested Struct like this: type ChildStruct1 struct { key3, key4,string } type ChildStruct2 struct { key4, key5,string } type MainStruct struct { ...

1 answers | 16 hours ago by Sankalp Mishra on Stack Overflow
1 answer

Go binary search error

Suppose you have two use cases: a := [] int {2, 2, 3, 4} i := sort.Search(len(a), func(pos int) bool { return a[pos] == 2}) fmt.Printf("%v -> %v \n", a, i) b := [] int {1, 2, 2, 3, 4} j := ...

1 answers | 19 hours ago by Andre Minov on Stack Overflow
2 answers

How to combine multiple assignment and Range in for loops

I'm trying to figure out how to (or if it's possible to) combine multiple assignment and ranges in Golang ex pseudo code of what I'd like to do files := [2]*os.File{} for i, _, fileName := 0, range ...

2 answers | 21 hours ago by Mike Graf on Stack Overflow
1 answer

Golang how can I guarantee data finishes in a goroutine while being accessed by another goroutine

Hi guys I am trying to make a party system using websockets where people can enter a queue and then get matched with 5 people similar to them. Right now I'm having trouble with this part: type ...

1 answers | 22 hours ago by Datsik on Stack Overflow
15 30 50 per page
1 2 3