matteo galeotti | 7 Jul 12:07 2015
Picon

Nagle's algorithm

Hi! Why Nagle's algorithm is disabled by default ?
I mean, I was searching for this function because I need it disabled ( I am writing a game server ), but for "not real-time-responsive" application should it be enabled ?

The doc:

func (*TCPConn) SetNoDelay

func (c *TCPConn) SetNoDelay(noDelay bool) error

SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.


So, have i misunderstood something or it is really disabled by default ? And if yes, why ? This algorithm is useful on the 99% application cases!


Have a nice day !

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Florin Patan | 7 Jul 11:21 2015
Picon

Add go version to $GOPATH/pkg

Hi,


I have the following two go sdks, one for 1.4 and one for tip and I'd like to reuse the same $GOPATH value.
The "fun" part begins when I compile a package with tip then with 1.4 or vice versa. Now I have to either append "-a" to the build / run / test commands or to rm -rf $GOPATH/pkg, which I forget from time to time.
As such, would it be possible to have a structure for $GOPATH/pkg which includes the go version I've used to compile the packages? I'm thinking something like $GOPATH/pkg/$goVersion/$arch.
I know currently Go 1.5 is closed for such changes but I'd rather target this for 1.6.
If there's a better way to manage this please let me know, I'd be happy to learn about it.


Thank you.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Nick Craig-Wood | 7 Jul 09:26 2015

time.Ticker not being garbage collected

This program (run locally) starts 1000000 go routines each of which
starts a ticker then closes the goroutines down again in an orderly fashion

http://play.golang.org/p/zy5X4hAq0I

It sleeps at the end so you can run top or equivalent.  If you do you'll
see it using a lot of CPU at this point.  kill the process with -QUIT
and you'll find that this is the only goroutine of significance running.

goroutine 100005 [running]:
runtime.siftdownTimer(0xe0a)
	/usr/local/go/src/runtime/time.go:265 +0xbf fp=0xc21641a768 sp=0xc21641a718
runtime.timerproc()
	/usr/local/go/src/runtime/time.go:172 +0x1cb fp=0xc21641a7e0
sp=0xc21641a768
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc21641a7e8
sp=0xc21641a7e0
created by runtime.addtimerLocked
	/usr/local/go/src/runtime/time.go:113 +0x1ba

It appears that all those tickers got leaked and the code is spending
all the CPU keeping them up to date.

Naively I was expecting that once the goroutines returned they would be
garbage collected but that doesn't appear to be the case.

This is easy to fix of course (with NewTicker and Stop()), but is it
expected that the tickers aren't garbage collected?

-- 
Nick Craig-Wood <nick@...> -- http://www.craig-wood.com/nick

--

-- 
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+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.

Tim K | 7 Jul 02:24 2015
Picon

Calling into a C library: cgo vs. some other local IPC

Let's say I'm working on a piece of code in Go (and I'm new to Go) that needs to make some calls to a library written in C. The library is not trivial but also not horribly complicated: about a dozen typedefs/structs and about 50 function calls (could potentially grow over time). The functions when called will either get some data from somewhere else and return it or take some data from the caller and send it/write it to some other system.The choices I have:

(1) cgo and call directly into the C library. The problem here is that I'm not a C expert and the C library makes heavy use of pointers to structs and to primitive types that the caller must allocate (e.g. the typical C int* len, data_t* data, uint8* buf). From briefly looking at cgo it seems that I would have to allocate memory and free it on the Go side, at least in some cases. Memory management and leaks scare me :)

(2) Suggest to the library author (coworker of mine) to provide and RPC/IPC type service to the library that I could simply connect to from Go, e.g. via a unix socket or some other form of RPC/IPC (e.g. gRPC).  Any suggestions here and how to deal with the authentication/authorization part? I'd like to make sure that it's secure even though it will run on the same machine.

Performance is not the main concern (as long as it's not horrible and too heavy handed, e.g. HTTP/REST/JSON API would be too much). Correctness is.

Any recommendations between (1) and (2)? Have you tackled a similar problem?

Thank you.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tyler Compton | 6 Jul 20:00 2015
Picon

Doing Business Logic

I'm working at a company that uses Java for their web server. They use Drools to implement their business logic, a library that uses scripts to generate a Java class on runtime to check form information and the like. I'm not necessarily convinced that this is the end-all way to do this kind of thing, but I am curious to hear how people do business logic in Go. Writing it directly into the code like normal would be fine, but there's something to be said for isolating something so potentially volatile from the main code base. I think it would be pretty cool to implement the logic through Lua scripts and have the Go code pass form data through it, especially since we have github.com/Shopify/go-lua now.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Guohua Ouyang | 6 Jul 15:35 2015
Picon

strings.ToTitle vs strings.ToUpper

Hi there,

I found there is no difference between the examples of these two methods, am I missing something or is it a bug of strings.ToTitle?
Regards,
Guohua

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
pgbgnet | 6 Jul 10:31 2015
Picon

Need help for Golang how to call a package function/s by string name from another package and send the struct data to it

Hello all :),
I`m new in Golang and have a problem with calling a package function/s by string name from another package.
i read a lot of this topic and still can`t find a solution for my problem :(
This is the first time i write anything on the web forums ever so please excuse me for the noob writing.
I will try to give you as much info as possible for my problem so ..

I'm trying to build web base small framework with dynamic struct of data looking like this :

1.Framework core functions location is : ../src/core/myStruct
package myStruct {

  type MFunc map[string]func();
  type MapStr map[string]string;
  ....

  type TableRec struct {
      TABLE_OPTIONS  TableData;  // table options from JSON file
      FIELDS MapData;            // fields from JSON file
      .....
      METHODS   MapStr;
     // METHODS   MFunc; // MFunc get a error :`(  =>( EXTRA *json.SyntaxError=invalid character 'F' looking for beginning of value)
  }

}

2.load JSON from System1 location : ../src/sys/System1/tables
Json file ..:
{
        "TABLE_OPTIONS" : {
          "TABLE_NAME": "FORM_INS",
          "SYSTEM_ON" : "System1",
            ...........
    },
    "METHODS" : {
        //"on_insert" : Form_ins_insert // error from MFunc

        "on_insert"   : "Form_ins_insert"  //MapStr work :/ 
          ......
    }, 
    "FIELDS" : {
        "ID" : {
            "TYPE"   : "INT",
            "VALUE"  : 0,
            "OPTIONS": { "RO": 1 , "HID": 0 }
        },
        "NAME" : {
                "SEP": { "en" : "Person Data" , "bg" : "Данни за клинета" },
            "LABEL":  {  "en" : "Full name","bg" : "Пълно име"  },
            "TYPE": "CHAR",
            "VALUE": "",
            "SIZE" : 200,
            "OPTIONS": {"ROW": 2 , "ROW_SIZE": 100  }
        },
        ......
    }
    .....
}

3  Must call func from System1 (or System2, or System3 ...) and send it the struct with the data i push in the struct in the core

 location : ../src/sys/System1/methods

package methods

import (
    "fmt"
    _ "../core/myStruct"   
)

func Form_ins_insert(rec *TableRec) (html string) {
  fmt.Println("================== Form_ins_insert ================");
  fmt.Println("\t\t on table =",rec.TABLE_OPTIONS.TABLE_NAME);
 
  // i must get to this point but have 0 ideas how :`( .....

 
  return html;
}


4 !!!! THE PROBLEM PART !!!!!

And the "callerFunc" (the relay station) calling System1,..,SystemN

location : ../src/sys

package sys

import (
    "fmt"
     "../core/myStruct"
     _ "../sys/System1/methods"
     _ "../sys/System2/methods"  // i thing i must set all systems here 1 by one ...
)

func CallSysMeth(rec *myStruct.TableRec, name string) {
    myRec := rec;
     
    fmt.Println("================== CallSysMeth ================");
    fmt.Println("======method name to call =",name," , Struct=",myRec.METHODS);

    // THIS PART IS LOST IN TRANSLATION FOR ME ?!?!?!?!?!?!?!?!?!?!?!?!
    // how to call system1 from "rec.TABLE_OPTIONS.SYSTEM_ON" with method name "Form_ins_insert" and send it the struct ????

    ......
}

I`m open for any ideas what ever how to make it work but how to make it better.
Keep in mind that every "table" can have a different methods and any "system" can have this methods and tables so i must call system from the "rec.TABLE_OPTIONS.SYSTEM_ON" with the method from "METHODS" list.
I decide to make it in JSON objects for flexibility so small changes like changing the labels (translating ) ор OPTIONS can be made without server restarts compiles and so on.




--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Kai Backman | 6 Jul 09:59 2015

Architecture prefix in $GOPATH/bin similar to $GOPATH/pkg

Gophers,

I've recently shed the oppression of a custom build system for the goodness that is the standard build tools. However, I haven't figured out a way to conveniently store multiple binary versions in the same GOPATH when building in a Vagrant box on Mac. The Mach-O and ELF binaries clash in $GOPATH/bin and 'go build' refuses to rebuild given the timestamps on the binary are fresh.

In the custom build system there would be a similar subdirectory structure in $GOPATH/bin as in $GOPATH/pkg which nicely resolves the issue. Is there something I'm missing? A quick search through the group did not turn up anything helpful.

Take care,

  Kai

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Klaus Post | 6 Jul 14:27 2015
Picon

[ANN] Dictionary Password Validation package

Hi!

I have created a package for dictionary password validation for Go.

If you have a site where users have passwords, and you don't already do dictionary checks, I would strongly recommend you look at this.


This can be used to protect your bcrypt/scrypt/PBKDF encrypted passwords against dictionary attacks. This is much more of a threat than brute force attacks, and is of course done by checking them against a dictionary (no magic).

I have written a blog post called Password Requirements Done Better (it could also be called why password requirements help hackers). With this library my intention is to make it as easy as possible for you to check passwords quickly and effectively against a dictionary.




You are able to use your own database and password dictionary. Currently the package supports importing common dictionary formats, and has built-in "drivers" for MongoDB, BoltDB, MySQL and PostgreSQL. If you decide to write your own database connection, there are functions to help you test that they function correctly.

I have just finished up the documentation and tests, but I am very open to suggestions, and if your favorite database is missing feel free to request it.


Best regards, Klaus


PS. Have a nice Gophercon - wish I was going!

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
LMR | 6 Jul 10:00 2015
Picon

Growing GO

FYI
http://redmonk.com/sogrady/2015/07/01/language-rankings-6-15/

highlight:
A year ago, we predicted that Go would become a Top 20 language within a six to twelve month timeframe. Six months ago, it achieved that goal landing as the #17 language in our January rankings. In this quarter’s run, Go continues on that same trajectory, up another two spots to #15. In the process, it leapfrogged Haskell and Matlab. While the language has appeared at times to be in the trough of disillusionment following an extended honeymoon period, none of the periodic criticism has had any apparent impact on the project’s growth. And with an increasingly strategic foundational role within projects that are themselves strategic, Go’s future appears bright. It’s also worth considering whether the Supreme Court decision could eventually, indirectly lead to a more significant change in Go’s fortunes given recent project activity.
--

However, I encourage the power to be :) to help its corporate adoption with new features, tooling etc. Enterprise adoption is very important and we don't want to see it relegated to yet another fringe language...

thank you

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Arun Ayyar | 4 Jul 10:58 2015
Picon

2-D array access in go vs C

I have the following code in C where I attempt to access elements of a two D int array

#include 
#include 
void main ()
{

int tr_nextstate[8][2] = {{0, 4}, {4, 0}, {5, 1}, {1, 5}, {2, 6}, {6, 2}, {7, 3}, {3, 7}};
int i, j,next_state=0;

clock_t start, end;
double cpu_time_used;
start = clock();

for (i = 0; i < 100000000; i++)
{
j = i % 2;
next_state = tr_nextstate[next_state][j];

} end = clock();

cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC*1000;
printf("fun() took %f milliseconds to execute \n", cpu_time_used);

}

I have the same code in go :

package main

import (
"fmt"
"time"
)

func main() {
tr_nextstate := [][]int{{0, 4}, {4, 0}, {5, 1}, {1, 5}, {2, 6}, {6, 2}, {7, 3}, {3, 7}}

next_state := 0 var j int startTime := time.Now() for i := 0; i < 100000000; i++ { j:= i % 2 next_state = tr_nextstate[next_state][j] } fmt.Printf("\nTime Elapsed : %v", time.Since(startTime))

}

When I run both the codes in my machine.
C - code gives a runtime of roughly 400 milliseconds
Go-code gives a runtime of roughtly 550 milliseconds

Can anyone throw light on why so? Is there any way to make the go code faster ?

My machine runs kubuntu 15.04 with i5 <at> 2.4GHz with 16GB RAM

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane