[go-nuts] go get failing In Mac 10.11.4

2016-06-21 Thread DM
Hi

On Mac OS X 10.11.4 *go get* is failing with the below error. 

jabongs-MacBook-Pro-4:florest debraj$ go get ./...
go install github.com/jabong/florest/src/common/config: open /var/folders/lp
/3q9_2mn51hd9s4yj_jcf3jxmgp/T/go-build823644730/github.com/jabong/
florest/src/common/config.a: no such file or directory
go install github.com/jabong/florest/src/common/utils/responseheaders: open 
/var/folders/lp/3q9_2mn51hd9s4yj_jcf3jxmgp/T/go-build823644730/github.
com/jabong/florest/src/common/utils/responseheaders.a: no such file or 
directory
go install github.com/jabong/florest/src/service: open /var/folders/lp/
3q9_2mn51hd9s4yj_jcf3jxmgp/T/go-build823644730/github.com/jabong/florest
/src/service.a: no such file or directory


Can some one let me know why this is failing? This is working perfectly 
fine on Ubuntu.

   - Go Lang Version - 1.6.1


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Difference between gowalker.org and godoc.org

2016-06-26 Thread DM
Can some one please explain me the difference between gowalker.org and 
godoc.org? I have viewed this thread 
.
 
But that seems to be little old.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] net/http: request canceled while waiting for connection

2016-07-12 Thread DM
Hi

We making some http PUT calls to a web server using net/http. Some time in 
the log we are seeing the below errors:-

