[go-nuts] Working with characters in strings

2016-10-29 Thread so . query
I understand that strings are immutable sequences of bytes and wanted to know how to idiomatically work with the "characters" within a string. For example how should I approach the following operations - Convert a string to a []string (slice or array). eg. "foobar" to ["f" "o" "o" "b" "

[go-nuts] Working with "characters" in strings

2016-10-29 Thread so . query
I know that strings are an immutable sequence of bytes, so what would be the most idiomatic way to handle the following operations. - Convert a string to []string (slice) or [n]string (array). Eg. "foobar" to ["f" "o" "o" "b" "a" "r"] - Iterate through a string and evaluate the run

[go-nuts] Re: Working with "characters" in strings

2016-10-29 Thread so . query
thanks! whats the "a:b" in this instance? did you mean s[i:i+1]? wouldn't that return a slice? so when iterating I'm comparing/using runes but what is the best way to refer to the ASCII values? On Saturday, October 29, 2016 at 9:36:57 AM UTC-7, Tamás Gulácsi wrote: > > 1. create the slice (s

Re: [go-nuts] Re: Working with "characters" in strings

2016-10-30 Thread so . query
thanks rob! On Saturday, October 29, 2016 at 1:24:02 PM UTC-7, Rob 'Commander' Pike wrote: > > Please read blog.golang.org/strings. > > -rob > > > On Sat, Oct 29, 2016 at 12:08 PM, > wrote: > >> thanks! whats the "a:b" in this instance? did you mean s[i:i+1]? wouldn't >> that return a slice? >>

[go-nuts] Rune-by-rune through a stream

2016-11-05 Thread so . query
Just a thought experiment, but what's the idiomatic way to read rune-by-rune from a stream that represents a string of infinite length? The stream itself can be from std.In or continually generated by a function. Would I use bufio.Scanner or bufio.Reader? I suppose its also possible to use a ch

[go-nuts] Re: Rune-by-rune through a stream

2016-11-06 Thread so . query
Thanks everyone for the examples and suggestions! I suppose the difference the between bufio.Reader versus bufio.Scanner is that Scanner provides specific tokenizing rules/functions designed for reading text while Reader is a more general data reader (and as Tamás stated adds buffering to io.Re

[go-nuts] Partial Variable Assignment

2016-11-11 Thread so . query
I thought it was possible to do partial assignment where, if one variable is already declared and a new one is not. https://stackoverflow.com/questions/39028645/golang-variable-assignment In the below example ok has been declared prior, but v has not. Trying to run the below results in an error

[go-nuts] Re: Partial Variable Assignment

2016-11-12 Thread so . query
thanks for clearing that up! On Friday, November 11, 2016 at 6:49:35 PM UTC-8, so.q...@gmail.com wrote: > > > I thought it was possible to do partial assignment where, if one variable > is already declared and a new one is not. > https://stackoverflow.com/questions/39028645/golang-variable-assig

[go-nuts] How to cast type alias and interface to int

2016-12-20 Thread so . query
How would I cast type alias MyInt and interface Foo, to an int? https://play.golang.org/p/Sb80WoKh4Y -- 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+

[go-nuts] Re: How to cast type alias and interface to int

2016-12-20 Thread so . query
Thanks! On Tuesday, December 20, 2016 at 1:13:35 AM UTC-8, Volker Dobler wrote: > > Like > bar = int(foo.(MyInt)) > that's: type-assert that foo is a MyInt and convert the MyInt to int. > > V. > > Am Dienstag, 20. Dezember 2016 09:45:33 UTC+1 schrieb so.q...@gmail.com: >> >> How would I cast

[go-nuts] Applying idiomatic Golang patterns to other languages?

2017-01-16 Thread so . query
Just curious how often you find yourself applying idiomatic Go patterns to other languages? (JavaScript, Python, C#, Java) For instance returning and handling an error value as opposed to throw-try-catch. I understand this isn't the best example since try-catch exceptions are more closely align

[go-nuts] How to idiomatically display chained errors?

2017-02-04 Thread so . query
Is there a idiomatic recommendation for generally displaying errors resulting from chained methods? The following would print out "ERROR: Foo() ERROR: Bar() ERROR: stdlib.Func() something went wrong with this standard function call", which feels obviously wrong. func main() { if err := F

Re: [go-nuts] How to idiomatically display chained errors?

2017-02-04 Thread so . query
So put each on a newline? On Saturday, February 4, 2017 at 12:17:45 AM UTC-8, Sander van Harmelen wrote: > > Did you check the errors package: https://godoc.org/github.com/pkg/errors > ? > > It offers a great way to wrap chained

Re: [go-nuts] How to idiomatically display chained errors?

2017-02-04 Thread so . query
I don't see an "Errors" subsection under the Methods chapter (6). Could you write a short example? On Saturday, February 4, 2017 at 3:50:49 PM UTC-8, oso wrote: > > You should avoid to put newline. I recommend you to have a look at > "Errors" (which is under Method section) section of http://www

[go-nuts] Are external test packages recommended?

2017-02-04 Thread so . query
I generally favor "external test packages", that is having "_test" as a suffix to my test package names. For example, "package foo" (foo.go) would have a test file (foo_test.go) named "package foo_test" I do so under the belief that it forces me to test against my package's public interface and

[go-nuts] Re: Are external test packages recommended?

2017-02-05 Thread so . query
I see the distinction, thanks for the feedback and confirmation! On Saturday, February 4, 2017 at 9:48:48 PM UTC-8, Dave Cheney wrote: > > On Sunday, 5 February 2017 15:39:55 UTC+11, so.q...@gmail.com wrote: > > I generally favor "external test packages", that is having "_test" as a > suffix to

Re: [go-nuts] How to idiomatically display chained errors?

2017-02-06 Thread so . query
That does look better. Are there any other examples from the Go source I can look at it? On Sunday, February 5, 2017 at 1:56:51 PM UTC-8, Lars Seipel wrote: > > On Sat, Feb 04, 2017 at 12:08:20AM -0800, so.q...@gmail.com > wrote: > > The following would print out "ERROR: Foo() ERROR: Bar() E

[go-nuts] Using React with Golang? and does it make sense?

2017-02-06 Thread so . query
Correct me if I'm wrong, but in serving web apps and sites. Golang simply fills in the blanks for predefined templates. React appears to be a bit more complicated requiring the creation of JavaScript/JSX classes representing the view. Having that rendered on the server-side and the difference a

[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-06 Thread so . query
Thanks for the comment. You said that Node is not required. But I thought react components are actually JavaScript objects. Would my Golang API server be responding back to requests with those JavaScript objects for the React library to render on the client's browser? On Monday, February 6,

[go-nuts] Re: Using React with Golang? and does it make sense?

2017-02-07 Thread so . query
Thanks for going into detail for me! On Monday, February 6, 2017 at 8:57:23 PM UTC-8, Kevin Powick wrote: > > > On Monday, 6 February 2017 23:37:15 UTC-5, so.q...@gmail.com wrote: >> >> >> You said that Node is not required. But I thought react components are >> actually JavaScript objects. >>

[go-nuts] Are the tests in the Go source code considered "Unit" tests?

2017-02-14 Thread so . query
>From my understanding Unit Tests should focus on testing a single feature and not use the filesystem. But in the Go source (https://github.com/golang/go) I saw several tests that would violate those conditions. Should we strive to follow more standard conventions in our own unit tests? or are

Re: [go-nuts] Are the tests in the Go source code considered "Unit" tests?

2017-02-15 Thread so . query
I see, Thank you both for your comments. On Wednesday, February 15, 2017 at 7:23:25 AM UTC-8, Ian Lance Taylor wrote: > > On Tue, Feb 14, 2017 at 10:35 PM, > > wrote: > > > > From my understanding Unit Tests should focus on testing a single > feature > > and not use the filesystem. > > >

[go-nuts] How do you implement and use Context.Done?

2017-02-17 Thread so . query
I'm not sure how to implement and use the Done function and its returned channel for contexts. https://golang.org/pkg/context/#Context The comments say to refer to https://blog.golang.org/pipelines, but I didn't see any example there. Can you provide an example of how to implement a context tha

Re: [go-nuts] How do you implement and use Context.Done?

2017-02-19 Thread so . query
Thanks, I see you build it up with decorators on a standard prototype. For example: https://play.golang.org/p/PJy5lE9QqF So context.Done is a convenience function for those that require it? Otherwise a context will expire after it leaves scope, so Done does not need to be called? On Friday,

Re: [go-nuts] How do you implement and use Context.Done?

2017-02-20 Thread so . query
I see thanks for the additional detail. On Monday, February 20, 2017 at 11:42:48 AM UTC-8, Ian Lance Taylor wrote: > > On Sun, Feb 19, 2017 at 2:57 PM, > > wrote: > > Thanks, I see you build it up with decorators on a standard prototype. > > For example: https://play.golang.org/p/PJy5lE9QqF

[go-nuts] Import path search order?

2017-02-20 Thread so . query
What is the search order for the import path? for example, relative then vendor then workspace? -- 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+unsub

[go-nuts] Re: Import path search order?

2017-02-21 Thread so . query
Thanks! what do you mean by "from left to right"? And by GOROOT, you mean it looks at the go source? On Tuesday, February 21, 2017 at 1:27:59 AM UTC-8, Nathan Kerr wrote: > > Relative package don't need to be searched for, they are explicit > (indicated with ./ or ../) > > Then it seems to be

[go-nuts] Re: Import path search order?

2017-02-21 Thread so . query
Thanks for the clarification! On Tuesday, February 21, 2017 at 10:00:41 AM UTC-8, Nathan Kerr wrote: > > GOPATH is a list > , though it > usually only contains one element. The first element in the list is the > leftmost one (e.g., GO

[go-nuts] Are relative import paths idiomatic?

2017-02-22 Thread so . query
Is it recommended or acceptable to use relative import paths, particularly for nested packages? or should I typically always use the full path? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving ema

[go-nuts] Re: Are relative import paths idiomatic?

2017-02-22 Thread so . query
Ok, Thanks for the answer! On Wednesday, February 22, 2017 at 9:46:26 AM UTC-8, Diego Medina wrote: > > Hi, > > Not recommended, it's better to be explicit by using the full import path, > even if it feels odd at first, other users reading your code will know > exactly where the packages are. >

[go-nuts] How to render a single webpage without templates?

2017-03-08 Thread so . query
In my handler I want to return a single webpage. But when using http.ServeFile, the images on the page aren't rendered. https://golang.org/pkg/net/http/#ServeFile And using http.FileServer, returns a handler that renders an entire directory (and children) https://golang.org/pkg/net/http/#FileSer