Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Tim Hawkins
That is a lofty goal, and not always achievable, many libraries are not self contained and often wrap other non-go libraries or device integration libraries that don't support that model. What people do inside a library should not be a language feature, otherwise the language is becoming overly op

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread as . utf8
I wasn't referring to concurrency within package scope, but data crossing package boundaries (the earlier post says libraries' are responsible to ensure data passed *to* them is safe). The map type reveals an implementation detail by documenting that it isn't safe for parallel use. On Friday,

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Henry
The implementation of map is not a valid argument to "unboxing the black boxes". The question to ask is who does the concurrency. In the case of map, if the user is the one accessing the map concurrently, then it is the user's responsibility to ensure the map is concurrent safe. If the map int

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread as . utf8
I mostly agree, but there are times when abstraction leads to complex code and more reasonable approach involves documented constraints. The map type is not safe either, but it enjoys widespread use. If it were abstracted to handle all possible use-cases, it would be unnecessarily slow for most

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Henry
Libraries should be more like black boxes. The user shouldn't need to know about their implementation, be it concurrent or not. It is the libraries' responsibility to ensure any data passed to them is safe. -- You received this message because you are subscribed to the Google Groups "golang-nu

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread ojucie
On Friday, June 24, 2016 at 3:27:43 PM UTC-3, Nick Pavlica wrote: > > It makes me want to just wrap every variable in a Mutex to be safe. > A sure path to craziness. > I'm guessing that the pattern is to keep Go programs as small as possible > so you can track all the corner cases effective

Re: [go-nuts] golang poll/epoll/select

2016-06-24 Thread graham4king
If you have a specific case that isn't covered by blocking in a go-routine, you can always use the syscall's directly, with a very similar API to what you would do in C. For example here's the epoll ones in stdlib: https://golang.org/pkg/syscall/#EpollCreate New syscall wrappers are in the x/

Re: [go-nuts] golang poll/epoll/select

2016-06-24 Thread Ian Lance Taylor
On Fri, Jun 24, 2016 at 2:44 PM, wrote: > Unfortunately I don't think this works if you want to do something like poll > stdin, skipping EOFs in a non-busy-waiting pattern. > > A simple poll() in C works fine for this, but I can't figure out how do this > this in Go because it does not provide a

Re: [go-nuts] Interface{} constrains on specific types

2016-06-24 Thread 'Thomas Bushnell, BSG' via golang-nuts
The trick is to do this: Decl special_interface and then special_interface requires an unexported interface which you implement in the specific (new) types that you can store in the thing. On Fri, Jun 24, 2016 at 3:10 PM 'Mihai B' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I'm de

Re: [go-nuts] golang poll/epoll/select

2016-06-24 Thread msoulier
Unfortunately I don't think this works if you want to do something like poll stdin, skipping EOFs in a non-busy-waiting pattern. A simple poll() in C works fine for this, but I can't figure out how do this this in Go because it does not provide a poll. Maybe I'm missing something. Mike On Thu

[go-nuts] Interface{} constrains on specific types

2016-06-24 Thread 'Mihai B' via golang-nuts
I'm developing a json schema generator (json schema from Go ast and the other way around). There is a keyword "oneOf" which requires exactly one schema to be valid in this keyword's value. In Go I translate it by using an empty interface{}. The issue is that when I convert the interface{} to

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Justin Israel
On Sat, 25 Jun 2016, 6:27 AM Nick Pavlica wrote: > > > On Thursday, June 23, 2016 at 6:44:22 PM UTC-6, Caleb Spare wrote: >> >> > To see if the the >> > race detector would find this potential bug for me, I ran the code with >> the >> > mutex(s) commented out with the -race flag on and didn't ge

[go-nuts] x/text/runes: How can i replace LF by CRLF ?