{"level":"error","message":"Put 
http://blitz:2196/cache/api/v1/buckets/styloko/entities/product-xlarge-multi-sku-de898wa73oooindfas
: *read tcp **172.16.84.112:2196* *:* *use of 
closed network connection"*,"stackTraces":["/var/lib/jenkins/jobs/CI_
styloko_pkg_creation/workspace/styloko/src/amenities/products/common/
cache_manager.go(295)","/var/lib/jenkins/jobs/CI_styloko_
pkg_creation/workspace/styloko/src/amenities/products/get/search/
exactquery/node_response.go(127)","/usr/local/go/src/
runtime/asm_amd64.s(2232)"],"timestamp":"2016-07-11T19:30:29+05:30"}

{"level":"error","message":"Put 
http://blitz:2196/cache/api/v1/buckets/styloko/entities/product-xlarge-multi-sku-mi162bg58vblindfas
: *net/http: request canceled while waiting for connection"*
,"stackTraces":["/var/lib/jenkins/jobs/CI_styloko_pkg_creation/
workspace/styloko/src/amenities/products/common/
cache_manager.go(295)","/var/lib/jenkins/jobs/CI_styloko_
pkg_creation/workspace/styloko/src/amenities/products/get/search/
exactquery/node_response.go(127)","/usr/local/go/src/
runtime/asm_amd64.s(2232)"],"timestamp":"2016-07-11T19:30:32+05:30"}

Can some one please let me know when does the error "Use of closed network 
connection", "request canceled while waiting for connection" can come?

I am using go 1.5 on Debian 8 64 Bit.

Thanks,
D

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] xorm - 4.3 - panic: gob: registering duplicate names

2016-07-15 Thread DM


I am getting the below exception with xorm - 4.3 and golang 1.4.2. Any idea 
what could be going wrong? Is this some known issue xorm - 4.3 or some 
thing other going wrong?

panic: gob: registering duplicate names for models.SalesOrderItemAttribute: 
"*models.SalesOrderItemAttribute" != 
"order-subscriber/models.SalesOrderItemAttribute"

goroutine 71 [running]:
encoding/gob.RegisterName(0xc208120750, 0x2f, 0x9d0cc0, 0xc2084dafc0)
/usr/local/go/src/encoding/gob/type.go:832 +0x568
encoding/gob.Register(0x9d0cc0, 0xc2084dafc0)
/usr/local/go/src/encoding/gob/type.go:884 +0x20f
github.com/go-xorm/xorm.(*Engine).GobRegister(0xc20856e3f0, 0x9d0cc0, 
0xc2084dafc0, 0x9d0cc0)
/home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:679 +0x32
github.com/go-xorm/xorm.(*Engine).autoMapType(0xc20856e3f0, 0x9d0cc0, 
0xc2084dafc0, 0x59, 0x59)
/home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:670 +0x290
github.com/go-xorm/xorm.(*Session).innerInsertMulti(0xc208606fc0, 0x86d0c0, 
0xc2081f5e80, 0x8, 0x0, 0x0)
/home/jabong-release/go/src/github.com/go-xorm/xorm/session.go:2071 +0x30c
github.com/go-xorm/xorm.(*Session).Insert(0xc208606fc0, 0xc2086153a0, 0x1, 0x1, 
0x0, 0x0, 0x0)
/home/jabong-release/go/src/github.com/go-xorm/xorm/session.go:2034 +0x260
github.com/go-xorm/xorm.(*Engine).Insert(0xc20856e3f0, 0xc2086153a0, 0x1, 0x1, 
0x0, 0x0, 0x0)
/home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:1284 +0x99
order-subscriber/dao.InsertItemAttributes(0xc208223180, 0x8, 0xa, 0x0, 0x0, 
0xd5a938, 0x0, 0xd5a938, 0x0, 0xd5a938, ...)

/var/lib/jenkins/jobs/CI_order-subscriber_pkg_creation/workspace/src/order-subscriber/dao/dao.go:236
 +0x35d

The code that is throwing that error looks something like below:-

func InsertItemAttributes(data []Model.SalesOrderItemAttribute, rc 
utilhttp.RequestContext, logKey string) error {
prf := logger.NewProfiler()
dataDogAgent := monitor.GetInstance()
logger.StartProfile(prf, "insert_order_item_attributes")
xEngine, _ := utils.GetInstance().Orm(true)
//  xEngine.ShowSQL = true

logger.InfoSpecific(logKey, "Trying to insert item attributes : ", data)
_, err := xEngine.Insert(&data)
...

The structure SalesOrderItemAttribute looks something like below:-

type SalesOrderItemAttribute struct {
IdSalesOrderItemAttribute int   `xorm:"not null pk autoincr INT(10)"`
FkSalesOrderAttributeSet  int   `xorm:"not null index INT(10)"`
FkSalesOrderItem  int   `xorm:"not null index INT(10)"`
Value string`xorm:"not null VARCHAR(255)"`
CreatedAt time.Time `xorm:"index DATETIME"`
UpdatedAt time.Time `xorm:"not null default 
'CURRENT_TIMESTAMP' TIMESTAMP"`
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: xorm - 4.3 - panic: gob: registering duplicate names

2016-07-17 Thread DM
No.

Is this something related to the below issue:-

https://groups.google.com/forum/#!topic/golang-nuts/VnFs2Cv0_UY

If yes how can I get around this problem in xorm?

On Saturday, 16 July 2016 00:09:45 UTC+5:30, DM wrote:
>
> I am getting the below exception with xorm - 4.3 and golang 1.4.2. Any 
> idea what could be going wrong? Is this some known issue xorm - 4.3 or 
> some thing other going wrong?
>
> panic: gob: registering duplicate names for models.SalesOrderItemAttribute: 
> "*models.SalesOrderItemAttribute" != 
> "order-subscriber/models.SalesOrderItemAttribute"
>
> goroutine 71 [running]:
> encoding/gob.RegisterName(0xc208120750, 0x2f, 0x9d0cc0, 0xc2084dafc0)
> /usr/local/go/src/encoding/gob/type.go:832 +0x568
> encoding/gob.Register(0x9d0cc0, 0xc2084dafc0)
> /usr/local/go/src/encoding/gob/type.go:884 
> +0x20fgithub.com/go-xorm/xorm.(*Engine).GobRegister(0xc20856e3f0, 0x9d0cc0, 
> 0xc2084dafc0, 0x9d0cc0)
> /home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:679 
> +0x32github.com/go-xorm/xorm.(*Engine).autoMapType(0xc20856e3f0, 0x9d0cc0, 
> 0xc2084dafc0, 0x59, 0x59)
> /home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:670 
> +0x290github.com/go-xorm/xorm.(*Session).innerInsertMulti(0xc208606fc0, 
> 0x86d0c0, 0xc2081f5e80, 0x8, 0x0, 0x0)
> /home/jabong-release/go/src/github.com/go-xorm/xorm/session.go:2071 
> +0x30cgithub.com/go-xorm/xorm.(*Session).Insert(0xc208606fc0, 0xc2086153a0, 
> 0x1, 0x1, 0x0, 0x0, 0x0)
> /home/jabong-release/go/src/github.com/go-xorm/xorm/session.go:2034 
> +0x260github.com/go-xorm/xorm.(*Engine).Insert(0xc20856e3f0, 0xc2086153a0, 
> 0x1, 0x1, 0x0, 0x0, 0x0)
> /home/jabong-release/go/src/github.com/go-xorm/xorm/engine.go:1284 +0x99
> order-subscriber/dao.InsertItemAttributes(0xc208223180, 0x8, 0xa, 0x0, 0x0, 
> 0xd5a938, 0x0, 0xd5a938, 0x0, 0xd5a938, ...)
> 
> /var/lib/jenkins/jobs/CI_order-subscriber_pkg_creation/workspace/src/order-subscriber/dao/dao.go:236
>  +0x35d
>
> The code that is throwing that error looks something like below:-
>
> func InsertItemAttributes(data []Model.SalesOrderItemAttribute, rc 
> utilhttp.RequestContext, logKey string) error {
> prf := logger.NewProfiler()
> dataDogAgent := monitor.GetInstance()
> logger.StartProfile(prf, "insert_order_item_attributes")
> xEngine, _ := utils.GetInstance().Orm(true)
> //  xEngine.ShowSQL = true
>
> logger.InfoSpecific(logKey, "Trying to insert item attributes : ", data)
> _, err := xEngine.Insert(&data)
> ...
>
> The structure SalesOrderItemAttribute looks something like below:-
>
> type SalesOrderItemAttribute struct {
> IdSalesOrderItemAttribute int   `xorm:"not null pk autoincr INT(10)"`
> FkSalesOrderAttributeSet  int   `xorm:"not null index INT(10)"`
> FkSalesOrderItem  int   `xorm:"not null index INT(10)"`
> Value string`xorm:"not null VARCHAR(255)"`
> CreatedAt time.Time `xorm:"index DATETIME"`
> UpdatedAt time.Time `xorm:"not null default 
> 'CURRENT_TIMESTAMP' TIMESTAMP"`
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Connection pooling with xorm and go-mysql

2016-07-20 Thread DM
Just cross-posting this from stackoverflow 

 
and github :-

I am using xorm 0.4.3 with go-mysql . 
We are on Golang 1.4.

We have specified maxIdleConnetions and maxOpenConnections in xorm as 
below:-

var orm *xorm.Engine
...
orm.SetMaxOpenConns(50)
orm.SetMaxIdleConns(5)

And we are using the same single xorm instance to query Mysql.

But still we are seeing lot of connections in TCP Connection Establised state 
which is way over the numbers I have configured in maxIdleConnetions and 
maxOpenConnections state when we lsof:-

app 8747 10568 sandeshsharma 16u IPv4 691032 0t0 TCP 
127.0.0.1:57337->127.0.0.1:mysql (ESTABLISHED)

We have also observed that even if we stop the MySQL, the connection 
numbers still remain fixed but in the CLOSED_WAIT state. If we shutdown the 
app then all connections go away.

app 8747 10844 sandeshsharma 38u IPv4 505058 0t0 TCP 
127.0.0.1:54160->127.0.0.1:mysql (CLOSE_WAIT)

However in mysql process list it is showing the correct number of 
connections as I have specified in maxIdleConnetions and maxOpenConnections.

Can some one please explain me this behaviour? Why are we observing so much 
TCP connections even though we have specified maxIdleConnetions and 
maxOpenConnections to 5 & 50 respectively?




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] SetSafe default value in mgo session

2016-08-04 Thread DM


Can someone explain me the difference between the default value of SetSafe() 
which 
is &Safe{}and SetSafe(nil)? 

As per the mgo godoc :-

If the safe parameter is nil, the session is put in unsafe mode, and writes 
become fire-and-forget, without error checking. The unsafe mode is faster since 
operations won't hold on waiting for a confirmation.

If the safe parameter is not nil, any changing query (insert, update, ...) will 
be followed by a getLastError command with the specified parameters, to ensure 
the request was correctly processed.

The default is &Safe{}, meaning check for errors and use the default behavior 
for all fields.

Looking at the code 
 it 
seems it will call getLastError with values j:false, w:0, wtimeout:0. This 
means it will not return any error from mongo and the behavior seems to be 
similar while calling SetSafe(nil).

Then what error I am expected to receive while calling mongo with 
SetSafe(&Safe{})?

I am on Mongo 3.0.9.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Continous Inspection of Go Code Quality

2016-08-26 Thread DM
Is there any tool available in GoLang for the Continuous Inspection of code 
quality something similar to SonarQube ?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Timeout using Select from "Go Design Pattern"

2016-09-23 Thread DM
I was going through the *"Go Design Pattern"* talk by Rob Pike.

Can some one explain me the doubt I am having in the slide Timeout using 
Select . In the the 
video this  is the location where it 
is explained.

The code in the slide returns if there is nothing returned by boring for 1 
second.

Is my below understanding correct:-

So when the program starts let say the below code is executed 

case <- time.After(1 * time.Second)

fmt.Println("You're too slow.") 

return 

before the below:-

case s := <- c
fmt.Println(s) 


So a timer is started for 1 second. Before 1 second is over let's say boring 
writes something to channel c then case s := <- c will be executed. The 
moment somthing is written on channel c the timer that was started gets 
garbage collected and therefore it never returns the current time on the 
channel after 1 second?

I am pasting the code below:-

func boring(msg string) <-chan string { // Returns receive-only channel of 
strings.

c := make(chan string)
go func() { // We launch the goroutine from inside the function.
for i := 0; ; i++ {
c <- fmt.Sprintf("%s %d", msg, i)
time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
}
}()
return c // Return the channel to the caller.
}


func main() {
c := boring("Joe")
for {
select {
case s := <-c:
fmt.Println(s)
case <-time.After(1 * time.Second):
fmt.Println("You're too slow.")
return
}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Adding a title in godoc

2016-09-23 Thread DM
I am trying to add a title in my godoc. I have referred godoctricks 
. My godoc looks 
like below:-

// Package hello-world provides a helloworld example 
// 
// Pre-requisites 
// 
//  * Go 1.5+ 
//  * Linux or MacOS 
//  * https://onsi.github.io/ginkgo/ for executing the tests 
// 
// 
package hello_world


But the godoc is showing up as below with Pre-requisites not as title:-








Can someone let me know what is going wrong?

Environment:-


   - Go 1.7
   - Mac OSX El Capitan

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Adding a title in godoc

2016-09-23 Thread DM
It seems the list was creating the problem. If I add a line after the text 
Pre-requisites it works as expected.

// Package hello-world provides a helloworld example
//
// Pre-requisites
//
// I need to add the this line
//  * Go 1.5+
//  * Linux or MacOS
//  * https://onsi.github.io/ginkgo/ for executing the tests
//
//
package hello_world

Is this an issue with godoc or it is the expected behavior?

On Saturday, 24 September 2016 02:49:08 UTC+5:30, DM wrote:
>
> I am trying to add a title in my godoc. I have referred godoctricks 
> <https://godoc.org/github.com/fluhus/godoc-tricks#Titles>. My godoc looks 
> like below:-
>
> // Package hello-world provides a helloworld example 
> // 
> // Pre-requisites 
> // 
> //  * Go 1.5+ 
> //  * Linux or MacOS 
> //  * https://onsi.github.io/ginkgo/ for executing the tests 
> // 
> // 
> package hello_world
>
>
> But the godoc is showing up as below with Pre-requisites not as title:-
>
>
> <https://lh3.googleusercontent.com/-Y--Ko4sDj8I/V-Wb-aFwp-I/AIc/8uCoyzOjlYo8N4e98qY44xBwB69eEIPsgCLcB/s1600/Screen%2BShot%2B2016-09-24%2Bat%2B2.38.48%2BAM.png>
>
>
>
>
>
>
> Can someone let me know what is going wrong?
>
> Environment:-
>
>
>- Go 1.7
>- Mac OSX El Capitan
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [Open sourced] Workflow based REST Api framework - "florest"

2016-09-27 Thread DM
It seems there is a typo in the README

Try:-

go get github.com/jabong/florest-core/*src*/examples

On Tuesday, 27 September 2016 20:17:18 UTC+5:30, parais...@gmail.com wrote:
>
> Reading the doc , trying to reproduce the instructions :
>
>  go get  -u github.com/jabong/florest-core/examples
> package github.com/jabong/florest-core/examples: cannot find package "
> github.com/jabong/florest-core/examples" in any o
>
>
> But that package isn't go gettable at first place anyway. 
>
>
> Le mardi 27 septembre 2016 12:12:48 UTC+2, suba...@gmail.com a écrit :
>>
>> Hi All,
>> Please check this https://github.com/jabong/florest-core.
>>
>> Thanks.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Getting error back after executing a shell script via Golang

2016-09-29 Thread DM
Cross-posting this from stackoverflow 

:-

I have a simple shell script (named copy.sh) which looks like below:-

#! /bin/sh

cp $1 $2

I did chmod 777 copy.sh.

I have a golang code which executes the above shell code:-

package main
import (
"fmt"
"os/exec")

func main() {
_, err := exec.Command("/Users/debraj/copy.sh", "/Users/debraj/temp.txt", 
"/Users/debraj/gotest/").Output()
if err != nil {
fmt.Println("Failed to execute command " + err.Error())
return
}
fmt.Printf("\nCopy Successful - %v")}

The above code is showing be the below output:-

jabongs-MacBook-Pro-4:src debraj$ go run copyerr.go Failed to execute command 
exit status 1
jabongs-MacBook-Pro-4:src debraj$ 

But the error I receive from shell script looks like below:-

jabongs-MacBook-Pro-4:~ debraj$ ./copy.sh /Users/debraj/temp.txt 
/Users/debraj/gotest/
cp: /Users/debraj/gotest/temp.txt: Permission denied 

Can someone let me know how how can I get the same error message that is 
returned by the shell script?

If I don;t do chmod 777 copy.sh and the file has permission as below:-

jabongs-MacBook-Pro-4:~ debraj$ ls -la copy.sh -rw-r--r--  1 debraj  staff  21 
Sep 29 13:28 copy.sh

Then the golang code gives the output as given by the shell script. Can 
some also let me know why this is behaving like this?

I am on

   - Golang 1.7
   - Mac OS X 10.11.4

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [go-redis] Relation between PoolTimeout, IdleTimeout & IdleCheckFrequency

2016-12-10 Thread DM
Just cross-posting this from stackoverflow 


Can someone let me know the relation between PoolTimeout 

, IdleTimeout 

 & IdleCheckFrequency 

 in go-redis ?

Doubts:-

   1. If I specify PoolTimeout 20ms, IdleTimeout 20ms, PoolSize 100 & 
   IdleCheckFrequency 1 min. Let's say all the connection in the pool are 
   used and a connection finishes its operation. Then will the request for a 
   new connection wait till the IdleCheck is run in 1 min interval?
   2. If I specify PoolSize 100 will the client keep open 100 connections 
   to redis even if there is no active client operation being performed to 
   Redis?

Environment:-

   1. Go - 1.7.4
   2. Redis - 3.2.6
   3. Go-Redis - v5.2

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] cgo - 'runtime.h' file not found in MacOSX

2016-12-15 Thread DM
I am trying to execute the cgo program as mentioned here 


package main

/*
#include "runtime.h"

int goId() {
return g->goid;
}
*/
import "C"
import "fmt"

func main() {
 x := C.goId()
 fmt.Printf("Id - %d", x)
}


On running the above program I am getting the below error:-

jab-MacBook-Pro-4:src debraj$ go build gid.go
# command-line-arguments
./gid.go:4:10: fatal error: 'runtime.h' file not found
#include "runtime.h"
 ^
1 error generated.


If I change the header to be like below:-

#include 


then it is giving me the below error:-

jab-MacBook-Pro-4:src debraj$ go build gid.go
# command-line-arguments
./gid.go:7:9: error: use of undeclared identifier 'g'
return g->goid;
   ^
1 error generated.


Environment:-


   - MacOSX - 10.11.6
   - Go - 1.7.3

Can someone let me know how can I run the above program in MacOSX?


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Golang periodically executing a go routine

2016-12-21 Thread DM
I am trying write a small golang program which will periodically execute lsof 
-i: to check number of open TCP connections at a port. Code looks 
like below:-

package main

import (
"fmt"
"log"
"os/exec"
"strings"
"sync"
"time"
)

type Lsof struct {
Command  string
Pid  string
User string
Fd   string
Type string
Device   string
SizeOff  string
Node string
Name string
TCPState string
}

//var result = make([]*Lsof, 0)
var ports = []int{30001, 30002}

func main() {
done := make(chan bool)
ticker := time.NewTicker(5 * time.Millisecond)
go func() {
for t := range ticker.C {
fmt.Println("Tick at", t)
connectionsCount()
}
}()
<-done
}

func connectionsCount() {
var wg sync.WaitGroup
wg.Add(len(ports))
for _, v := range ports {
go count(v, wg)
}
wg.Wait()
}

func count(port int, wg sync.WaitGroup) {
defer wg.Done()
var tcpState = make(map[string]int)
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -i:%d", 
port)).Output()
if err != nil {
log.Fatal(err)
}
//fmt.Println(string(out))
num := strings.Split(string(out), "\n")
for no, n := range num {
if no == 0 {
continue
}
n = strings.TrimSpace(n)
if len(n) <= 0 {
continue
}
i := 0
temp := strings.Split(n, " ")
cleanedVal := make([]string, 10)
for _, v := range temp {
v = strings.TrimSpace(v)
if len(v) <= 0 {
continue
}
cleanedVal[i] = v
i++
}
if len(cleanedVal) < 8 {
//log.Println(n)
continue
}
l := new(Lsof)
l.Command = cleanedVal[0]
l.Pid = cleanedVal[1]
l.User = cleanedVal[2]
l.Fd = cleanedVal[3]
l.Type = cleanedVal[4]
l.Device = cleanedVal[5]
l.SizeOff = cleanedVal[6]
l.Node = cleanedVal[7]
l.Name = cleanedVal[8]
if l.Node == "TCP" {
l.TCPState = cleanedVal[9]
count, ok := tcpState[l.TCPState]
if !ok {
tcpState[l.TCPState] = 1
} else {
tcpState[l.TCPState] = count + 1
}
}
//fmt.Printf("\n%+v", *l)
//result = append(result, l)
}
fmt.Printf("Port=%d ", port)
for k, v := range tcpState {
fmt.Printf("{TCP State=%s,Value=%d},", k, v)
}
fmt.Println()
}


But on running the program I am seeing the ticker is not ticking 
periodically. It is just ticking once:-

Tick at 2016-12-21 14:37:03.847694697 +0530 ISTPort=30002 {TCP 
State=(LISTEN),Value=2},Port=30001 {TCP State=(LISTEN),Value=2},

Can someone let me know what is going wrong?

   - Go Version - 1.7.3

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Golang periodically executing a go routine

2016-12-22 Thread DM
Thanks :) .

On Wednesday, 21 December 2016 15:42:55 UTC+5:30, Axel Wagner wrote:
>
> You need to pass the WaitGroup as a pointer. This way, connectionsCount 
> creates a WaitGroup, increments it's counts, passes a copy of it to count 
> and then waits on the original; count, however, only Done()s its copy.
>
> go vet should probably complain about that, as it contains an appropriate 
> marker to not be copied.
>
> On Wed, Dec 21, 2016 at 10:35 AM, DM > 
> wrote:
>
>> I am trying write a small golang program which will periodically execute 
>> lsof 
>> -i: to check number of open TCP connections at a port. Code looks 
>> like below:-
>>
>> package main
>>
>> import (
>> "fmt"
>> "log"
>> "os/exec"
>> "strings"
>> "sync"
>> "time"
>> )
>>
>> type Lsof struct {
>> Command  string
>> Pid  string
>> User string
>> Fd   string
>> Type string
>> Device   string
>> SizeOff  string
>> Node string
>> Name string
>> TCPState string
>> }
>>
>> //var result = make([]*Lsof, 0)
>> var ports = []int{30001, 30002}
>>
>> func main() {
>> done := make(chan bool)
>> ticker := time.NewTicker(5 * time.Millisecond)
>> go func() {
>> for t := range ticker.C {
>> fmt.Println("Tick at", t)
>> connectionsCount()
>> }
>> }()
>> <-done
>> }
>>
>> func connectionsCount() {
>> var wg sync.WaitGroup
>> wg.Add(len(ports))
>> for _, v := range ports {
>> go count(v, wg)
>> }
>> wg.Wait()
>> }
>>
>> func count(port int, wg sync.WaitGroup) {
>> defer wg.Done()
>> var tcpState = make(map[string]int)
>> out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -i:%d", 
>> port)).Output()
>> if err != nil {
>> log.Fatal(err)
>> }
>> //fmt.Println(string(out))
>> num := strings.Split(string(out), "\n")
>> for no, n := range num {
>> if no == 0 {
>> continue
>> }
>> n = strings.TrimSpace(n)
>> if len(n) <= 0 {
>> continue
>> }
>> i := 0
>> temp := strings.Split(n, " ")
>> cleanedVal := make([]string, 10)
>> for _, v := range temp {
>> v = strings.TrimSpace(v)
>> if len(v) <= 0 {
>> continue
>> }
>> cleanedVal[i] = v
>> i++
>> }
>> if len(cleanedVal) < 8 {
>> //log.Println(n)
>> continue
>> }
>> l := new(Lsof)
>> l.Command = cleanedVal[0]
>> l.Pid = cleanedVal[1]
>> l.User = cleanedVal[2]
>> l.Fd = cleanedVal[3]
>> l.Type = cleanedVal[4]
>> l.Device = cleanedVal[5]
>> l.SizeOff = cleanedVal[6]
>> l.Node = cleanedVal[7]
>> l.Name = cleanedVal[8]
>> if l.Node == "TCP" {
>> l.TCPState = cleanedVal[9]
>> count, ok := tcpState[l.TCPState]
>> if !ok {
>> tcpState[l.TCPState] = 1
>> } else {
>> tcpState[l.TCPState] = count + 1
>> }
>> }
>> //fmt.Printf("\n%+v", *l)
>> //result = append(result, l)
>> }
>> fmt.Printf("Port=%d ", port)
>> for k, v := range tcpState {
>> fmt.Printf("{TCP State=%s,Value=%d},", k, v)
>> }
>> fmt.Println()
>> }
>>
>>
>> But on running the program I am seeing the ticker is not ticking 
>> periodically. It is just ticking once:-
>>
>> Tick at 2016-12-21 14:37:03.847694697 +0530 ISTPort=30002 {TCP 
>> State=(LISTEN),Value=2},Port=30001 {TCP State=(LISTEN),Value=2},
>>
>> Can someone let me know what is going wrong?
>>
>>- Go Version - 1.7.3
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Resolving 'cannot find package' error with vendor in go 1.7

2017-01-11 Thread DM
I have a project structure which looks like below:-

session-service
_libs   //Contains all the external dependencies
... // Other packages


Content of _libs looks like below:-

github.com 
golang.org 
x
  net
gopkg.in

My Makefile looks like below:-

.PHONY: deploy

LOGLEVEL ?= 1
CONFIGFILE ?= 2
GOFLAGS ?= $(GOFLAGS:)

PWD = $(shell pwd)export GOPATH = $(shell echo 
$$GOPATH):$(PWD)/_libs:$(PWD)export GOBIN = $(PWD)/binexport GOROOT = $(shell 
echo $$GOROOT)

deploy: clean build install 

build:
@rm -rf pkg/ 2>/dev/null
@rm -rf _libs/pkg/ 2>/dev/null
@go build $(GOFLAGS) ./...

install:
@go install ./...

clean:
@go clean $(GOFLAGS) -i ./...

## EOF


Everything is working fine. Now I am thinking of moving to vendor. So I 
renamed my _libs to vendor and modified my Makefile like below:-

export GOPATH = $(shell echo $$GOPATH):$(PWD)


But after this I started getting the following error:-

vendor/golang.org/x/net/html/charset/charset.go:20:2: cannot find package 
"golang.org/x/text/encoding" in any of:

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/vendor/golang.org/x/text/encoding
 (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding (from $GOPATH)

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/src/golang.org/x/text/encoding
vendor/golang.org/x/net/html/charset/charset.go:21:2: cannot find package 
"golang.org/x/text/encoding/charmap" in any of:

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/vendor/golang.org/x/text/encoding/charmap
 (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/charmap (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/charmap (from $GOPATH)

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/src/golang.org/x/text/encoding/charmap
vendor/golang.org/x/net/html/charset/charset.go:22:2: cannot find package 
"golang.org/x/text/encoding/htmlindex" in any of:

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/vendor/golang.org/x/text/encoding/htmlindex
 (vendor tree)
/usr/local/go/src/golang.org/x/text/encoding/htmlindex (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/encoding/htmlindex (from $GOPATH)

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/src/golang.org/x/text/encoding/htmlindex
vendor/golang.org/x/net/html/charset/charset.go:23:2: cannot find package 
"golang.org/x/text/transform" in any of:

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/vendor/golang.org/x/text/transform
 (vendor tree)
/usr/local/go/src/golang.org/x/text/transform (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/text/transform (from $GOPATH)

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/src/golang.org/x/text/transform
vendor/golang.org/x/net/http2/h2i/h2i.go:38:2: cannot find package 
"golang.org/x/crypto/ssh/terminal" in any of:

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/vendor/golang.org/x/crypto/ssh/terminal
 (vendor tree)
/usr/local/go/src/golang.org/x/crypto/ssh/terminal (from $GOROOT)
/Users/debraj/golang/src/golang.org/x/crypto/ssh/terminal (from $GOPATH)

/Users/debraj/golang/src/bitbucket.org/myntra/session-service/src/golang.org/x/crypto/ssh/terminal



Environment:-

   - go version go1.7.3 darwin/amd64
   - Mac OS X 10.11.6

Can someone let me know why I am getting the above errors with vendor but 
everything works fine with _libs?


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.