Re: [go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread 'Bryan C. Mills' via golang-nuts
On Wed, Jan 24, 2018 at 3:00 PM, Christian LeMoussel wrote: > Thank you Bryan for your advice. > In examples, I see how to pass the Go pointers directly. > > For example : > h := C.CString(name) > defer C.free(unsafe.Pointer(h)) > gerrno, err := C.getaddrinfo(h,

[go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Tamás Gulácsi
if the main goroutine exits, all other goroutines exit, too. -- 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

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread 'Axel Wagner' via golang-nuts
On Wed, Jan 24, 2018 at 8:59 PM, dc0d wrote: > It is as described in the spec. Regarding the specs it's correct. But > that's not the reason. > You didn't ask for a reason this time, you ask for what is happening. > The original question is about the "why". > > Why

[go-nuts] Flag package issue when nonflag argument string begins with a minus sign

2018-01-24 Thread erisa
I have a CLI program that uses the flag package and has one flag and takes a string as its only nonflag argument. The string can be a complex expression, but it is possible that the first character of the string is a minus sign. This parses correctly: powerseries -nterms=10 "x ^ 10" But this

Re: [go-nuts] How to broadcast a graceful server shutdown down the road?

2018-01-24 Thread Joris Berthelot
Hi Justin, Thank you for your answer. The thing is, from my understanding, the request context is done once the HTTP response has been returned so if my goroutines rely on this context, it's cancelled as soon as the response is sent. I would like my goroutines to be cancelled only when a

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread roger peppe
Why? Consider this code. When c is first evaluated, it's ok to send on, so it would evaluate f, but f causes c to be not ready, so f has been evaluated even though c cannot be sent on. package main import ( "log" "time" ) func main() { c := make(chan int,

[go-nuts] Re: Flag package issue when nonflag argument string begins with a minus sign

2018-01-24 Thread Scott Pakin
On Wednesday, January 24, 2018 at 11:00:37 AM UTC-7, erisa wrote: > > I have a CLI program that uses the flag package and has one flag and takes > a string as its only nonflag argument. The string can be a complex > expression, but it is possible that the first character of the string is a >

[go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread Christian LeMoussel
Thank you Bryan for your advice. In examples, I see how to pass the Go pointers directly. For example : h := C.CString(name) defer C.free(unsafe.Pointer(h)) gerrno, err := C.getaddrinfo(h, nil, , ) To h := make([]byte, len(name)+1) copy(h, name) gerrno, err :=

[go-nuts] Re: golang with single-page HTML.

2018-01-24 Thread matthewjuran
One way is the server still serves all of those endpoints, but instead of returning a full HTML page they each just return data. The single page state depends on what data is received when each is queried. Using a template for the single page is a way to set an initial state. jQuery has easy

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread dc0d
It is as described in the spec. Regarding the specs it's correct. But that's not the reason. The original question is about the "why". Why is that so? This behavior was unexpected. On Wednesday, January 24, 2018 at 11:20:01 PM UTC+3:30, Axel Wagner wrote: > > Both the channel and the value

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread 'Axel Wagner' via golang-nuts
> > Both the channel and the value expression are evaluated before > communication begins. Communication blocks until the send can proceed. A > send on an unbuffered channel can proceed if a receiver is ready. A send on > a buffered channel can proceed if there is room in the buffer. A send on a >

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread Marvin Renich
* dc0d [180124 14:44]: > > > > > If the channel is nil, there's nothing to lock. But also, there's no > > sending happening. > > > > So first the payload is computed and then the nil check happens? To add to what Axel said, it would be inconsistent to only evaluate

[go-nuts] Re: Graven: Build tool for Go projects.

2018-01-24 Thread matthewjuran
You are using interfaces to define a type. The overhead of interface isn’t necessary to achieve the same goal. I see that github.com/gorilla also uses this pattern in places. Supporting another tool or providing a mock for testing is just making a new value of the type. I do use sub-packages

Re: [go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Matt Harden
When the program exits, all goroutines die instantly. The doc is saying that the program does not wait for any goroutine to complete except the "main" goroutine (the one that invoked the function main at startup). If you do want to wait for other goroutines to exit before exiting the program,

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread dc0d
You are right Alex. And seems I am wrong and it does not really matter that much and is not a fruitful topic. -- 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

Re: [go-nuts] Re: Web Framework for Beginners

2018-01-24 Thread Glen Newton
I am not going to be popular expressing this, but I really really really like gowut: https://github.com/icza/gowut Just write (drop-dead simple) Go code for SPA, AJAX handled transparently, no fiddling with Javascript. See: Gowut - Showcase of Features

[go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Sundar Nadathur
Thank you both for the replies. Hi Tamas, I am wondering about: go func() { <-sigCh cancel() } If the program exits normally, presumably sigCh channel will not get notified, and this goroutine will continue to run. How do we ensure that it quits on normal program exit? Regards,

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread dc0d
> > If the channel is nil, there's nothing to lock. But also, there's no > sending happening. > So first the payload is computed and then the nil check happens? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group

[go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Sundar Nadathur
I am probably mis-understanding or missing something. The golang spec says: Program execution begins by initializing the main package and then invoking the function main. When that function invocation returns, the program exits. *It does not

[go-nuts] Re: resource cleanup in closure

2018-01-24 Thread 'simon place' via golang-nuts
thanks for the interest, a Done method would be what i was thinking of by the type/object way to do it, rather than the closure way of handing-back/defering a func. but its the isolation i'm thinking about, without some way to get the garbage collector to call code,( like in the original post

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread roger peppe
On 24 January 2018 at 20:58, Axel Wagner wrote: > On Wed, Jan 24, 2018 at 9:12 PM, roger peppe wrote: >> >> Why? Consider this code. When c is first evaluated, it's ok to send >> on, so it would >> evaluate f, but f causes c to be not ready, so

Re: [go-nuts] Re: Web Framework for Beginners

2018-01-24 Thread Michael Masouras
I second what Shawn said, I just use the standard library. Whenever I need something not quite covered (or an easier abstraction), I use gorilla . On Wed, Jan 24, 2018 at 6:16 AM, dc0d wrote: > gobuffalo has a

[go-nuts] Re: golang with single-page HTML.

2018-01-24 Thread Glen Newton
Try https://github.com/icza/gowut https://gowut-demo.herokuapp.com/show Glen On Wednesday, January 24, 2018 at 4:24:51 PM UTC-5, matthe...@gmail.com wrote: > > One way is the server still serves all of those endpoints, but instead of > returning a full HTML page they each just return data.

[go-nuts] Re: First time building a rest-api-based web app: general security-related questions

2018-01-24 Thread Pat Farrell
The first answer depends on more questions to language independent requirements such as: 1) are you using TLS/HTTPS for first tier traffic protection? 2) what threat model do you have (what threats do you worry about? what do you deliberately ignore? Who are the bad guys? 3) How valuable is the

[go-nuts] URL handling

2018-01-24 Thread Michael Jones
Why doesn’t url.PathEscape convert a $ to a %24? Looking at HTML specs that’s what seems should happen. Thanks Michael -- Michael T. Jones michael.jo...@gmail.com -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group

[go-nuts] get_tls macro and friends

2018-01-24 Thread Caleb Spare
Quick question about the Go assembler. I'm trying to use the get_tls and related macros mentioned near the bottom of https://golang.org/doc/asm. Although the line # include "go_asm.h" doesn't give an error, subsequent lines where I use the macro fail: get_tls(CX) // unrecognized instruction

Re: [go-nuts] get_tls macro and friends

2018-01-24 Thread Rob Pike
If you run go build with the -work flag, you can see the directory in which the build happens, and go_asm is written there. -rob On Thu, Jan 25, 2018 at 2:25 PM, Caleb Spare wrote: > Quick question about the Go assembler. > > I'm trying to use the get_tls and related macros

Re: [go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Sundar Nadathur
Thank you! Got it. Regards, Sundar On Wednesday, January 24, 2018 at 3:23:04 PM UTC-8, Matt Harden wrote: > > When the program exits, all goroutines die instantly. The doc is saying > that the program does not wait for any goroutine to complete except the > "main" goroutine (the one that

[go-nuts] Re: Gorilla Sessions Example Question

2018-01-24 Thread aikiav8r
Thanks - apparently I wasnt quite getting the -I argument correct with logout to make all of it work. I still have a little confusion about why the contents of the old cookie were not invalidated, to keep a newbie from doing stupid things like I was trying. Thanks again ! -Lynch > >> --

[go-nuts] First time building a rest-api-based web app: general security-related questions

2018-01-24 Thread ofbizfanster
i come from a java and c# background, and have built webapps the "classic" way (i.e., jsp, asp.net, cookies, server-side rendering, occasionally ajax, etc) i am about to build my first (eventually) medium-sized web app, where the server-side would just be serving up data rest-api style, and

[go-nuts] syscall.SetNonblock stopped working in Go 1.9.3

2018-01-24 Thread Dave Keck
Hey all, this program exits (as expected) when run with macOS 10.12.6 + Go 1.8.6, but it deadlocks when run with Go 1.9.3: https://play.golang.org/p/Dw_ND9gkgPm The same behavior is observed when using unix.SetNonblock instead of syscall.SetNonblock. It appears that the SetNonblock()

Re: [go-nuts] Web Framework for Beginners

2018-01-24 Thread Burak Serdar
Revel is a good one. https://revel.github.io/ On Wed, Jan 24, 2018 at 6:49 AM, pradam wrote: > Hi Gophers, > > As for Newbie to Go.I am excited to learn a web framework but I don't know > where to start please help me out by suggesting a good framework for >

[go-nuts] Ensuring resource cleanup when app is killed

2018-01-24 Thread Tamás Gulácsi
func main() { if err := Main(); err != nil { log.Fatal(err) } } func Main() error { ctx, cancel := cintext.WithCanvel(context.Background()) defer cancel() sigCh := make(chan signal.Signal, 1) go func() { <-sigCh cancel() } signal.Notify(sigCh, signal.Interrupt) ...

Re: [go-nuts] Web Framework for Beginners

2018-01-24 Thread Shawn Milochik
Don't use a framework. Use the standard library. It does everything you need. When you find something that you don't want to do "manually," go find a package that you *plug into* your code. When you start with a framework, you're accepting thousands of decisions made by others. Many of them will

[go-nuts] Re: Web Framework for Beginners

2018-01-24 Thread dc0d
gobuffalo has a nice workflow (I've used it for two in-house apps). On Wednesday, January 24, 2018 at 5:20:05 PM UTC+3:30, pradam wrote: > > Hi Gophers, > > As for Newbie to Go.I am excited to learn a *web framework* but I > don't know where to start please help me out

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread Ian Lance Taylor
On Tue, Jan 23, 2018 at 10:13 PM, dc0d wrote: > > The third option was the expected one. Locking aside (as the thought line > behind the original question), the time spent on preparing/calculating a > result value to be sent to a channel, is not directly relevant to

Re: [go-nuts] Ensuring resource cleanup when app is killed

2018-01-24 Thread Ian Lance Taylor
On Tue, Jan 23, 2018 at 11:20 PM, Sundar Nadathur wrote: > > My golang application creates UNIX sockets in specific paths: > /mypath/name1.sock, /mypath/name2.sock etc. It then launches a go routine > that listens to one or more of those sockets. I need to ensure that they

[go-nuts] Re: "type MyByte byte", then how to convert []MyByte to []byte so that I can use bytes.Xyz functions for []MyByte?

2018-01-24 Thread digg
On Wednesday, January 24, 2018 at 8:35:25 AM UTC-5, Volker Dobler wrote: > > See https://golang.org/doc/faq#convert_slice_with_same_underlying_type > > On Wednesday, 24 January 2018 13:57:59 UTC+1, di...@veryhaha.com wrote: >> >> except unsafe ways. >> > > Yes: explicit loop. > > Why did you do

Re: [go-nuts] Re: How to pass Go []byte (arrays/slices) as C *char to C functions

2018-01-24 Thread 'Bryan Mills' via golang-nuts
It may be considerably more efficient to pass the Go pointers directly. To do so, you may need to convert through unsafe.Pointer. Note that many C APIs that take a char* expect it to be null-terminated, so if you take that approach you may need to append an extra 0 to the slice.

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread 'Axel Wagner' via golang-nuts
If the channel is nil, there's nothing to lock. But also, there's no sending happening. But the conceptual locking Ian mentions is there no matter whether you a) first compute the value and then wait to be able to send, or b) first wait to be able to send and then compute the value. In both

Re: [go-nuts] Unused code warnings

2018-01-24 Thread mrx
On Tue, Jan 23, 2018 at 2:53 PM, Paul Jolly wrote: > Take a look at unused: > > https://github.com/dominikh/go-tools > > That will help you to eliminate unused code pre compile time. > Thanks a lot, that will help for sure! // Patrik -- You received this message because you

[go-nuts] "type MyByte byte", then how to convert []MyByte to []byte so that I can use bytes.Xyz functions for []MyByte?

2018-01-24 Thread digg
except unsafe ways. -- 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

[go-nuts] Ensuring resource cleanup when app is killed

2018-01-24 Thread Sundar Nadathur
My golang application creates UNIX sockets in specific paths: /mypath/name1.sock, /mypath/name2.sock etc. It then launches a go routine that listens to one or more of those sockets. I need to ensure that they get cleaned up (removed) at the end. I tried the obvious thing -- use defer in main()

[go-nuts] Re: "type MyByte byte", then how to convert []MyByte to []byte so that I can use bytes.Xyz functions for []MyByte?

2018-01-24 Thread Volker Dobler
See https://golang.org/doc/faq#convert_slice_with_same_underlying_type On Wednesday, 24 January 2018 13:57:59 UTC+1, di...@veryhaha.com wrote: > > except unsafe ways. > Yes: explicit loop. Why did you do type MyByte byte in the first place? Extra methods on your byte? V. -- You received

[go-nuts] Email sent via command line is not delivered in Golang

2018-01-24 Thread Amandeep Kaur
I am sending emails in one of my projects through command line. The project back end is written in Golang. I am using following code to send emails: package utils import( "bytes" "html/template" "os/exec" "fmt" ) type EmailRequest struct{

Re: [go-nuts] "type MyByte byte", then how to convert []MyByte to []byte so that I can use bytes.Xyz functions for []MyByte?

2018-01-24 Thread Ian Davis
A loop is the usual way. On Wed, 24 Jan 2018, at 12:57 PM, d...@veryhaha.com wrote: > except unsafe ways. > > -- > 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

[go-nuts] Re: Email sent via command line is not delivered in Golang

2018-01-24 Thread Ain
Cross-posted to SO: https://stackoverflow.com/questions/48421688/email-sent-via-command-line-is-not-delivered-in-golang ain kolmapäev, 24. jaanuar 2018 13:49.05 UTC+2 kirjutas Amandeep Kaur: > > > > > I am sending emails in one of my projects through command line. The > project back end is

[go-nuts] Web Framework for Beginners

2018-01-24 Thread pradam
Hi Gophers, As for Newbie to Go.I am excited to learn a *web framework* but I don't know where to start please help me out by suggesting a good framework for beginners. thank you, -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread dc0d
Is this applied when the channel is nil? Does select statement first lock the channel then check if it's nil? On Wednesday, January 24, 2018 at 6:07:50 PM UTC+3:30, Ian Lance Taylor wrote: > > On Tue, Jan 23, 2018 at 10:13 PM, dc0d > wrote: > > > > The third option

[go-nuts] How to broadcast a graceful server shutdown down the road?

2018-01-24 Thread Joris Berthelot
Hello everybody, First post in this group, I'm a bit new for the language (I've been more and less writing Go for a year now) and I have a question for you guys. I would like to know how to broadcast a HTTP server shutdown to any running goroutines launched by HTTP handlers. From what I

[go-nuts] Re: Graven: Build tool for Go projects.

2018-01-24 Thread Clinton Begin
Hi Matt, thanks for the review. Here is some feedback and explanation. >> Does BuildTool need to be an interface? Having methods on a pointer to nothing (type GoBuildTool struct{}) seems unnecessary to me. Interfaces are expressions of functional contract, and have little dependency or basis