2016-06-24 Thread mhhcbon
Hi, I have a small func like this func WriteAsWindows1252 (src string, dst string) error { bSrc, err := ioutil.ReadFile(src) if err != nil { return err } bDst := make([]byte, len(bSrc)*2) replaceNonAscii := runes.Map(func(r rune) rune { if r > unicode.MaxASCII {

[go-nuts] Re: x/text/runes: How can i replace LF by CRLF ?

2016-06-24 Thread mhhcbon
I forgot to mention another difficulty i have using replacement. As it will receive only one rune at a time in runes.Map(func(r rune) rune {}) If the file already contains \r\n, i guess i will be doubling the \r, resulting in an ugly \r\r\n Any ideas ? Le vendredi 24 juin 2016 22:54:35 UTC+2

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 11:27:43 -0700 (PDT) Nick Pavlica wrote: [...] > > > mutex(s) commented out with the -race flag on and didn't get a > > > warning. > > > > Did you make some concurrent requests? The race detector only tells > > you about races that happen, so you need to excercise the > > c

[go-nuts] Re: How to be safe in Go?

2016-06-24 Thread adonovan via golang-nuts
On Thursday, 23 June 2016 20:27:21 UTC-4, Nick Pavlica wrote: > > While learning Go from the book "The Go Programming Language", by > Addison-Wesley I was working through an example and was taken back by how > easy it is to cause a data race. > I'm glad you appreciated this risk, but I hope it d

Re: [go-nuts] Custom syscall.Sockaddr

2016-06-24 Thread Elliot Morrison-Reed
SocketCAN has been part of mainline linux since kernel 2.6.25 (so getting close to a decade now), and it is pretty much the standard for all CAN bus communication on linux. Thanks for the hint, I will look into adding support in the golang.org/x/sys/unix package. Regards, Elliot On Fri, Jun 24,

[go-nuts] Re: Porting Go to New Platforms

2016-06-24 Thread Efraim Sealman
Hello, Can you please share some info about how you made the go binary to run on QNX? Aram, Can you please share what have you done for solaris to support go compiler? Watched the video that you posted and couldn't get much from it. Couldn't find the slides though. We're looking to make the

Re: [go-nuts] How to be safe in Go?

2016-06-24 Thread Nick Pavlica
On Thursday, June 23, 2016 at 6:44:22 PM UTC-6, Caleb Spare wrote: > > > To see if the the > > race detector would find this potential bug for me, I ran the code with > the > > mutex(s) commented out with the -race flag on and didn't get a warning. > > Did you make some concurrent requests?

Re: [go-nuts] Custom syscall.Sockaddr

2016-06-24 Thread Ian Lance Taylor
On Fri, Jun 24, 2016 at 8:05 AM, wrote: > > I am trying to set up an interface from Go to SocketCAN > (https://www.kernel.org/doc/Documentation/networking/can.txt). This > implements the linux socket interface, however it is a completely separate > socket type from the regular AF_INET or AF_UNIX

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Joubin Houshyar
On Friday, June 24, 2016 at 1:16:12 PM UTC-4, Joubin Houshyar wrote: > > > On Friday, June 24, 2016 at 7:39:23 AM UTC-4, Konstantin Khomoutov wrote: >> >> On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) >> dc0d wrote: >> >> > To shuffle items in a slice I'm doing this: >> > >> > var res []Item >>

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Joubin Houshyar
On Friday, June 24, 2016 at 7:39:23 AM UTC-4, Konstantin Khomoutov wrote: > > On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) > dc0d > wrote: > > > To shuffle items in a slice I'm doing this: > > > > var res []Item > > > > //fill res logic > > > > shuffle := make(map[int]*Item) > > for k, v := r

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Thanks Val for explanation & clarification; On Friday, June 24, 2016 at 5:24:30 PM UTC+4:30, Val wrote: > > The playground caches everything, so running multiple times the same > program will just serve the previously generated output. > > Also in the playground everything is frozen at some point

Re: [go-nuts] Re: [ANN] Gomail v2: sending emails faster

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 07:08:54 -0700 (PDT) Bernard LEGAUT wrote: > I recently switch from go 1.5.1 to go 1.6, and gomail seems to get in > trouble. What's the actual problem? People with strong telepathic skills are rare and far in between. Also, does `go get -u` for gomail solve the problem?

[go-nuts] Custom syscall.Sockaddr

2016-06-24 Thread elliotmr
Hello All, I am trying to set up an interface from Go to SocketCAN (https://www.kernel.org/doc/Documentation/networking/can.txt). This implements the linux socket interface, however it is a completely separate socket type from the regular AF_INET or AF_UNIX socket types. The sockaddr struct f

[go-nuts] Re: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-24 Thread David Marceau
The core problem was: w.Header().Set("Content-Disposition","attachment;filename=" + strOutputFileOfJournalctl) Should actually be: w.Header().Add("Content-Disposition","attachment;filename=" + strOutputFileOfJournalctl) I preferred to put the above line before the serveFile. That's all. Thanks

[go-nuts] Re: [ANN] reform, a better ORM, reaches v1, moves to gopkg.in

2016-06-24 Thread Tong Sun
Thanks for open up and sharing you fourth milestone Alexey. I have the following questions: - how to define the relations between multiple tables? - how to deal with the case that a table has a composite primary key instead of just a single-field primary key? The answers are better in the readm

[go-nuts] Re: [ANN] Gomail v2: sending emails faster

2016-06-24 Thread Bernard LEGAUT
I recently switch from go 1.5.1 to go 1.6, and gomail seems to get in trouble. Anyone with the same issue ? Thanks, On Wednesday, September 2, 2015 at 8:55:26 AM UTC-3, Alexandre Cesaro wrote: > > Hi, > > I just released the second version of Gomail >

Re: [go-nuts] How to init a global map

2016-06-24 Thread Tong Sun
Two thumbs up, Val! FTA, all your valuable input has been archived and documented at https://github.com/suntong/lang/blob/master/lang/Go/src/ds/Map-Set1.go https://github.com/suntong/lang/blob/master/lang/Go/src/ds/Map-Set0.go Thanks again! On Fri, Jun 24, 2016 at 9:43 AM, Val wrote: > These q

[go-nuts] Re: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-24 Thread David Marceau
Here is what is in my import. Maybe I should be looking in goji instead of net/http? import ( "fmt" "net" "time" "strconv" "strings" "os" "encoding/json" "net/http" "crypto/tls" "crypto/rand" "github.com/gorilla/mux" "github.com/goji/httpauth"

Re: [go-nuts] How to init a global map

2016-06-24 Thread Val
These questions are not dumb. On the contrary, "by reference" vs "by values" is a fundamental question in most languages, and the source of many headaches when used incorrectly so it's worth taking some time to ask and get it right. Yes you may change the values of an existing map, inside any f

[go-nuts] Re: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-24 Thread David Marceau
I tried to repeat the same ordering as the iris infrastructure within the function, but it still behaves not as expected. It does not show the file->save... dialog. It shows the file within the browser as a web page. func blah (w http.ResponseWriter, r *http.Request) { strOutputFileOfJourn

Fwd: [go-nuts] How to init a global map

2016-06-24 Thread Tong Sun
*(Thanks a lot for all your help Val!)* One last question, which I wasn't able to find myself from https://blog.golang.org/go-maps-in-action Since a map is a pointer, for any function that take map as a parameter, or function like, func (s set) Something(xxx) Does it means the map values can b

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Martin Geisler
On Fri, Jun 24, 2016 at 1:05 PM, dc0d wrote: > > Hi; > > To shuffle items in a slice I'm doing this: > > var res []Item > > //fill res logic > > shuffle := make(map[int]*Item) > for k, v := range res { > shuffle[k] = &v > } > res = nil > for _, v := range shuffle { > res = append(res, *v) > } >

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Val
The playground caches everything, so running multiple times the same program will just serve the previously generated output. Also in the playground everything is frozen at some point in the past : the clock, the randomness sources, and you can't make outgoing requests to import randomness from

[go-nuts] Re: Shuffle Items in a Slice

2016-06-24 Thread Val
2 implementations here : http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go As for the map iteration trick, the runtime doesn't guarantee to randomize anything, although it often tries to, so developers don't rely on some specific order. I've seen (in the past) some map iteration

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Kaveh Shahbazian
Thanks Martin for the clarification! Yet this inconsistent behavior is daunting. What version of Go is playground using? x86? GopherJS? Better be something wrong with playground! :) On Fri, Jun 24, 2016 at 5:08 PM Martin Geisler wrote: > On Fri, Jun 24, 2016 at 1:05 PM, dc0d wrote: > > > > Hi;

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Please explain what other properties are you referring to? I'm using this to choose from a list of tickets/tokens from database to reduce contention (CouchDB). So being cryptographic is not a concern here but rather being fast. And if I'm not mistaken package rand uses a mutex internally - I th

Re: [go-nuts] Re: [ANN] primegen.go: Sieve of Atkin prime number generator

2016-06-24 Thread gordonbgood
On Saturday, 18 June 2016 17:54:45 UTC+7, ⚛ wrote: > > On Saturday, June 18, 2016 at 12:21:21 AM UTC+2, gordo...@gmail.com wrote: >> >> On Friday, June 17, 2016 at 4:48:06 PM UTC+2, gordo...@gmail.com wrote: >> Have you tried compiling > > > eratspeed with a new version of GCC to see how it

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Jan Mercl
map ranging randomization has to be fast - at the cost of the randomization other properties. Use instead perhaps https://golang.org/pkg/math/rand/#Rand.Perm to get a random slice of indexes of a proper length. Later range that slice instead and indirectly use the original slice item at the particu

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 04:05:49 -0700 (PDT) dc0d wrote: > To shuffle items in a slice I'm doing this: > > var res []Item > > //fill res logic > > shuffle := make(map[int]*Item) > for k, v := range res { > shuffle[k] = &v > } > res = nil > for _, v := range shuffle { > res = append(res, *v) > }

[go-nuts] Re: can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-24 Thread David Marceau
Again, I want to clarify the file does arrive in the browser, but I want to ensure the "file->save..." dialog appears in the web browser when it arrives. I found some older code I wrote a couple of years ago that was behaving as expected: w.Header().Set("Content-Type", "application/octet-st

[go-nuts] Shuffle Items in a Slice

2016-06-24 Thread dc0d
Hi; To shuffle items in a slice I'm doing this: var res []Item //fill res logic shuffle := make(map[int]*Item) for k, v := range res { shuffle[k] = &v } res = nil for _, v := range shuffle { res = append(res, *v) } Which inserts items into a map then ranges over that map. Ranging over a map

Re: [go-nuts] russian language books about Go

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 13:10:42 +0600 Oleg Puchinin wrote: > Where I can find subject ? Did you google? Off the top of my head, http://golang-book.ru/ and then you can have buy printed books, see https://toster.ru/q/300184 Also note that there exists a golang-ru mailing list and a VK public commu

Re: [go-nuts] Re: undefined: syscall.LoadLibrary

2016-06-24 Thread Konstantin Khomoutov
On Fri, 24 Jun 2016 03:22:23 -0700 (PDT) Andrew Mezoni wrote: > >> So, how exactly does this method work with Linux shared libraries? > > It does not work on Linux. > On Linux you should use the methods: > > dlclose, dlopen, dlmopen - open and close a shared object > > http://man7.org/linux/ma

[go-nuts] Re: undefined: syscall.LoadLibrary

2016-06-24 Thread Andrew Mezoni
>> So, how exactly does this method work with Linux shared libraries? It does not work on Linux. On Linux you should use the methods: dlclose, dlopen, dlmopen - open and close a shared object http://man7.org/linux/man-pages/man3/dlopen.3.html -- You received this message because you are subsc

[go-nuts] Re: undefined: syscall.LoadLibrary

2016-06-24 Thread Andrew Mezoni
>> But when I try this on linux I get: Linux does not have a `LoadLibrary` Also Linux does not have `kernel32.dll` and so on. P.S. The `LoadLibrary` also in `kernel32.dll` library which are only on Windows. https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms684175(v=vs.85).aspx -- You r

[go-nuts] russian language books about Go

2016-06-24 Thread Oleg Puchinin
Hello ! Where I can find subject ? Oleg. -- 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: