[go-nuts] Re: political fundraising on golang.org!

2020-06-14 Thread Amnon Baron Cohen
I, for one, applaud the posting of the banner.

Solidarity!

On Sunday, 14 June 2020 14:36:38 UTC+1, peterGo wrote:
>
> Recently, a political message with a fundraising link appeared as a banner 
> atop golang.org websites: https://golang.org/, https://pkg.go.dev/.
>
> content/static: add Black Lives Matter banner to top of site
> https://go-review.googlesource.com/c/website/+/237589
>
> 
> Black Lives Matter.
> https://support.eji.org/give/153413/#!/donation/checkout;
>target="_blank"
>rel="noopener">Support the Equal Justice Initiative.
> 
>
> How was this decision made?
>
> Go is a programming language. For political fundraising use personal 
> Twitter and Facebook accounts. 
>
> Peter
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4b27cc7e-5714-459b-8358-5b7f9511be82o%40googlegroups.com.


[go-nuts] Re: what is the complexity of regexp.MustCompile()?

2020-06-08 Thread Amnon Baron Cohen
Should we care?

Regular expressions are generally small. 
So the asymptotic complexity is not particularly important.

But regular expressions are often used to search large amounts of input.

regexp gives us fast, guaranteed linear search times.
But we pay for this with slower compilation times.

In my opinion, this is a good tradeoff.



On Wednesday, 3 June 2020 18:07:12 UTC+1, Ray Pereda wrote:
>
> I believe that the complexity of regexp.MustCompile() 
>  is linear based on this 
> comment in the regexp package overview. 
> 
>
> "The regexp implementation provided by this package is guaranteed to run 
> in time linear in the size of the input"
>
>
> What is the complexity of regexp.MustCompile() 
> ? Is it linear in the length 
> of the regular expression?
>
> -ray
>
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/162b28e7-bd81-47d4-afb7-7fe9f8a15b8do%40googlegroups.com.


[go-nuts] Re: Need help with go modules

2020-05-23 Thread Amnon Baron Cohen
I would work through

https://golang.org/doc/code.html

- Amnon

On Friday, 22 May 2020 12:59:03 UTC+1, lj0...@gmail.com wrote:
>
> It looks like I am not only one to struggle with (new?) go modules. 
> I still consider me as novice to GO but the major problem is as usual, the 
> focus. 
>
> 1. Modules are complicated to understand
> 2. Lack of examples (of real use, not just POC)
> 3. Focus on extra (scale up) details (that are surely important) and none 
> of focus on basic things (which are essentially more important as they make 
> things working and not working)
>
> I have spent several days in attempt to make a working module and I 
> failed. 
> I learned a lot of things on the way but still did not manage to make a 
> working example.
> The working example in my understanding shall be given as:
>
> Variant 1: Making executable
>
> 1. how the main (executable) uses the module (import and function call, 
> how to avoid function name conflicts?)
> 2. how to build a module that 1.(main program uses)
> 3. how and where to compile and what and what compilation output to expect
>
> Variant 2: Making library
>
> In a way a module is a library but, one may want to make his own library 
> that will be used in his project and within that library use his custom 
> modules, so we go the same
>
> 1. how library modules uses the custom module (import and function call 
> and how to avoid function name conflicts from different modules?
> and 
> 2. which shall be the same as for Variant 1. How really to make a working 
> module.
> 3. which shall be the same as for Variant 1. how and where to compile and 
> what and what compilation output to expect
>
> this is more a feedback on what conceptually I am struggling with go and 
> modules
>
> ---
>
> On the other note the relation between gopath and modules. Currently (I am 
> trying to use go 1.14) I understand that there is a method of 'gopath' 
> where go will seek for libraries. This goes to compilation part.
>
> Say have i have a custom module site/name/module (literally)
>
> what i put in package part? what would be relation between main and 
> others. In others - is there package site/name ?
> where to put sources so go finds them?  (while compilation gopath method 
> suggests where to put sources - it is a help but is this correct way of 
> doing things?
> how to compile these sources so it is explained which modules are used 
> (and from where)?
> if I just compile a module - what do I get ? If I get some sort of an 
> object - where to look for it? How it is called? How do I reference it from 
> the source.
>
> For example in my experimental trials I get (a hello world executable 
> trying to call function defined in a module)
>
> I am getting error: 'site/name/module' imported and not used
> of course since module is not found
> I also get error: undefined: Hello 
> which is a function I try to call.
>
> Hope all of these make sense, and possibly someone wrote somewhere 
> something of these but so far I did not find it. And I LIKE reading 
> documentation, but documentation is just partially helpful.
>
> Thanks
>
>
>
>
>
>
>
>
>
>
>
> On Tuesday, May 5, 2020 at 1:28:55 PM UTC+2, Amnon Baron Cohen wrote:
>>
>> Interesting. At first sight this should work.
>>
>> You definitely don't need a go.mod file in ~HOME/src/myrepo/cmd/cmd1
>>
>> Which go version are you running?
>>
>> What is your $GOPATH set to?
>>
>> What output does cd ~HOME/src/myrepo; go build give?
>>
>> The usual convention is to push the code in a VCS such as github and use 
>> the vcs path as an argument to go mod init
>>
>> e.g.
>> go mod init github.com/myuser/myrepo
>>
>> - Amnon
>>
>> On Monday, 4 May 2020 14:59:22 UTC+1, web user wrote:
>>>
>>> I have a personal project using GOPATH
>>>
>>> But recently, I wanted to use go-redis for a project and v7 forces you 
>>> to use go mod. So I figured, I'd migrate the account over to go mod. But 
>>> I'm stuck. 
>>>
>>>
>>> My directory structure is:
>>>
>>> ~HOME/src/myrepo
>>> ~HOME/src/myrepo/cmd/cmd1
>>> ~HOME/src/myrepo/commong
>>> ~HOME/src/github
>>>
>>> So I did the following command: cd ~HOME/src/myrepo; go mod init 
>>> ~HOME/src/myrepo
>>>
>>> when I run the command go build ~HOME/src/myrepo/cmd/cmd1/...
>>>
>>> It does not update the go.mod in the directory ~HOME/src/myrepo? Do I 
>>> need a go.mod in ~HOME/src/myrepo/cmd/cmd1
>>>
>>>
>>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/592b93a4-1508-49db-b8f1-a82237ba88ff%40googlegroups.com.


[go-nuts] Re: How to work with multiple environment like dev, test, staging, prod in golang ?

2020-05-17 Thread Amnon Baron Cohen
My advice is to use the same application-dev.yml,   application-test.yml, 
application-prod.yml YAML files 
that you are familiar with, and have your application read its config from 
them.

Changing language does not mean that you have to change the way you 
configure your application.

On Sunday, 17 May 2020 18:19:23 UTC+1, Shishira Pradhan wrote:
>
> Hi All,
>
> i'm a java developer, currently working on golang. In springboot, we have 
> configuration like port, database etc info are stored in yaml files like 
> application-dev.yml,   application-test.yml, application-prod.yml profiles, 
> and profile name is passed during running the application to load profile 
> specific configuration. I need to understand that how to load/pass profile 
> based properties in golang ?
>
> Thanks,
> shishira
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/48ca49ae-0d0f-4148-86d4-88c65b21a62e%40googlegroups.com.


[go-nuts] Re: Type Assertion on File type

2020-05-08 Thread Amnon Baron Cohen
The beautiful thing about Go is that it is statically typed,
so you don't need to check if your function returned an *os.File.
The compiler already did it  for you

On Thursday, 7 May 2020 17:57:05 UTC+1, André kouamé wrote:
>
> Hi,
>
> I want to check, if the value return by my function has the type *os.File
> This my code :
> func createFile(filename string) (*os.File, error) {
> f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
> return f, err
>
> }
> //Test code
> filename := "testfile"
> f, _ := createFile(filename)
> c := (*os.File)
> fmt.Println(c)
> Error return : 
> invalid type assertion: f.(*os.File) (non-interface type *os.File on left) 
> Process exiting with code: 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b67843f8-1a87-4feb-bd01-3fc85951c3ea%40googlegroups.com.


[go-nuts] Re: DisableKeepAlive not being honored in http.transport

2020-05-07 Thread Amnon Baron Cohen
In these situations I would normally use wireshark to look at the 
life-cycle of a single session.
Which direction are the FIN and RST packets going?
Are they sent from the client, or the server?
If the RST packets are sent by the server - i.e. the server is slamming 
shut the connection,
then the client can not reuse them and has to create new ones.

If foo is https, then this does make it harder to use tcpdump to look at 
the headers.
But you can print out the response headers sent bt foo.com using 
https://golang.org/pkg/net/http/httputil/#DumpResponse
and this should give you a bit more information.

Hope this helps...
- Amnon

On Thursday, 7 May 2020 15:13:04 UTC+1, Ryan Rank wrote:
>
> This is what I did, and see no change in behavior.
>
> for i := 0; i < 10; i++ {
> response, err :=client.Get("https://foo.com;)
> if err!= nil{
> panic(err)
> }
> ioutil.ReadAll(response.Body)
> response.Body.Close()
> }
>
> The network trace shows a SYN, SYN-ACK, ACK at the beginning of each HTTP 
> GET, and a FIN-ACK followed by some RST packets (those RSTs are common for 
> the foo.com in this case).
>
> I do know that foo.com honors keepalives because it's readily apparent 
> when I use *ab *to test.
>
> Also, I did upgrade to go 1.14.2 and nothing changed.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/33d4eca3-e80a-458b-9cdd-51fe6b674632%40googlegroups.com.


[go-nuts] Re: DisableKeepAlive not being honored in http.transport

2020-05-06 Thread Amnon Baron Cohen
Connections are indeed reused where possible by default in the Go standard 
library.
But as http (before http2) does not support multiplexing, it is not 
possible to reuse
a connection which is still in use (i.e. which is still in the process of 
reading the response).
These means that the body of the http response does need to be read till 
completion
and then closed by the client.

So you will want to do something like

for i := 0; i < 10; i++ {
r, err := client.Get("https://foo.com;)
if err != nil {
   panic(err)
}
io.Copy(os.Stdout, r)
r.Close()
}

Hope this helps
- Amnon

On Wednesday, 6 May 2020 19:01:55 UTC+1, Ryan Rank wrote:
>
> I wrote a small program that runs a repeated GET against a given URL. 
> However, the DisableKeepAlives boolean does not seem to be honored. Code is 
> similar to this:
>
> transport := {
> DisableKeepAlives: false,
> }
>
> client := {
> Transport: transport,
> }
>
> for i := 0; i < 10; i++ {
> _, err := client.Get("https://foo.com;)
> }
>
> Based on the code, I would expect the HTTP session to stay alive. I ran 
> the preceding code with keepalive enabled and disabled, performance was not 
> impacted. I then did a TCPDump and saw that the TCP session was being built 
> and torn down with every HTTP Request. I have a feeling that I'm missing 
> something. Does anyone have any ideas?
>
> Go 1.11.1 on CentOS 7
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/892d54fe-3e60-438e-8e1e-d8a72b22ba3c%40googlegroups.com.


[go-nuts] Re: Need help with go modules

2020-05-05 Thread Amnon Baron Cohen
Interesting. At first sight this should work.

You definitely don't need a go.mod file in ~HOME/src/myrepo/cmd/cmd1

Which go version are you running?

What is your $GOPATH set to?

What output does cd ~HOME/src/myrepo; go build give?

The usual convention is to push the code in a VCS such as github and use 
the vcs path as an argument to go mod init

e.g.
go mod init github.com/myuser/myrepo

- Amnon

On Monday, 4 May 2020 14:59:22 UTC+1, web user wrote:
>
> I have a personal project using GOPATH
>
> But recently, I wanted to use go-redis for a project and v7 forces you to 
> use go mod. So I figured, I'd migrate the account over to go mod. But I'm 
> stuck. 
>
>
> My directory structure is:
>
> ~HOME/src/myrepo
> ~HOME/src/myrepo/cmd/cmd1
> ~HOME/src/myrepo/commong
> ~HOME/src/github
>
> So I did the following command: cd ~HOME/src/myrepo; go mod init 
> ~HOME/src/myrepo
>
> when I run the command go build ~HOME/src/myrepo/cmd/cmd1/...
>
> It does not update the go.mod in the directory ~HOME/src/myrepo? Do I need 
> a go.mod in ~HOME/src/myrepo/cmd/cmd1
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/11a98c18-6b02-4a00-907c-1cded0ba4d79%40googlegroups.com.


Re: [go-nuts] json decode is very slow

2020-05-03 Thread Amnon Baron Cohen
Excellent advice Jesper!

On Sunday, 3 May 2020 10:34:12 UTC+1, Jesper Louis Andersen wrote:
>
> The general rule is to run a corollary of Dijkstra: experiments can only 
> show the presence of problems in a system, not their absence :)
>
> That is, seek to validate your assumptions rather than trying to guess 
> what is wrong with the system.
>
> The obvious things to check against are HTTP/1.1 vs HTTP/2 operation. 
> There are times where the multiplexing nature of HTTP/2 needs some more 
> gentle coercion in order to run fast. And I wouldn't a priori assume your 
> proxy takes all of the request given the sizes of the inputs. I'd much 
> rather assume it will use some kind of small buffering. Otherwise, your 
> proxy are sitting with 512 kilobyte of data in a buffer and that is going 
> to be a problem given enough connections. It might do buffering up to 4k or 
> something such however. Above that, it is likely to start streaming the 
> data in a little bit at a time. This is definitely something to do some 
> investigation on.
>
> If you cut out GCP/GKE/ISTIO you can verify if the culprit is Go itself, 
> or something in front of it. Since you have a fast and a slow system, you 
> can slot each in and look for differences in how the system is operating.
>
> On Thu, Apr 30, 2020 at 1:14 PM Sarath Prabath Redlapalli Jaya <
> harrysa...@gmail.com > wrote:
>
>> Thanks Amnon & Hi Jesper,
>>
>> You're correct. Most of the time is actually spent in *ioutil.ReadAll()* . 
>> Trying to debug network issues related to GCP, GKE & the functionality of 
>> ISTIO sidecar reverse proxy, but seems okay so far couldn't find anything.
>>
>> But, I've performed an interesting experiment. 
>>
>> Tried the same API in Ruby with Sinatra by mirroring the traffic. When 
>> instrumented the API Response Times, all were <= 100 ms. Any clues on how 
>> to debug this?I can't seem to find much on inner workings of 
>> http.Request.Body -> io.ReadCloser
>>
>> Also, If we're are looking for flaky end-user connections i.e., mobile 
>> wireless devices etc., the connection termination is at reverse proxy 
>> itself and the lag in reading request shouldn't be observed at the 
>> application level. Correct me if I'm wrong.
>>
>> Regards
>>
>> On Thu, Apr 30, 2020 at 2:34 PM Jesper Louis Andersen <
>> jesper.lo...@gmail.com > wrote:
>>
>>> On Tue, Apr 28, 2020 at 6:48 PM Sarath Prabath Redlapalli Jaya <
>>> harrysa...@gmail.com > wrote:
>>>
 We've instrument the above code block and reading request body bytes is 
 taking very long i.e., upto 5 secs sometimes reaching upto 20 seconds at 
 the throughput of ~4-5K RPM


 The Request Body Size Metrics are as follows

 Average: 73190 Bytes
 90th percentile: 170862 Bytes
 99th percentile: 467638 Bytes


>>> Let us assume we have 500 kilobytes of data. At 20 seconds processing 
>>> time, you are looking at something like 25 bytes per millisecond, which 
>>> seems rather low for a decent CPU. Try measuring the time it takes to 
>>> ioutil.ReadAll from the Reader I assume you have access to. My hunch is you 
>>> are spending most of the time there, and relatively little on decoding the 
>>> JSON data you have. Once you've done this, you will have some more 
>>> knowledge of where to look: the network, or the JSON decoder.
>>>
>>> If this is a web request, you should also look at how time it takes the 
>>> other end to feed data to the GCP process. Chances are that the problem is 
>>> in the other end, and you are looking at a slow sender, especially if you 
>>> have a large set of mobile devices out there with variety in their internet 
>>> connections.
>>>
>>>
>
> -- 
> J.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/84af6b68-8c5c-440a-aabb-32c590764a79%40googlegroups.com.


[go-nuts] Re: json decode is very slow

2020-05-02 Thread Amnon Baron Cohen
That was my fault too. encoding/json is slow, but not that slow.

Unfortunately the title of this thread is a bit misleading.
Apparently what is taking time here is reading the data off the wire,
rather than decoding the data once it has arrived. 

So it seems that that the slowness is probably nothing to do with json 
decoding
and nothing to do with Go.

Sarath says that a Ruby implementation is fast.
So I would get tcpdump traces for both, and walk your way through the 
relevant 
sessions, and see what the differences are.

On Saturday, 2 May 2020 03:54:47 UTC+1, Jason E. Aten wrote:
>
> you could try ffjson https://github.com/pquerna/ffjson
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0b481259-43d1-4140-a206-9b747809b311%40googlegroups.com.


[go-nuts] Re: json decode is very slow

2020-04-30 Thread Amnon Baron Cohen
encoding/json is quite old and not particularly fast.
There are some other implementations  around which use code generation
rather than reflection, and which claim to give a speedup of 3x or meore

I would try one of them:
https://github.com/mailru/easyjson
or https://github.com/pquerna/ffjson

On Tuesday, 28 April 2020 17:49:08 UTC+1, Sarath Prabath Redlapalli Jaya 
wrote:
>
> req := {}
> json.NewDecoder(r.Body).Decode(req)
>
>
> We've instrument the above code block and reading request body bytes is 
> taking very long i.e., upto 5 secs sometimes reaching upto 20 seconds at 
> the throughput of ~4-5K RPM
>
> The Request Body Size Metrics are as follows
>
> Average: 73190 Bytes
> 90th percentile: 170862 Bytes
> 99th percentile: 467638 Bytes
>
> Tried ioutil.ReadAll too. But, the read time is same. We're not sure why 
> it's so very slow on production with HIGH BANDWIDTH Network line.
>
> Also, there are 5% of errors in this API with following errors while 
> decoding json data
>
>1. unexpected EOF
>2. Error in decoding request: read tcp 127.0.0.1:8080->127.0.0.1:48896: 
>i/o timeout
>
> We're using Kubernetes with Istio 1.0.5 on GCP. These errors are probably 
> from Envoy Sidecar, but since the Envoy acts as a reverse proxy, not sure 
> why we can get EOF or Timeout Errors since end user connection terminates 
> at proxy itself.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/65271a8e-ee33-4d9f-9eec-8a4f9c53fc99%40googlegroups.com.


[go-nuts] Re: the size of the files compiled in GO

2020-04-20 Thread Amnon Baron Cohen
Executable size for small programs is not a top priority in gc.
So if you care about executable size (e.g. if your code runs on 
microcontrollers,
or WASM), you may want to have a look at https://tinygo.org/ .

On Sunday, 19 April 2020 21:18:29 UTC+1, serhat...@gmail.com wrote:
>
> It is one of the first things that people who start golang wonder, also 
> another feature that makes this language unique.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/56df5937-a9a6-4e39-b54d-3f57e7be628a%40googlegroups.com.


[go-nuts] Re: [ANN] Go Brain Teasers (book)

2020-04-18 Thread Amnon Baron Cohen
give us a few samples to whet our appetite!

On Saturday, 18 April 2020 10:15:57 UTC+1, Miki Tebeka wrote:
>
> Hi,
>
> I'm happy to announce that my book is finally out. It contains 25 brain 
> teasers to tickle your mind.
> - Gumroad (ePub & PDF) https://gum.co/Qkmou
> - Amazon (mobi & dead tree) https://www.amazon.com/dp/B0876DBMFM/
>
> Speical thanks to Dave Cheney for writing the foward and inspiring some of 
> these brain teasers.
>
> Stay curious, keep hacking,
> Miki
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c91e19fc-4b5c-48aa-9c01-cd665a0a2c7e%40googlegroups.com.


[go-nuts] Re: "Timers rely on the network poller", why is that?

2020-04-17 Thread Amnon Baron Cohen
The go runtime does its waiting (both for timers and network events) in 
netpoll.

On Friday, 17 April 2020 11:10:58 UTC+1, Vincent Blanchon wrote:
>
> Hi everyone,
>
> From what I understand, timers are ran by:
> - the P holding them
> - other P if timer-stealing happen (thanks to the async preemption that 
> should not happen often)
> - sysmon thread that, periodically, check if some timers have to run
>
> But, in the comments of the code, I have seen this sentence "Timers rely 
> on the network poller". I wonder how is it related to the net poller, I do 
> not get the relation here.
> Any help is appreciated :)
>
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/29019b79-6d4a-48d2-8f0d-823ffe085e2d%40googlegroups.com.


Re: [go-nuts] testing code that uses ioutil.ReadDir?

2020-04-13 Thread Amnon Baron Cohen
"Coverage is a proxy for testing quality, but not a guarantee of it. 
Getting to 100% coverage is a better indicator of chasing metrics than of 
actually writing good tests"

Wise words indeed.
I'm going to print out this quote and frame it.
Thanks Rob! 

On Monday, 13 April 2020 17:07:25 UTC+1, K Richard Pixley wrote:
>
> On 4/10/20 4:15 PM, Ian Lance Taylor wrote: 
> > I'm not proud. Here is an example program for which os.Open(dirname) 
> > succeeds but ioutil.ReadDir(dirname) fails.  You may have to adjust 
> > pathMax and nameMax for your system.  Whether you actually want to use 
> > this technique is left to you. 
>
> Thank you.  I hadn't thought of exploiting pathname limits. 
>
> I'll probably use Rob's solution presented a couple messages down, but I 
> appreciate hearing this solution 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e5029c75-21dd-4d54-ba44-73a398eabe98%40googlegroups.com.


[go-nuts] Re: Intercepting field access and method call

2020-04-12 Thread Amnon Baron Cohen
Go is a simple language. 

Code in Go does what it says. No magic. 

That is its beauty. That is its power.

On Sunday, 12 April 2020 03:59:08 UTC+1, Tanmay Das wrote:
>
> Say you have a struct Foo and you access fields and call methods on it as 
> you normally would. But is it possible to execute a hook before or after 
> that field access or method call? A good scenario will be:
>
> The user calls non-existent method foo.Bar() or accesses non-existent 
> field foo.Bar. If they don't exist, I want to:
> a) In case of a method call: forward that call to foo.Baz()
> b) In case of field access: set the foo.Bar at runtime with some value
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c49365b1-bf56-46e4-af8c-ef9667febb2a%40googlegroups.com.


Re: [go-nuts] Go course

2020-03-29 Thread Amnon Baron Cohen
Thanks! A great write-up.

On Friday, 27 March 2020 16:32:51 UTC, Owen Waller wrote:
>
> Hi Dave,
>
> As the original author of the post that Dan has referenced, I can say that 
> Go does indeed make IMHO a good first programming language. It all comes 
> down to how you explain things. Thanks Dan for the reference :)
>
> I'm not going to repeat what the original discussion said, but let me try 
> to pick out a few things.
>
> I was teaching the very young - 10 & 11 year olds. So I had to simplify 
> things down quite a bit. So I didn't cover things like:
>
> * functions - arguments vs parameters I thought this was just too to big a 
> step. Yes they used functions, but they didn't write them, including 
> functions with no parameters and no return values.
>
> * structs - again its just to big a jump. You can do a lot with just 
> numbers and strings
>
> * Local vs global variables - again too big a jump and doesn't make sense 
> without functions.
>
> * Anything you might think of as advanced - so concurrency, testing, 
> packages and modules, file and network IO, even errors etc I left out.
>
> With an older group I'd put all of those back in except concurrency, 
> starting with functions, then packages, then IO. 
>
> But that still leaves the key things that all programming languages have 
> in common namely variables, instruction sequencing, selection and 
> repetition. In the UK this is what they have to cover at this age group. 
> This is also the order I introduce these in, and over about 15 hours. So I 
> let them work slowly. At least at this age group typing is still an issue, 
> so they need time just for that.
>
> Static typing I did not find to be a problem at all. The way I approached 
> it was simple. Kids already have a good grasp of numbers (whole and 
> fractions and decimals fractions) and words at this age. So they know that 
> writing "hello+world" in English makes no sense. The "+" symbol is only 
> used with numbers. So "1+1" does make sense in a different context. 
>
> All I had to do was ask the kids did they think they needed a number or a 
> word for a variable type? If they where reading a variable from the 
> keyboard that they had to use in a sum, they can work out they need a 
> number not a word. If all they wanted to do was echo the variable back - 
> say their name - then they work out it's a word. It takes a few hours, but 
> within 3-4 hours most of the kids have worked it out. After that its just a 
> syntax and typing problem.
>
> You'll find that having the types helps the kids reason about the 
> programs. This is something I personally find very difficult with python 
> and other typeless languages. It's very hard to reason about an old bit of 
> code because you don't know what the valid operations or data range is of a 
> type, which especially if it a named well helps you reason about the logic. 
> So with kids I would say you want to be as explicit as possible. Static 
> typing helps with this.
>
> The way I introduced numbers was subtle, but matches what they typically 
> see in maths at that age. So a number is an int type initially. Only when 
> we need fractions did I introduce float64, and I only talked about those 
> two numeric types (so no int8 or float32). And I talk about numbers not int 
> or float64, unless I have to be specific.
>
> Words are simply strings, that's just a new name they have to learn and 
> associate with a sequence of characters/letters. They get this really 
> quickly.
>
> The other approach I took was that I gave them partially completed Go 
> programs, where the level of completion tails off each session. So I did 
> this for two reasons. Firstly to cover a bit of boiler plate, things like 
> the import statements and the main() function header. I do talk about these 
> and the partial programs also explain these in the comments but I don't 
> expect the kids to type these lines. Secondly I want them to focus on 
> whatever was key to that session.
>
> The programs are heavily commented to both explain what is there already 
> and what and where I want them to fill in the blanks.
>
> And since the programs are incomplete they won't compile and run to begin 
> with. So they kids have to get he correct syntax from the get go. That's 
> just the same as in English, you have to have the correct spelling and 
> grammar, so the kids have a similar concept at that age.
>
> If you do this they'll absorb things like main() and import just because 
> they will be familiar. So they'll spot it if you leave it out after a few 
> weeks. Or be able to complete an import statement (if you tell them the 
> package name) just by coping a previous example.
>
> My last trick was as I kept things to keyboard IO, I had a little wrapper 
> package that hid the complexity of the text scanner class and converting 
> form strings to ints etc that the programs used.
>
> So to give you an idea of what I had them doing, they where printing 
> "Hello " after 

Re: [go-nuts] Go course

2020-03-26 Thread Amnon Baron Cohen
The println and print builtin may be removed from the language in the 
future.

On Thursday, 26 March 2020 19:18:50 UTC, David Riley wrote:
>
> And since I'm a fan of lifelong learning, I have to admit to not having 
> known that println() was a builtin until this post. Thanks! That does 
> un-complicate it somewhat. 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1c6c8ed3-1b2c-4d51-a34d-09d2056fc18c%40googlegroups.com.


Re: [go-nuts] Go course

2020-03-26 Thread Amnon Baron Cohen
Go is not C. C programmers have to master explicit memory management, which 
is a challenge to new and experience programmers alike.
C is a beautiful language. But very low level.

Having spent several years programming in Python, I would say that it is 
much more complicated than Go.
It has a large and growing number of expressive features which add to the 
cognitive load of those attempting
to get up to speed on the language. When you learn Go, you don't need to 
understand dict comprehensions,
decorators, metaclasses, asyncio etc. Compare the breathtaking simplicity 
of launching a Go routine
with the convoluted mess of python threading.

The lack of strong static typing and a separate compilation phase means 
that errors which in Go would 
cause a compilation error result in run-time exceptions, when a particular 
code path gets executed.

Python also has the "feature" that changes in invisible whitespace 
characters change the programme semantics.
I never really understood the rationale for the feature.

The Go 1 compatibility promise is also helpful. This means that course 
materials or online code examples written 
8 years ago will still work today. The python community broke most existing 
code when they moved from Python 2 to Python 3.
(A decade on this transition is still ongoing).

On Wednesday, 25 March 2020 23:04:58 UTC, David Riley wrote:
>
> It’s just my opinion, and I’m willing to be wrong. :-) 
>
> But having TAed a university introductory computer science course that was 
> first in C and then in Python (and having had several students who failed 
> when it was in C retake in Python and pass with flying colors), I will say 
> that a lot of the elements that tripped beginners up in C which were absent 
> in Python are present in Go. 
>
> Most of those (e.g. separate compilation, static typing, a few other bits 
> of arcana) are features that make Go a much more effective systems language 
> than Python, but I do feel like it’s probably best to “take the bumpers 
> off” AFTER the student knows about loops, variables, functions, etc. 
>
> Again, it’s only my point of view, and I do have some biases, but they do 
> have some basis. 
>
>
> - Dave 
>
> > On Mar 25, 2020, at 17:08, Dan Kortschak  > wrote: 
> > 
> > I don't agree that Go is intrinsically harder than python as a beginner 
> > programming language. There are things that are subtle, but these can 
> > largely be avoided in the beginner setting. 
> > 
> > Note that there have been discussions here about using Go as a language 
> > for teaching beginners, notably this one 
> > https://groups.google.com/d/topic/golang-nuts/FIRSDBehb3g/discussion 
> > 
> > Dan 
> > 
> >> On Wed, 2020-03-25 at 13:34 -0400, David Riley wrote: 
> >> If you are already a programmer in another language, the Tour of Go 
> >> (tour.golang.org) is absolutely the best. 
> >> 
> >> If you are not already a programmer in another language, I personally 
> >> don't recommend Go as a first language; it's an excellent language, 
> >> but I feel that people will do better with it once they already grasp 
> >> the fundamentals of programming and are ready for something with 
> >> slightly more arcana.  Python makes a pretty good first language. 
> >> 
> >> 
> >> - Dave 
> >> 
> >> 
> >>> On Mar 25, 2020, at 6:07 AM, Renato Marcandier < 
> >>> renato.m...@gmail.com > wrote: 
> >>> 
> >>> Hello guys, 
> >>> 
> >>> What's the best course to start with Go? 
> >>> 
> >>> 
> >>> 
> >>> Regards 
> >>> RG 
> >>> 
> >>> -- 
> >>> 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 golan...@googlegroups.com . 
> >>> To view this discussion on the web visit 
> >>> 
> https://groups.google.com/d/msgid/golang-nuts/b2aa0e9a-921f-49de-a0be-729a6ca35f5f%40googlegroups.com
>  
> >>> . 
> >> 
> >> -- 
> >> 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 golan...@googlegroups.com . 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/golang-nuts/18B2AF64-4888-4730-B282-FCB4C00AB697%40gmail.com
>  
> >> . 
> > 
> > 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b43ecb5a-c043-44d4-92d6-f8c046dda7ff%40googlegroups.com.


[go-nuts] Re: json to golang struct definition lib

2020-03-26 Thread Amnon Baron Cohen
An interesting approach.

Slightly surprised you did not use "encodeing/json" to parse the json input,
which would have been much easier.

On Thursday, 26 March 2020 00:05:01 UTC, sanye wrote:
>
> Hello gophers, 
>
> I found an interesting project: https://github.com/mholt/json-to-go , 
> which translate given json data into golang struct definition, it's very 
> useful when dealing with complex json 
>
> It's written in javascript, but maybe a golang version is useful when 
> doing some works like code generation, so I ported it to golang: 
> https://github.com/kumakichi/json-to-go 
>
> Any feedback are appreciated. 
>
> sanye 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d8b41228-2b54-41f6-bfc5-9adef9e46722%40googlegroups.com.


[go-nuts] Re: I'm writing my website in golang but there is issue called 404 page not found

2020-03-09 Thread Amnon Baron Cohen
Also worth adding some unit tests, including one which reproduces your 404 
error.

See https://www.youtube.com/watch?v=hVFEV-ieeew for a great video about how 
to 
add these tests.

On Monday, 9 March 2020 14:53:20 UTC, anderso...@blacklane.com wrote:
>
> please post the code as text. Either in a github/whatever repo or here, 
> but please, as text and a runnable code.
>
> I don't see you registering any handler for */register.html*, you have 
> one for */register* only. Also if the method is not POST, you should 
> return *405 Method Not Allowed *instead of 
>
> *404 Not Found.*
> As tip, use the http constants such as http.MethodPost. See them here: 
> https://golang.org/pkg/net/http/#pkg-constants
>
> Best,
> Anderson
>
> On Sunday, 8 March 2020 16:19:20 UTC+1, Ali Hassan wrote:
>>
>> [image: goSnippet.JPG][image: firefox.JPG]
>>
>> [image: xhrSnippet.JPG]
>> [image: htmlSnippnet.JPG]Browser Error 404   please help me resolve this 
>> error. I think this is because of html page but when try this 
>> /register.html then whole page display on my console. I will exchange my 
>> data 
>>
>>
>> [image: buttonSnippnet.JPG]
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/983f155b-947a-4b65-8475-613c856af096%40googlegroups.com.


[go-nuts] Re: Changing source code in order code to be supported from older Golang versions e.g. Go 1.10

2020-03-08 Thread Amnon Baron Cohen
Microsoft stopped supporting XP in 2006. This meant XP machines stopped 
getting security updates.
The following year the WannaCry trojan infected 200,000 XP computers 
globally, including 80,000 in Britain's
National Health Service (including some MRI machines). This caused a major 
crisis in hospitals, the cancellation
of all non-urgent procedures and the reversion to manual methods of 
administration. This attack cost the NHS
over £80 million. Nobody has ever estimated the impact on patient outcome.

There are many ways could try to "help" Dimitrios find ways to run modern 
Go code on XP, and help him 
extend the lifetime of his fleet of XP machines. But this would keep his 
organisation vulnerable to the next
WannaCry attack. So I would suggest the most useful response is "don't do 
it".

On Friday, 6 March 2020 19:11:44 UTC, Jake Montgomery wrote:
>
> On Friday, March 6, 2020 at 1:20:38 PM UTC-5, Amnon Baron Cohen wrote:
>>
>> Anyone who is able to put up with a 20 year old OS
>> will be able to tolerate a 2 year old Go version...
>>
>
> Dimitrios' question is a perfectly legitimate one. Your response does 
> nothing to actually answer the question. It also comes across as a bit 
> snarky. Just a friendly reminder that the Go community strives to be 
> "friendly and welcoming" to all. https://golang.org/conduct is a 
> worthwhile read. 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f8b17c6b-55b4-4782-8b48-77855eea3e1f%40googlegroups.com.


Re: [go-nuts] Changing source code in order code to be supported from older Golang versions e.g. Go 1.10

2020-03-07 Thread Amnon Baron Cohen
also

https://stackoverflow.com/questions/52137098/go-after-1-10-and-support-of-windows-xp/52137703#52137703

On Saturday, 7 March 2020 13:38:17 UTC, Amnon Baron Cohen wrote:
>
> https://github.com/golang/go/issues/23380
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9d3bfea4-781f-4771-b68f-72b14c30910a%40googlegroups.com.


Re: [go-nuts] Changing source code in order code to be supported from older Golang versions e.g. Go 1.10

2020-03-07 Thread Amnon Baron Cohen
https://github.com/golang/go/issues/23380

On Saturday, 7 March 2020 11:42:28 UTC, Jesper Louis Andersen wrote:
>
> While it isn't supported, it might be there are not that much work needed 
> to make 1.14 run on Windows XP. At least you should consider that path as 
> well in addition to program rewriting. It may be a simpler path.
>
> On Thu, Mar 5, 2020 at 12:08 PM Dimitrios Trechas  > wrote:
>
>> Dear colleagues,
>>
>> There are even now cases that a Windows XP is needed. The latest Golang 
>> compiler that could target XP was 1.10.
>>
>> Is there anyone who had to write a source converter that could convert 
>> recent Golang code to backwards compatible code (in case there is no 
>> version clash/hell of different libs) ? E.g. number literals, source 
>> modules to Golang 1.10?
>>
>>
>> Thank you in advance.  
>>
>> -- 
>> 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/9c246db8-5197-4e1d-a32e-2bca11e99e20%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> J.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cf40d41b-fa71-41ba-8c7f-ed6b411d553c%40googlegroups.com.


Re: [go-nuts] Connection Refused while scraping the data

2020-03-07 Thread Amnon Baron Cohen
You might get better results if you at a www to the beginning of the 
hostname.

curl https://www.indeed.co.in/browsejobs/Engineering

does download a page

whereas curl https://indeed.co.in/browsejobs/Engineering
does give a connection refused error.

On Saturday, 7 March 2020 04:36:04 UTC, Kurtis Rader wrote:
>
> On Fri, Mar 6, 2020 at 8:21 PM Kuldeep Avsar  > wrote:
>
>> I am trying to Scrape the Job Titles one by one from the Indeed.co.in 
>> 
>>  website
>>
>> but it through me connection refused problem while I am visiting to the 
>> particular jobs Title
>>
>> categories page and trying to take response back from the page but It's 
>> shows error on that time. 
>>
>> please help me out to solve this problem i am tried to solve this but this 
>> not solved. Please help.
>>
>> 2020/03/07 09:08:41 Error to Connect with Indeed Jobs Category Page.Get 
>> https://indeed.co.in/browsejobs/Engineering: dial tcp 169.44.165.69:443: 
>> connect: connection refuse
>>
>>
> The web site you are accessing thinks you are executing a DDOS attack or 
> are otherwise violating their terms of service. This has nothing to do with 
> the Go language. You need to rate limit your requests of that site.
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/bf5ebe6c-7a92-4d34-8530-ebdead009b78%40googlegroups.com.


[go-nuts] Re: Changing source code in order code to be supported from older Golang versions e.g. Go 1.10

2020-03-06 Thread Amnon Baron Cohen
Anyone who is able to put up with a 20 year old OS
will be able to tolerate a 2 year old Go version...

On Thursday, 5 March 2020 11:08:07 UTC, Dimitrios Trechas wrote:
>
> Dear colleagues,
>
> There are even now cases that a Windows XP is needed. The latest Golang 
> compiler that could target XP was 1.10.
>
> Is there anyone who had to write a source converter that could convert 
> recent Golang code to backwards compatible code (in case there is no 
> version clash/hell of different libs) ? E.g. number literals, source 
> modules to Golang 1.10?
>
>
> Thank you in advance.  
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5a2710ac-1782-4e24-8c6c-0a1b31e1671b%40googlegroups.com.


[go-nuts] Re: Many instances question - shared library

2020-02-28 Thread Amnon Baron Cohen
That does not sound like a scalable architecture!

The number of simultaneous user connections the architecture can support is 
limited to the number of processes 
your server can run. The resources required by a process are orders of 
magnitude more than those required for a goroutine.
And the Go runtime adds to that.

Three options:
1) rewrite third party app in Go to run in a single process with a 
goroutine per connection
2) don't use Go for your extension
3) Write a stub extension in C which talks over gRPC to a single Go server 
instance


On Friday, 28 February 2020 15:39:21 UTC, Luke Mauldin wrote:
>
> The multiple instances are required to due to way the 3rd party 
> application works. In brief, it creates a new process for each user 
> connection and then each new process dynamically load the Go shared library 
> to provide C extension points.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4e77316c-5d5f-44d4-968a-ae311ee685d8%40googlegroups.com.


[go-nuts] Re: Many instances question - shared library

2020-02-28 Thread Amnon Baron Cohen
> However, due to the nature of the application, there maybe 100 or 200 
instances

Interesting...
Could you elaborate the nature of the application, and why a single 
instance is not enough... 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f4a19892-ba46-4816-8ae0-9615768ad5b6%40googlegroups.com.


[go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-28 Thread Amnon Baron Cohen
somebody beat us to it:
https://github.com/torden/go-strutil#reversestr

But for some strange reason, they seem to have made the this a method of a 
StringProc class.
Perhaps they used to code in Java.

On Friday, 28 February 2020 13:07:54 UTC, Himanshu Makkar wrote:
>
> Hi
>
> I think we can create a package to reverse a string and can use it 
> whenever needed.
>
>  reverse.go
>
>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/98e8bd00-7722-4513-918b-3b547d395881%40googlegroups.com.


Re: [go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-28 Thread Amnon Baron Cohen
That's cool!

Of course we could reverse rune-slice in place, leaving a 7 liner...

func Reverse(s string) string {
   r := []rune(s)
   for i, j := 0, len(r) - 1; i < j; i, j = i +1 , j-1 {
  r[i], r[j] = r[j], r[i]
   }
   return string(r)
}




On Friday, 28 February 2020 08:45:33 UTC, rog wrote:
>
>
>
> On Fri, 28 Feb 2020 at 08:23, Amnon Baron Cohen  > wrote:
>
>> Here is a dumb version, that wastes loads of memory.
>>
>> func reverse(in string) string {
>>out := strings.Builder{}
>>out.Grow(len(in))
>>runes:= make([]rune, 0, len(in))
>>
>>
>>for _, r := range in {
>>   runes = append(runes, r)
>>}
>>
>> You might be interested to know that this operation is built in to Go 
> itself, which means you can do something like this:
>
> func Reverse(s string) string {
> runes := []rune(s)
> rev := make([]rune, 0, len(runes))
> for i := len(runes) - 1; i >= 0; i-- {
> rev = append(rev, runes[i])
> }
> return string(rev)
> }
>
> It's not even *that* much slower (about 60%). It doesn't always preserve 
> the original string length though.
>
>
>
> On Saturday, 15 February 2020 16:37:15 UTC, Amarjeet Anand wrote:
>>
>> Hi
>>
>> I was wondering why isn't there built-in string reverse function. Is it 
>> left intentionally because of some reason?
>>
>> Although strings are immutable in go, there are multiple ways to achieve 
>> this pretty easily. But having this function inbuilt will save our time 
>> because we need it quite often.
>>
>>
>> -- 
> 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 golan...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/cae39c11-f492-4890-b0ff-332d2e51042b%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/cae39c11-f492-4890-b0ff-332d2e51042b%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e6239d6d-6dba-4735-902f-2eaf10ffcc38%40googlegroups.com.


[go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-28 Thread Amnon Baron Cohen


Here is a dumb version, that wastes loads of memory.

func reverse(in string) string {
   out := strings.Builder{}
   out.Grow(len(in))
   runes:= make([]rune, 0, len(in))


   for _, r := range in {
  runes = append(runes, r)
   }
   for i := len(runes) -1; i >= 0; i-- {
  out.WriteRune(runes[i])
   }
   return out.String()
}




On Saturday, 15 February 2020 16:37:15 UTC, Amarjeet Anand wrote:
>
> Hi
>
> I was wondering why isn't there built-in string reverse function. Is it 
> left intentionally because of some reason?
>
> Although strings are immutable in go, there are multiple ways to achieve 
> this pretty easily. But having this function inbuilt will save our time 
> because we need it quite often.
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cae39c11-f492-4890-b0ff-332d2e51042b%40googlegroups.com.


Re: [go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-27 Thread Amnon Baron Cohen
lol!

Where are you rob?
We miss you!

On Thursday, 27 February 2020 23:23:57 UTC, Rob 'Commander' Pike wrote:
>
> Once bytten, twice shy.
>
> -rob
>
>
> On Fri, Feb 28, 2020 at 10:17 AM Jesper Louis Andersen <
> jesper.lo...@gmail.com > wrote:
>
>> The key observation is that you only look at a byte once.
>>
>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d0ae98a8-357d-4c53-bb6c-7381d4a0e2a8%40googlegroups.com.


Re: [go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-27 Thread Amnon Baron Cohen
You are right.
I had wrongly assumed that utf8.DecodeLastRuneInString has O(n) runtime.
But it has constant runtime as it reads at most 4 bytes at the end of the 
string.


On Thursday, 27 February 2020 21:47:19 UTC, kortschak wrote:
>
> Why? There's a single correctly sized allocation made up front and then 
> a linear time walk along the encoded runes with truncation after each 
> rune. 
>
> On Thu, 2020-02-27 at 13:05 -0800, Amnon Baron Cohen wrote: 
> > O(n^2) 
> > 
> > On Thursday, 27 February 2020 18:53:01 UTC, rog wrote: 
> > > If you really just want to reverse rune-by-rune, it's pretty 
> > > straightforward: 
> > > 
> > > func Reverse(s string) string { 
> > > r := make([]byte, 0, len(s)) 
> > > for len(s) > 0 { 
> > > _, n := utf8.DecodeLastRuneInString(s) 
> > > i := len(s) - n 
> > > r = append(r, s[i:]...) 
> > > s = s[:i] 
> > > } 
> > > return string(r) 
> > > } 
> > > 
> > > That will also deal correctly with invalid utf8 encoding - all the 
> > > bytes of the original string will be present in the result. 
> > > > 
> > 
> > -- 
> > 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 golan...@googlegroups.com . 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/golang-nuts/2333bc33-8740-4f8b-972e-37d2d60b9dc7%40googlegroups.com
>  
> > . 
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/18eb08a5-f2be-452b-a31f-9643932fc4bd%40googlegroups.com.


Re: [go-nuts] Re: Why isn't there strings.reverse("str") function?

2020-02-27 Thread Amnon Baron Cohen
O(n^2)

On Thursday, 27 February 2020 18:53:01 UTC, rog wrote:
>
> If you really just want to reverse rune-by-rune, it's pretty 
> straightforward:
>
> func Reverse(s string) string {
> r := make([]byte, 0, len(s))
> for len(s) > 0 {
> _, n := utf8.DecodeLastRuneInString(s)
> i := len(s) - n
> r = append(r, s[i:]...)
> s = s[:i]
> }
> return string(r)
> }
>
> That will also deal correctly with invalid utf8 encoding - all the bytes 
> of the original string will be present in the result.
>
>>
>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2333bc33-8740-4f8b-972e-37d2d60b9dc7%40googlegroups.com.


Re: [go-nuts] Re: Lot's of test errors in package zmq4 with Go version 1.14, no errors with earlier versions

2020-02-26 Thread Amnon Baron Cohen
from https://www.jwz.org/doc/worse-is-better.html

Two famous people, one from MIT and another from Berkeley (but working on 
Unix) once met to discuss operating system issues. The person from MIT was 
knowledgeable about ITS (the MIT AI Lab operating system) and had been 
reading the Unix sources. He was interested in how Unix solved the PC 
loser-ing problem. 

The PC loser-ing problem occurs when a user program invokes a system 
routine to perform a lengthy operation that might have significant state, 
such as IO buffers. If an interrupt occurs during the operation, the state 
of the user program must be saved. Because the invocation of the system 
routine is usually a single instruction, the PC of the user program does 
not adequately capture the state of the process. The system routine must 
either back out or press forward. The right thing is to back out and 
restore the user program PC to the instruction that invoked the system 
routine so that resumption of the user program after the interrupt, for 
example, re-enters the system routine. It is called ``PC loser-ing'' 
because the PC is being coerced into ``loser mode,'' where ``loser'' is the 
affectionate name for ``user'' at MIT.


The MIT guy did not see any code that handled this case and asked the New 
Jersey guy how the problem was handled. The New Jersey guy said that the 
Unix folks were aware of the problem, but the solution was for the system 
routine to always finish, but sometimes an error code would be returned 
that signaled that the system routine had failed to complete its action. A 
correct user program, then, had to check the error code to determine 
whether to simply try the system routine again. The MIT guy did not like 
this solution because it was not the right thing.


The New Jersey guy said that the Unix solution was right because the design 
philosophy of Unix was simplicity and that the right thing was too complex. 
Besides, programmers could easily insert this extra test and loop. The MIT 
guy pointed out that the implementation was simple but the interface to the 
functionality was complex. The New Jersey guy said that the right tradeoff 
has been selected in Unix-namely, implementation simplicity was more 
important than interface simplicity.


On Wednesday, 26 February 2020 17:10:48 UTC, Manlio Perillo wrote:
>
> On Wednesday, February 26, 2020 at 4:14:38 PM UTC+1, Ian Lance Taylor 
> wrote:
>>
>> On Wed, Feb 26, 2020 at 7:11 AM Manlio Perillo  
>> wrote: 
>> > 
>> > On Wednesday, February 26, 2020 at 3:51:54 PM UTC+1, Peter Kleiweg 
>> wrote: 
>> >> 
>> >> Op woensdag 26 februari 2020 13:05:40 UTC+1 schreef Manlio Perillo: 
>> >>> 
>> >>> On Wednesday, February 26, 2020 at 12:33:05 PM UTC+1, Peter Kleiweg 
>> wrote: 
>>  
>>  With Go version 1.14 I get a lot of errors when I run: 
>>  
>>  go test -v github.com/pebbe/zmq4 
>>  
>>  I didn't see this with Go 1.13.8 or any earlier version. 
>>  
>>  Is this a problem with Go 1.14, or am I doing something wrong and 
>> just got lucky until now? 
>>  
>>  How do I debug this? The errors are different for each run. Below is 
>> a sample of some errors. 
>>  Line numbers are not always accurate, because I inserted some calls 
>> to test.Log(). 
>> >>> 
>> >>> 
>> >>> The errors are probably caused by 
>> https://golang.org/doc/go1.14#runtime. 
>> >>> 
>> >>> The solution is to update zmq4  to explicitly handle interrupted 
>> system calls. 
>> >> 
>> >> 
>> >> Often the program freezes before I get an interrupted system call. It 
>> hangs inside a ZeroMQ C++ library function. 
>> >> zmq4 is just a wrapper for ZeroMQ. I can't "fix" ZeroMQ to make it 
>> work with Go. 
>> >> 
>> >> Is there a way to stop Go from interrupting my system calls? It 
>> happens rather randomly all over the place. 
>> > 
>> > 
>> > 
>> https://stackoverflow.com/questions/36040547/zeromq-how-to-react-on-different-signal-types-on-eintr
>>  
>> > 
>> > ZeroMQ may return an EINTR error , but zmq4 does not list it in 
>> errors.go. 
>> > ZeroMQ asks the caller to handle EINTR, so zmq4 should handle it 
>> internally or return it to the caller. 
>> > 
>> > https://golang.org/doc/go1.14#runtime should have mentioned that not 
>> only programs that use packages like syscall or golang.org/x/sys/unix 
>> will see more slow system calls fail with EINTR errors, but also programs 
>> that use Cgo. 
>>
>> I don't know ZeroMQ.  If the ZeroMQ calls correspond closely to system 
>> calls, then it could work for them to return EINTR.  In that case the 
>> fix is going to be for the Go wrapper around ZeroMQ to check whether 
>> the error returned is syscall.EINTR, and to retry the call if it is. 
>>
>>
> Unfortunately it is not that simple:
>
> http://250bpm.com/blog:12
> https://alobbs.com/post/54503240599/close-and-eintr
> http://man7.org/linux/man-pages/man7/signal.7.html
> https://github.com/golang/go/issues/11180
> https://www.python.org/dev/peps/pep-0475/
>
> 

Re: [go-nuts] setting up a hardened https server in go 1.13

2020-02-21 Thread Amnon Baron Cohen


On Friday, 21 February 2020 17:49:06 UTC, Kevin Chadwick wrote:
>
> On 2020-02-21 16:13, Amnon Baron Cohen wrote: 
> > 
> Default connection limits suggest it isn't production ready by default and 
> so is 
> the main reason...so define properly hardened, but also. 


hardened means following the recommendations of Filippo's blog post 
(which in practice adds about 30 lines to your code).

But without a list of vulnerabilities, this sounds to me like FUD.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c77967d6-d87f-433b-af7a-4b4e5775415c%40googlegroups.com.


Re: [go-nuts] setting up a hardened https server in go 1.13

2020-02-21 Thread Amnon Baron Cohen
Interesting.

What vulnerabilities does OpenBSDs httpd protect against, which a properly 
hardened net/http does not?

The problem with proxying through OpenBSD's server, nginx or any other 
server is that there is another 
moving part that you need to master, configure, monitor, and which may have 
its own vulnerabilities.

Filippo, who wrote the blog, is now on the core go team, and working on Go 
Crypto and getting
hardened behaviour by default. See https://blog.filippo.io/hi/ and 
https://go.googlesource.com/proposal/+/master/design/cryptography-principles.md
This would be welcome, as hardening net/http requires a couple of dozen 
lines of boilerplate code.

As you say, his blog post is four years old, and four years is a long time 
in crypto land,
it would be great if we got some updated recommendation from Filippo.
The default behavior has been improved. SSLv3 for instance will be removed 
when 
Go 1.14 comes out (in a few days time). Perhaps we could coax Filippo to 
write 
a Go blog with his updated best practices?



On Friday, 21 February 2020 11:15:53 UTC, Kevin Chadwick wrote:
>
> On 2020-02-21 01:42, DrGo wrote: 
> > Are there more up-to-date recommendations for go 1.13? 
>
> Personally I run Go behind either app engine or via fcgi behind OpenBSD 
> httpd. 
> I'm not sure any other https server has the same level of key protection 
> as 
> revamped in OpenBSDs httpd (separate to LibreSSL), since heartbleed 
> (despite not 
> being as vulnerable as most). 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/05e2f98e-e443-4fe6-b2b4-1f47a7eae730%40googlegroups.com.


[go-nuts] Re: array json streaming inside json object

2020-02-20 Thread Amnon Baron Cohen
https://github.com/golang/go/issues/33714 is related.

The problem you describe is far greater when decoding.

On Friday, 21 February 2020 05:06:58 UTC, Jérôme LAFORGE wrote:
>
> Thank you both.
>
> When I am the designer of API that must stream json array, I use JSONL. 
> And it is much easier to use it as sender.
>
> Unfortunately, in this case, I can't modify the API.
>
> I read somewhere (I can't remember where), that somebody plans to work on 
> simplicity for streaming json object with Go
> Does someone know if it is actually the case or if it still plans?
>
> Le jeudi 20 février 2020 21:06:21 UTC+1, Brian Candler a écrit :
>>
>> There is even a "standard" for this: http://jsonlines.org/
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4c7b448f-cce1-4fc5-86ec-52473fe99e67%40googlegroups.com.


[go-nuts] Re: array json streaming inside json object

2020-02-20 Thread Amnon Baron Cohen
Unfortunately there is not a more elegant way.

Unless you change the protocol, and dispense with the idea of returning a 
single json object,
and instead return line delimited streaming json.
Then you can dispense with injecting brackets into your stream,
and just call 

  enc.Encode(doc)
  w.Write([]byte('\n'))

for each doc

On Wednesday, 19 February 2020 13:15:36 UTC, Jérôme LAFORGE wrote:
>
> Hello,
> Do you know an elegant, simple and clean way to stream an json array 
> inside json object?
>
> Here an example, that does the job, but I find it complicated (and how we 
> manage the comma when document has error and we have to ignore it)
>
> https://play.golang.org/p/lZa8iVaQAKg
>
> thx in adv
> BR
> Jérôme
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1ab33d01-9885-4874-b260-0efab4f13738%40googlegroups.com.


Re: [go-nuts] Re: [Proposal] Change how gofmt formats struct fields

2020-02-20 Thread Amnon Baron Cohen

>
> Gofmt's style is no one's favorite, yet gofmt is everyone's favorite. 
> 


>From Go Proverbs.

https://www.youtube.com/watch?v=PAAkCSZUG1c=8m43s

Rob Pike answered this proposal in advance back in 2015.

Wise words...
 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e7a8e427-9611-4a58-8a96-de6c8a1d0de1%40googlegroups.com.


[go-nuts] Re: Why Discord is switching from Go to Rust

2020-02-07 Thread Amnon Baron Cohen
https://twitter.com/_rsc/status/1224802726774812672?s=20 
https://twitter.com/_rsc/status/1224802727773065221?s=20

On Friday, 7 February 2020 12:24:50 UTC, Everton Marques wrote:
>
> I think Go is way better than Rust, but it is amusing to see why people 
> pick one over another.
>
> "Remarkably, we had only put very basic thought into optimization as the 
> Rust version was written. Even with just basic optimization, Rust was able 
> to outperform the hyper hand-tuned Go version. This is a huge testament to 
> how easy it is to write efficient programs with Rust compared to the deep 
> dive we had to do with Go."
>
>
> https://blog.discordapp.com/why-discord-is-switching-from-go-to-rust-a190bbca2b1f
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f4481ae5-5e26-48ca-be1c-1cd1f929917f%40googlegroups.com.


[go-nuts] Re: Any chance of not deprecating GOPATH ?

2020-02-02 Thread Amnon Baron Cohen
Kill GOPATH!

It was a terrible idea. Thankfully no longer needed.
But it causes no end of confusion.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d1dcabc1-78b1-431f-a088-79bf4e6a3dc5%40googlegroups.com.


[go-nuts] Re: [Proposal] Change how gofmt formats struct fields

2020-02-01 Thread Amnon Baron Cohen
The indent man page  (for formatting C 
code) has dozens of options to allow the user to tweak the output format.

The greatest thing about gofmt great thing about gofmt is that it has no 
such options. No style options. No new vs old mode.
Gofmt just produces a single canonical format.

Let's keep it that way.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fbaf8e58-b478-497b-b8b1-2d3265f70523%40googlegroups.com.


[go-nuts] Re: [Proposal] Change how gofmt formats struct fields

2020-01-29 Thread Amnon Baron Cohen


On Wednesday, 29 January 2020 17:56:35 UTC, Manlio Perillo wrote:
>
> Is this reasonable?
>
>
Not really, as it would generate many gratuitous changes to existing code.
This is one thing gofmt avoids. 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/69318dbd-0549-435e-b2d4-cacef9469e46%40googlegroups.com.


Re: [go-nuts] Re: Go mindshare is low & ~flat, per Google Trends

2020-01-26 Thread Amnon Baron Cohen
Maybe Go is too stable and boring.

Perhaps we should add wacky new features in each release, remove old 
features,
and change the way everything else works in surprising and undocumented 
ways.
This way all our users will be forced to google like crazy to figure out 
how to port 
their code to the latest release. That should drive up our search count on 
Google trends.
Until our users give up and abandon the language.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8248c542-4315-42c5-b48a-ef9bd09abb9a%40googlegroups.com.


Re: [go-nuts] Re: Go mindshare is low & ~flat, per Google Trends

2020-01-16 Thread Amnon Baron Cohen
https://www.benfrederickson.com/ranking-programming-languages-by-github-users/

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/58fb16ef-90eb-45f4-8232-013262d23848%40googlegroups.com.


Re: [go-nuts] Re: Go mindshare is low & ~flat, per Google Trends

2020-01-16 Thread Amnon Baron Cohen
Go was originally conceived as a niche language. And if it does what we 
need, then I don't think 
we need to be particularly bothered if other languages are more "popular".

But when looking at language popularity, I am not sure that the number of 
google searches is the most meaningful metric.

Lines of code on github could be more interesting.

FWIW: Githubs octoverse shows shows a 147% growth in Go usage last year.

And more interesting growth stats can be found on the Go blog 
https://blog.golang.org/8years

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/28b8066f-876b-41f6-b249-94dc4f255347%40googlegroups.com.


[go-nuts] Re: How to make a server being server and client simultaneously

2020-01-15 Thread Amnon Baron Cohen
Is this homework?
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9a6e6ea3-1040-42e6-be2f-8d901ad04bb5%40googlegroups.com.


[go-nuts] Re: About the change for default "-mod=vendor" in Go 1.14

2020-01-09 Thread Amnon Baron Cohen


On Thursday, 9 January 2020 08:38:56 UTC, T L wrote:
>
> Yes, when I change the "go 1.13" directive to "go 1.14", it suggests I 
> need to run 'go mod vendor' to sync.
> After the sync, it works. Thanks for the help.
>
> So if the directive is 1.13, no default "-mod=vendor" compiler flag is 
> set? And not any message is suggested?
>
> On Wednesday, January 8, 2020 at 11:51:59 AM UTC-5, Sean Liao wrote:
>>
>> works for me when tested with gp1.14beta1, are you sure your go.mod has 
>> the  "go 1.14" directive?
>> go's tooling currently assumes vendor is a full local copy of all code 
>> needed to build a module
>> with modules the recommended way is to have your patched  / unavailable 
>> module somewhere else
>> and point to it with either standard require or a replace
>>
>
> This should work, but it is to tedious, for there are tons of old 
> dependency packages.
> I need to create tons of go.mod files under those package folders and add 
> tons of replace lines in the main go.mod file.
>
> If Go SDK 1.14+ also support a special folder vendor_legacy, then things 
> would become simpler.
>

Things would be much, much, simpler if we kill off the vendor folder.

It always was a horrible hack.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4e3cc8b9-1bae-4af2-bff8-01de048b005d%40googlegroups.com.


Re: [go-nuts] Re: A question !

2020-01-07 Thread Amnon Baron Cohen


On Tuesday, 7 January 2020 09:44:28 UTC, Motaz Hejaze wrote:
>
>
> May i ask what is the best deployment for more performance ?? 
>
>>
>>
Do whatever is easiest. If you have come from the Python/Django world 
then you will be blown away by Go's speed, whatever deployment you use.
I would also use the standard library's built in web-server rather than 
proxying 
behind nginx. 

A big benefit of Go's improved speed is that you can stop worrying about 
performance.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a4063992-911d-4f3c-a518-5088762ba0fb%40googlegroups.com.


Re: [go-nuts] Publishing and using go module from tarball?

2020-01-06 Thread Amnon Baron Cohen
> Go modules tooling does not seem to support http at
> all and as for the https I did not find any way to allow use of 
self-signed
> certificate...

In Go 1.14 (available as in beta) you can set the GOINSECURE env var to 
allow http download.
https://tip.golang.org/cmd/go/#hdr-Environment_variables


>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/457d73e2-a353-47fe-850f-2d8a88b819b6%40googlegroups.com.


Re: [go-nuts] Publishing and using go module from tarball?

2020-01-06 Thread Amnon Baron Cohen
In Go 1.14 (available as in beta) you can set the GOINSECURE env var to 
allow http download.
https://tip.golang.org/cmd/go/#hdr-Environment_variables

On Sunday, 5 January 2020 17:34:50 UTC, volf...@gmail.com wrote:
>
>
>
> On Sunday, January 5, 2020 at 11:02:52 AM UTC, Amnon Baron Cohen wrote:
> > If you are happy publishing a zip archive rather than a tarball,
> > then you can server the module download protocol directly.
> > See https://research.swtch.com/vgo-module#download_protocol
>
> That definitely looks interesting and I will try to find some time to look 
> into it
> deeper, however testing it locally seems much more difficult then it really
> should have been. Go modules tooling does not seem to support http at
> all and as for the https I did not find any way to allow use of self-signed
> certificate...
>
> But still, it looks like it might be possible so thanks again, I will try 
> to
> twist it to work for my use-case.
>
> Thanks :)
>
> W.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/aedbf622-b1e1-4c7e-8c94-07305734422a%40googlegroups.com.


Re: [go-nuts] Publishing and using go module from tarball?

2020-01-05 Thread Amnon Baron Cohen
If you are happy publishing a zip archive rather than a tarball,
then you can server the module download protocol directly.
See https://research.swtch.com/vgo-module#download_protocol

On Sunday, 5 January 2020 05:11:32 UTC, wgr wrote:
>
> On 2020-01-04 15:54, volf...@gmail.com  wrote: 
> > Greetings, 
> > 
> > I would like to ask if it is possible to publish go module using tarball 
> and 
> > later on somehow use it. All examples I was able are about using go 
> modules 
> > from some git repository. However, what I would like to do is publish 
> > tarball 
>
> Would `go mod vendor` then building with `go build -mod=vendor` or 
> `GOFLAGS=-mod=vendor go build` work for 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a5a8352d-edbc-470d-8c22-eb624ba9a75c%40googlegroups.com.


[go-nuts] Re: A question !

2020-01-05 Thread Amnon Baron Cohen

> 1 - Is there really a big performance ( speed ) difference between using 
Python OR Golang in backend web development ? 
Python suffers from poor performance, so moving to Go should give you a 
speedup of  well over an order of magnitude.
(See https://www.techempower.com/benchmarks/ for example benchmarks).

> 2 - What is the fastest resource to learn Golang ( efficiently ) ?

https://tour.golang.org/welcome/ 

https://gowebexamples.com/

> 3 -  What is the ( best and most secured ) web framework for building a 
high traffic web services with Golang ?

I, personally, would probably start with the standard library. 

> 4 - I know that go comes with builtin web server , is it reliable for 
production ? or shall we connect go with classic web servers aka ( nginx , 
apache ) ?
The built-in web server in net/http is production grade, both in terms of 
performance, security and functionality.

Just one pedantic nit-pick. People call the language "Go" and not "Golang".

Best of luck, and enjoy!




On Saturday, 4 January 2020 18:28:24 UTC, Motaz Hejaze wrote:
>
> Hello Guyz , 
> This is Hejaze from Egypt
> Currently i wok as a python django web developer
> I am new to Golang and i want to ask you guys with experience 
>
> 1 - Is there really a big performance ( speed ) difference between using 
> Python OR Golang in backend web development ? 
> 2 - What is the fastest resource to learn Golang ( efficiently ) ?
> 3 -  What is the ( best and most secured ) web framework for building a 
> high traffic web services with Golang ?
> 4 - I know that go comes with builtin web server , is it reliable for 
> production ? or shall we connect go with classic web servers aka ( nginx , 
> apache ) ?
> 5 - What do you think about future job demands regarding Golang , i mean 
> will take a decent share of job requests ?
>
> Thanks and i hope you all be patient with my questions 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/86afb7f4-1990-4a5c-8e60-9915a6234e7b%40googlegroups.com.


[go-nuts] Re: How to fill a map with requests from client

2020-01-03 Thread Amnon Baron Cohen
I have copied the problematic lines of your code into a tiny programme on 
the Go playground.
https://play.golang.org/p/9vMrdtC-2zX

If you run it you will see the problem.

I would play around with the code to get a feel for what is happening.

If you want to append job names, then you probably want to use a slice 
rather than a map.

And to get the lifetime of this slice right, it should be created outside 
the loop which processes each new request.

Like I said, play around with the small example, until you understand what 
is happening and you can get the code to do the right thing.
Then you can update your original program.

Good luck!

On Friday, 3 January 2020 09:02:26 UTC, MUNGAI wrote:
>
> Hi, as indicated above, all is a local variable to you function. Maybe you 
> meant to have all variable on a global scope and as a map of maps.
>
> Regards
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a9faf0f9-26c8-414c-a4f3-012da8b3a742%40googlegroups.com.


[go-nuts] Re: How to fill a map with requests from client

2020-01-03 Thread Amnon Baron Cohen


all := make(map[string]string) // create the map 
all["client request"] =  clientJob.name// append the client requests on 
map


gets called each time a request arrives.
So a new empty map gets created each time a request arrives.

The comment on the second line is wrong. The code does not "append" to the 
map. It overwrites the "client request" element.


On Friday, 3 January 2020 07:14:22 UTC, nks wrote:
>
> I am a beginner in Golang, This is a TCP server that receives requests and 
> sends back a hello message to the client attached with the client's 
> message(name)
>  *how can I fill those requests into a map without erasing the previous 
> request?*
>  this is the code, the request is appended to the map but when the next 
> comes, it replaces the current on.
>
>
>  // Goroutine and Socket programming TCP server
> //**
> // TCP 
> //--
>
> package main
>
> import (
> "bufio"
> "fmt"
> "net"
> "time"
> )
> // check if there is any error and send a message. but it's better to remove 
> panic later (it's not recommended to use it)
> //***
> func check(err error, message string) { 
> if err != nil {
> panic(err)
> }
> fmt.Printf("%s\n", message)
> }
> // Create the client structure that contains the client's name and the 
> connection
> //
>
> type ClientJob struct { 
> name string
> conn net.Conn
>
> }
>
> // Create the function,the channel with type struct
> //*
>
> func generateResponses(clientJobs chan ClientJob) {
> for {
> // Wait for the next job to come off the queue.
> clientJob := <-clientJobs
>
> // Do something thats keeps the CPU buys for a whole second.
> for start := time.Now(); time.Now().Sub(start) < time.Second; {
> }
>
> // Send back the response.
>
> clientJob.conn.Write([]byte("Hello, " + clientJob.name))
>
> //clientJob:=make(chan ClientJob)
> //name:=make(chan string)
> //name:=<-clientJobs
>
> all := make(map[string]string) // create the map 
> all["client request"] =  clientJob.name// append the client requests 
> on map
> fmt.Println("All requests in the slice", all) // show all the 
> requests in the map
>
>
>
> }
>
> }
>
> // The main function
> //***
>
> func main() {
> clientJobs := make(chan ClientJob) // declare the channel used in the 
> function above
> go generateResponses(clientJobs)  // put the function in a goroutine
>
> ln, err := net.Listen("tcp", ":8080") // connect to the port 8080, it can 
> be changed to any port if needed
> check(err, "Server is ready.") // show the message that the server is 
> ready to receive
> //fmt.Println(<-clientJobs)
> // start checking the connection et receiving from the client and pass it 
> into a goroutine and send it via a channel ClientJobs<-ClientJob{name, conn}
> for {
> conn, err := ln.Accept()
> check(err, "Accepted connection.")
>
> go func() {
> buf := bufio.NewReader(conn)
>
> for {
> name, err := buf.ReadString('\n')
>
> if err != nil {
> fmt.Printf("Client disconnected.\n")
> break
> }
>
> clientJobs <- ClientJob{name, conn} // pass the name and conn 
> to the clientJobs channel
>
> }
>
>
> }()
> }
> }
>
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4b3b875f-9204-41e4-b427-6981de4f4d66%40googlegroups.com.


[go-nuts] Re: Question regarding a very tricky build set up

2019-12-26 Thread Amnon Baron Cohen


On Sunday, 22 December 2019 08:08:56 UTC, christoph...@gmail.com wrote:
>
> Oh my gosh. You could have saved all the time for writing that long long 
> question if someone had told you before that GOPATH is a thing of the past. 
>
> Go has a new package dependency management system called Go Modules, and 
> this removes the need for a central source code workspace. 
>
> See https://github.com/golang/go/wiki/Modules to get started, search 
> https://blog.golang.org for its Go Module posts, or search the Web for 
> "Go Modules".


The problem is that the documentation on golang.org is still littered with 
instructions about the GOPATH way of doing things.
Happily there is a review in flight to fix this 
https://go-review.googlesource.com/c/website/+/199417
which hopefully will land soon. 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f9e86744-6249-45b4-b979-cc3297c387d9%40googlegroups.com.


[go-nuts] Re: Storing test cases in array of struct vs slice of struct

2019-12-24 Thread Amnon Baron Cohen
Array and slice are pretty much equivalent. Slices require (three 
characters) less typing.
And arrays save a couple of bytes at run-time by not allocating a slice 
header.

Maps, on the other hand, will execute the tests in a randomised order.
In a properly written test, this should not  matter. But if test results 
depend 
on the order the tests are run, you really want every run of your tests to 
produce the 
same results. Otherwise you will never know whether your tests passed 
because your code is correct,
or because you just happened to get lucky this time with the execution 
order.

On Monday, 23 December 2019 14:46:42 UTC, Rodolfo Carvalho wrote:
>
> This is a question about organizing table tests.
>
> I believe the most common idiom for writing table tests is to store test 
> cases in a slice of structs like in the example from 
> https://github.com/golang/go/wiki/TableDrivenTests 
> 
> :
>
> var flagtests = []struct {
> in  string
> out string
> }{
> {"%a", "[%a]"},
> // ...
> {"%-1.2abc", "[%-1.2a]bc"},
> }
>
> I've also seen map[string]struct{...} used when one wants to give test 
> cases a name (described in detail in 
> https://dave.cheney.net/2019/05/07/prefer-table-driven-tests).
>
> What got me curious, however, are cases where instead of a slice literal, 
> the author has chosen to use an array literal. Example from the Go source 
> tree:
>
> src/net/http/cookiejar/jar_test.go:var hasDotSuffixTests = [...]struct {
> src/net/http/cookiejar/jar_test.go- s, suffix string
> src/net/http/cookiejar/jar_test.go-}{
> src/net/http/cookiejar/jar_test.go- {"", ""},
> src/net/http/cookiejar/jar_test.go- {"", "."},
> src/net/http/cookiejar/jar_test.go- {"", "x"},
>
>
> To my surprise, the array literal pattern appears more often than maps in 
> tests in the Go tree:
>
> $ git grep -F '[]struct {' -- '*_test.go' | wc -l 
> 742 
> $ git grep -F '[...]struct {' -- '*_test.go' | wc -l  
> 38 
> $ git grep -F 'map[string]struct {' -- '*_test.go' | wc -l  
> 11 
>
>
> Why and when would one put test cases in an array literal? What is the 
> point?
>
>
> Thank you and cheers,
>
> Rodolfo
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/11914431-bcae-4649-8fac-164c70b4c972%40googlegroups.com.


[go-nuts] Re: Getting Gobot package fails

2019-09-22 Thread Amnon Baron Cohen
try go get -u github.com/hybridgroup/gobot

and change the import paths in your program.


On Sunday, 22 September 2019 16:14:48 UTC+1, Arie van Wingerden wrote:
>
> When I issue this command (as instructed on Gobot site):
>  go get -d -u gobot.io/x/gobot/...
>
> I get this message:
>  package gobot.io/x/gobot/...: unrecognized import path "
> gobot.io/x/gobot" (https fetch: Get http://gobot.io/x/gobot/?go-get=1: 
> redirected from secure URL https://gobot.io/x/gobot?go-get=1 to insecure 
> URL http://gobot.io/x/gobot/?go-get=1)
>
> Any ideas how to get around this?
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5469ae1f-342f-4bdf-a3db-8bfca363b486%40googlegroups.com.


Re: [go-nuts] [cgo ] Export go function to C - illegal character

2019-06-26 Thread Amnon Baron Cohen
https://docs.microsoft.com/en-us/cpp/build/reference/decorated-names?view=vs-2019

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/37617315-b60c-4a54-80ed-8c392d238e4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-15 Thread Amnon Baron Cohen
I would add that engineering is the art of tradeoffs.

The language authors decided to route all network scheduling
through netpoll, and launch a new goroutine for every incoming http 
request. These decisions carry a significant overhead. But they mean 
that users of the language can effortlessly write production ready web apps 
which magically
scale to utilise all the cores at our disposal, handle concurrent
and long-running requests with grace, handle orders of magnitudes more 
requests than python or ruby, and which do not require us to become
experts in tuning Apache/Nginx configs.

So the authors have decided to favour making our lives easier over 
trying to get absolutely optimal performance in benchmarks.
Personally I appreciate their choices and enjoy using Go.
Those who have other priorities are more than welcome to write the web apps 
in 
Perl, Rust, C++, assembler etc... 
Go was never meant to be all things to all people.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0aad04a4-136e-4a9d-992e-c2fa89d1dedd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-11 Thread Amnon Baron Cohen
For those interested, you can find some web benchmarks 
here https://www.techempower.com/benchmarks/

For the trivial http ping type server, you would expect latency to be 
dominated by system time.
strace'ing your code will give you an idea what it is doing. Go allows you 
to have multiple goroutines
serving responses. This does carry a certain overhead as any network reads 
will have to go through
netpoll to demux and schedule goroutines when the packets they are waiting 
for arrives.
So we should not be too dismayed if Go code shows higher latencies than a 
single treaded script. 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d091d5a4-afdc-4538-b86c-fe6fa6b99ccf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go Module Mirror and Checksum Database in Beta!

2019-05-31 Thread Amnon Baron Cohen
Not really. 
You need the list feature of GOPROXY, which is only available in 1.13 (or 
tip).


>
> Is there a way to test proxy.golang.org with go1.12 if we have private 
> dependencies ? 
>
> -- 
> William Dodé 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c0240271-d1f3-43d7-a12f-0fc772ded6b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go Module Mirror and Checksum Database in Beta!

2019-05-31 Thread Amnon Baron Cohen
See https://go.googlesource.com/proposal/+/master/design/25530-sumdb.md

The current behavior is not ideal from a security point of view.
So it is good that 1.13 is fixing this.
And unless the fix is default, most users will not get the benefit.

Anyone who wants to old behavior just needs to set two environment vars.

On Friday, 31 May 2019 14:15:28 UTC+1, wilk wrote:
>
> On 30-05-2019, Katie Hockman wrote: 
>
> > The module mirror at proxy.golang.org serves the go command=E2=80=99s 
> proxy 
> > protocol. The Go 1.13 development tree uses this mirror for all module 
> > downloads by default. See the go command documentation at tip 
> > 
> > for details. To make earlier versions of the go command use it (when in 
> > module mode), set GOPROXY=3Dhttps://proxy.golang.org. 
>
> Could you explain why this option will be default and not opt-in ? 
> It can break current workflow, for example with private repos. 
>
> Thanks 
>
> -- 
> William Dodé 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d3c61f54-fff3-46c9-8b8d-275686e2def1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Interesting public commentary on Go...

2019-05-28 Thread Amnon Baron Cohen
If it aint broke, don't fix it.

On Thursday, 23 May 2019 14:18:25 UTC+1, lgo...@gmail.com wrote:
>
> https://utcc.utoronto.ca/~cks/space/blog/programming/GoIsGooglesLanguage
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f8e2cb1d-4067-48b9-bd51-c95c4bf731ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Http Handler to produce static content

2019-05-20 Thread Amnon Baron Cohen
When web-apps are implemented in scripting languages which suffer from poor 
performance,
it is common practice to proxy them behind a "real" web server such as 
nginx, and offload SSL
termination, caching, handling of static components, etc to it.
In Go http.ListenAndServe is an industrial strength web server, capable of 
gracefully handling high request 
rates, large numbers of simultaneous connections, http2 etc. So your Go App 
may as well be the web server.
You are, or course, at liberty to proxy your web app behind nginx etc, like 
the Python and Ruby folk.
But why add extra moving parts, extra configuration and extra complexity to 
your deployment stack?

On Monday, 20 May 2019 18:08:14 UTC+1, Tyler Compton wrote:
>
> Sorry I don't quite understand -- my go application IS my webserver.
>>
>
> This is a topic that has confused me in the past. In the simple case where 
> you build a Go executable and get requests from it directly, your Go 
> application *is* your web server. However, it's common in industry to put a 
> system like nginx in front of your Go executable that takes care of serving 
> static content like images, JavaScript, CSS, and so on to the user without 
> consulting your Go application at all. Then, when this web server gets a 
> request on and endpoint that it doesn't know how to serve, like an API 
> call, it will forward that request to your Go application.
>
> With a setup like this, you're able to concentrate on writing business 
> logic in Go and configure caching and static resource management elsewhere. 
> In these cases, the application in front of your Go application is the "web 
> server" because it is in charge of directly serving resources to the 
> client. Your Go application might be called the "web application" because 
> it is in charge of doing application-specific tasks. It isn't strictly 
> necessary to adopt this format just to cache static resources, but if your 
> needs become more complicated in the future it might be something worth 
> considering :)
>  
>
>> Are you saying Go net/http is not capable of doing what I'm asking?
>>
>> On Sun, May 19, 2019 at 9:59 AM satyendra singh
>> > wrote:
>> >
>> > Hi Tong,
>> > You can use a webserver between browser and your go application which 
>> will take care of header modification for browser caching.
>> >
>> > Thanks and regards,
>> > Satyendra
>> >
>> > On Sun, 19 May, 2019, 7:26 PM Tong Sun, > > wrote:
>> >>
>> >> Hi,
>> >>
>> >> How to have http.Handle / http.HandleFunc to produce static content 
>> that browser will use their caches without downloading every time?
>> >>
>> >> For a simplest http.HandleFunc, like the following,
>> >>
>> >> func sayHello(w http.ResponseWriter, r *http.Request) {
>> >>message := "Hello "
>> >>
>> >>w.Write([]byte(message))
>> >> }
>> >>
>> >>
>> >>
>> >> Thet HTTP Header it produce is:
>> >>
>> >> HTTP/1.1 200 OK
>> >> Date: Sun, 19 May 2019 13:46:32 GMT
>> >> Content-Length: 6
>> >> Content-Type: text/plain; charset=utf-8
>> >>
>> >>
>> >> I.e., the "Date:" part is changing all the time, even if I've added a 
>> "last-modified" Header field.
>> >>
>> >> What's the solution? Thx
>>
>> -- 
>> 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAMmz1OeBW5rp4RcfYtC%3Dk%3DpeX%3DdizF5G9Gv0Y1dgm5%2BG3%3DZBYA%40mail.gmail.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/0ae68bf2-5a5a-42e1-97e7-dbc12c515887%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Any way to prevent gc emitting AVX256 and AVX512 instructions for amd64?

2019-05-14 Thread Amnon Baron Cohen
OK.
Thanks for the explanation and pointers.

On Tuesday, 14 May 2019 15:15:46 UTC+1, Ian Lance Taylor wrote:
>
> On Tue, May 14, 2019 at 7:03 AM Amnon Baron Cohen  > wrote: 
>
> > > go version 
> > go version go1.12.5 linux/amd64 
> > > GODEBUG=cpu.avx=off go build hello.go 
> > > objdump -d hello | grep '%ymm' 
> >   4021bd: c5 fe 6f 16  vmovdqu (%rsi),%ymm2 
> >   4021c1: c5 fe 6f 1f  vmovdqu (%rdi),%ymm3 
> >   4021c5: c5 fe 6f 66 20vmovdqu 0x20(%rsi),%ymm4 
> > 
> > > GODEBUG=cpu.avx=off,cpu.avx2=off go build hello.go 
> > > objdump -d hello | grep '%ymm' |head 
> >   4021bd: c5 fe 6f 16  vmovdqu (%rsi),%ymm2 
> >   4021c1: c5 fe 6f 1f  vmovdqu (%rdi),%ymm3 
> >   4021c5: c5 fe 6f 66 20vmovdqu 0x20(%rsi),%ymm4 
> >   4021ca: c5 fe 6f 6f 20vmovdqu 0x20(%rdi),%ymm5 
>
> Yes: GODEBUG=cpu.avx=off affects runtime execution.  It does not 
> affect the compiler.  You should set it when running the program.  It 
> will override the CPU detection to say that AVX instructions are not 
> available on this processor. 
>
> There is no way to change what the compiler generates. 
>
> Ian 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b7023a42-7984-433d-b917-835b5b20116c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Any way to prevent gc emitting AVX256 and AVX512 instructions for amd64?

2019-05-14 Thread Amnon Baron Cohen
Thanks!

> 
> go version
go version go1.12.5 linux/amd64
> GODEBUG=cpu.avx=off go build hello.go 
> objdump -d hello | grep '%ymm'
  4021bd: c5 fe 6f 16  vmovdqu (%rsi),%ymm2
  4021c1: c5 fe 6f 1f  vmovdqu (%rdi),%ymm3
  4021c5: c5 fe 6f 66 20vmovdqu 0x20(%rsi),%ymm4

> GODEBUG=cpu.avx=off,cpu.avx2=off go build hello.go 
> objdump -d hello | grep '%ymm' |head
  4021bd: c5 fe 6f 16  vmovdqu (%rsi),%ymm2
  4021c1: c5 fe 6f 1f  vmovdqu (%rdi),%ymm3
  4021c5: c5 fe 6f 66 20vmovdqu 0x20(%rsi),%ymm4
  4021ca: c5 fe 6f 6f 20vmovdqu 0x20(%rdi),%ymm5

but the sledgehammer GOARCH=386 does work

> GOARCH=386 go build hello.go 
> objdump -d hello | grep '%ymm' 
> 

I'll keep digging.

- Amnon

On Tuesday, 14 May 2019 14:30:32 UTC+1, Ian Lance Taylor wrote:
>
> On Tue, May 14, 2019 at 2:18 AM Amnon Baron Cohen  > wrote: 
> > 
> > I am trying to avoid running any AVX instructions in order to prevent 
> Intel's dynamic frequency scaling 
> > reducing my CPU base frequency. 
>
> You should be able to avoid AVX instructions at runtime by setting the 
> environment variable GODEBUG=cpu.avx=off.  For the complete list of 
> available GODEBUG=cpu options available on amd64 see the options 
> variable in internal/cpu/cpu_x86.go. 
>
> Ian 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/eff9890f-db33-499e-b6ce-f449fdfa49db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Any way to prevent gc emitting AVX256 and AVX512 instructions for amd64?

2019-05-14 Thread Amnon Baron Cohen
apart from GOARCH=386 ?

On Tuesday, 14 May 2019 10:17:46 UTC+1, Amnon Baron Cohen wrote:
>
> I am trying to avoid running any AVX instructions in order to prevent 
> Intel's dynamic frequency scaling 
> reducing my CPU base frequency.
>
> Thanks,
>Amnon
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b4159be3-c21c-49c6-87dd-bc362dbf2641%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Any way to prevent gc emitting AVX256 and AVX512 instructions for amd64?

2019-05-14 Thread Amnon Baron Cohen
I am trying to avoid running any AVX instructions in order to prevent 
Intel's dynamic frequency scaling 
reducing my CPU base frequency.

Thanks,
   Amnon

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8424b79b-0be9-4ed9-b6fa-9af3ff44103f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Deferring a close that can fail

2019-03-21 Thread Amnon Baron Cohen
The idiomatic Go way is to write

   defer  ifDB.Close()

Simple is better than clever.

+ Readability does matter.


And in situations where you really need to check that the connection was 
successfully closed, and
you have a workable scheme for recovering from this situation, then write a 
named helper function
which encompasses this logic, rather than writing a convoluted anonymous 
function.

And make sure that all the execution paths in this function have unit tests.



On Tuesday, 19 March 2019 23:57:51 UTC, David Collier-Brown wrote:
>
> It's a known bad thing to defer a close for anything buffered, as 
> discussed at https://www.joeshaw.org/dont-defer-close-on-writable-files/
> but some constructs lack a Sync() call.
>
> For example, I have code like
> ifDB, message, err := OpenInflux(server, debug)
> if err != nil {
> // If this fails, fail fast so we notice
> panic(fmt.Errorf("failed to open and ping influxDB, %s %v",
> message, err))
> }
> defer func() {
> err = ifDB.Close()
> if err != nil {
> // This may be a harmless, very bad thing
> panic(fmt.Errorf("failure closing connection to 
> influxDB, %v", err))
> }
> }()
>
>
> which closes an influxDB database, but will panic if the close fails.
>
> Separate logic makes sure I have passed the point at which the data is 
> committed before I commit my reading of input, so eventually the data will 
> be reread and rewritten. Nevertheless, this is exceedingly complex, and the 
> comment sums it up: "a harmless, very bad thing".
>
> Is there an idiomatic way to address this? I ended up reading influxDB 
> code and doing all sorts of deranged safety-critical-system DFAs to 
> reassure myself this will actually work, but every time I do that, my brain 
> hurts!
>
> --dave
>
>
>

-- 
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: Implementing an EventBus in Go

2019-03-11 Thread Amnon Baron Cohen
https://github.com/nats-io/go-nats

On Monday, 11 March 2019 04:41:25 UTC, Kasun Vithanage wrote:
>
> Hi all,
>
> I've experience implementing event buses in Java. 
> In Java, I used a singleton where I can register callbacks to methods and 
> fire event from a publisher(maybe from another thread) and propagate it to 
> subscribers.
>
> In Go what would be the best pattern to implement a pub/sub event bus? 
> Are channels are a better choice than using callbacks in this scenario(*one 
> to many* event propagation)?
> Or callbacks are better for this? 
>
> (I need to propagate events *only* to subscribers of the topic)
>
> Regards,
> Kasun
>

-- 
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: What is the future of go mod vendoring?

2019-02-15 Thread Amnon Baron Cohen
https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away

On Thursday, 14 February 2019 02:26:35 UTC, Paul A. Fortin wrote:
>
> I have heard that the vendir dirctory is here to stay and also that it is 
> going away - can someone from the goteam give us a idea of the future of 
> that feature?
>
> Thanks
>
> p4tin
>
>

-- 
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: Contributors wanted: Quantitative performance improvement study

2019-02-06 Thread Amnon Baron Cohen
https://www.techempower.com/benchmarks/#section=data-r15=ph=json

>
>

-- 
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: Go vs C speed - What am I doing wrong?

2019-02-03 Thread Amnon Baron Cohen
If you like these kind of 
benchmarks 
https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/go-gpp.html
may be what you are looking for. In these results Go is generally half the 
speed of C, but 50 times faster than python.

Go does not attempt to generate the fastest code at all costs. But the 
generated code is usually fast enough,
and you gain much faster development and compilation times. Garbage 
collection, for example, does impose
some runtime overhead. But it frees the programmer from the tedious and 
error-prone task of manually managing 
memory allocations. If you really care about each nanosecond of execution 
time, and are prepared to do a lot of work
to minimise run-time, then C, C++ or Rust may be your best choice. But for 
most of us here, Go does hit the sweetspot.

For those interested, I gave a talk to the Go London meetup last year about 
the limitations of these kind of benchmarks.
https://youtu.be/YDPKUJndhw4


-- 
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: Patch method

2019-01-09 Thread Amnon Baron Cohen
try https://golang.org/pkg/net/http/ 
and https://golang.org/pkg/encoding/json/

On Tuesday, 8 January 2019 14:24:37 UTC, afriyie...@gmail.com wrote:
>
> Hi,
>
> Am new in Go programming and need help to write a PATCH method for my 
> go-server.
> my data field look like these
>
> type NFProfile struct {
> NFType   string `json:"nftype"`
> NFInstanceID string `json:"instanceid"`
> NFStatus string `json:"nfstatus"`
> ID   string `json:"id"`
> }
>
> //Create NFProfile DB
> type NFProfileDB struct {
> nfprofiles map[string]NFProfile
> }
>
> Can anyone tell me what to and if there is any library to do this such 
> that i can use poastman to send PATCH request
> to the server.
>
> Thanks in advance
> Abraham
>

-- 
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] Re: go language sensitive editor?

2018-11-22 Thread Amnon Baron Cohen
https://www.gnu.org/fun/jokes/ed-msg.html

On Thursday, 22 November 2018 13:49:09 UTC, Anirudh Vyas wrote:
>
> Could never get this one - Ed is the standard editor, is there a 
> historical context of this? Did people say this a lot back when there were 
> vim emacs and Ed only as choices of editors? 
> On Nov 22, 2018, 05:28 -0800, Volker Dobler  >, wrote:
>
> As emacs has not been recommended yet: Emacs! 
>
> V.
>
> On Tuesday, 20 November 2018 21:52:11 UTC+1, Pat Farrell wrote: 
>>
>> I know, this is both a FAQ and an unanswerable question. I'm an old 
>> programmer who has used nearly every editor known to man. I am not a fan of 
>> whole-universe IDEs, but can use them. I also speak vi/vim pretty fluently.
>>
>> What editors do folks use for go? I'd like something that can complete 
>> function names, understand imports, and give some assistance.
>>
> --
> 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.


Re: [go-nuts] Re: Large (binary or text) File transfers over rpc

2018-11-04 Thread Amnon Baron Cohen
And don't forget the bit-torrent class of solutions.

On Friday, 2 November 2018 16:56:17 UTC, Tom Mitchell wrote:
>
> Moving files is a solved, non trivial problem 
> Have you looked at tools like scp (ssh), rsync, kermit, ftp, sftp, tftp 
> and network filesystems (nfs and samba)?
> Even git and http.  Error recover, host name lookup, compression, restart, 
> safe abort, transport encryption, authentication, buffering.
>
> https://en.wikipedia.org/wiki/Sorcerer%27s_Apprentice_Syndrome
>
> https://stackoverflow.com/questions/68335/how-to-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh
>
>
>
>
>
> On Thu, Nov 1, 2018 at 11:24 PM Tamás Gulácsi  > wrote:
>
>> 2018. november 2., péntek 6:21:47 UTC+1 időpontban Anirudh Vyas a 
>> következőt írta:
>>>
>>> Hello there - 
>>>
>>> I am looking for example/help for using rpc to do file downloads - I am 
>>> not sure if this is possible, or recommended or if there is a 
>>> better/cleaner way. I like the robust nature of RPCs and have written a few 
>>> good, performant distributed systems in them - was hoping/wondering if I 
>>> could use RPC to do downloads - I currently use combination of io.Copy and 
>>> a TCP server to do this.
>>>
>>
>> What kind of RPC ? RPC is just "Remote Procedure Call".
>> If s `send(data []byte)` won't be enough (size restrictions), you can 
>> copy the io interfaces:
>> CreateFile(name, perms...) (fileHandle)
>> WriteFile(fileHandle, chunk)
>> CloseFile(fileHandle)
>>
>>
>> -- 
>> 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.
>>
>
>
> -- 
>T o mM i t c h e l l
>

-- 
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: non-standard json

2018-11-03 Thread Amnon Baron Cohen
Try something like 
https://play.golang.org/p/eHEjKINz9aW

func extract(r io.Reader) {
   dec := json.NewDecoder(r)
   for {
  var el s
  err := dec.Decode()
  if err == io.EOF {
 break
  }
  log.Println(el)
   }
}


On Thursday, 1 November 2018 16:14:17 UTC, Alex Dvoretskiy wrote:
>
> Is there is a way to read a file line by line and extract JSON data from 
> it? 
>
>
> Example:
>
> file:
> `
> value1: {"field1": "123, "field2": "123"}
> value2: {"field1": "456", "field2": "879"}
> 
> `
>
> I need to extract the struct in a loop:
>
> type s struct {
> field1 string
> field2 string
> }
>
>

-- 
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: Go 1.11 and 1.10.4 are Released

2018-08-28 Thread Amnon Baron Cohen
Any plans to upgrade https://play.golang.org/ to 1.11?

On Friday, 24 August 2018 23:24:25 UTC+1, Andrew Bonventre wrote:
>
> Hello gophers,
>
> We just released Go 1.11 and 1.10.4.
>
> You can read the announcement blog post here:
>   https://blog.golang.org/go1.1 1
>
> You can download binary and source distributions from our download page:
>   https://golang.org/dl/
>
> To compile from source using a Git checkout, update to the release with 
> "git checkout go1.11" or "git checkout go1.10.4" and build as usual.
>
> To find out what has changed in Go 1.11, read the release notes:
>   https://golang.org/doc/go1.1 1
>
> Thanks to everyone who contributed to the release!
>
> Cheers,
> The Go Team
>

-- 
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] Re: http Transport dies too slowly

2018-05-27 Thread Amnon Baron Cohen
No, just get rid of the clients map, and instead, just create a single
global client.
Http Clients are designed to be used by multiple goroutines.

On Sun, May 27, 2018 at 4:33 PM, Tamás Gulácsi  wrote:

> Map is not concurrency safe, you have to synchronize access. For example
> with a sync.Mutex.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/uDOBUBNIz3o/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@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] Re: http Transport dies too slowly

2018-05-27 Thread Amnon Baron Cohen
As Tamas said, reuse the client.

Just make the client into a global variable.


On Sunday, 27 May 2018 11:29:47 UTC+1, Vadim Lesich wrote:
>
> Do you have an example?
>
> воскресенье, 27 мая 2018 г., 8:39:50 UTC+3 пользователь Tamás Gulácsi 
> написал:
>>
>> Just reuse the created http.Client.
>
>

-- 
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: vgo with package path without dot

2018-02-24 Thread Amnon Baron Cohen


On Friday, 23 February 2018 
>
>
> I work with GOPATH per project. 
>
> Then I use to give them a one word path directly under src: 
>
> $GOPATH/src/myapp 
>
>
Go is a highly opinionated language assumes that you lay out your code as 
described in https://golang.org/doc/code.html
If you decide to do things differently (by having 'simpler' paths which do 
not correspond to the 
VCS location of your code on the net), then you end up having to fight the 
go tools, 
rather than have them work for 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: ListenAndServ and channels

2018-01-06 Thread Amnon Baron Cohen
The global var should have been protected by a mutex, or loaded and saved
using sync/atomic functions, as it is accessed from multiple goroutines.

Another minor point:

Why do:

result := fmt.Sprintf("Hello there %s", i)
io.WriteString(w, result)

instead of just:
fmt.Fprintf(w, "Hello there %s", i)



On Friday, 5 January 2018 23:58:01 UTC, matthe...@gmail.com wrote:
>
> Using a channel read in the http handler will block the ticker for loop 
> until the read occurs, but if you want that then pass mc into the generic 
> function: https://play.golang.org/p/GrHQxPhy1qu
>
> Using a buffered channel will keep the history of ticks and not block but 
> may run out of buffer space if the handler isn't called enough.
>
> Amnon's global var should work if you are just looking for the current 
> tick value.
>
> Matt
>
> On Friday, January 5, 2018 at 12:33:32 PM UTC-6, Amnon Baron Cohen wrote:
>>
>> try using a global var.
>> something like https://play.golang.org/p/05-xBDh5rgn
>>
>> On Thursday, 4 January 2018 15:09:41 UTC, Keith Brown wrote:
>>>
>>> I am trying to Serve a webpage while running a ticker in the background. 
>>> I am trying to generate a random number, genRandom() , periodically and 
>>> publish it on a channel so generic() can see the results. I have something 
>>> like this https://play.golang.org/p/6d1xmqpUYY7 but I don't know how to 
>>> get channel results to generic()? Do I need to make my mc channel a global? 
>>>
>>

-- 
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: ListenAndServ and channels

2018-01-05 Thread Amnon Baron Cohen
try using a global var.
something like https://play.golang.org/p/05-xBDh5rgn

On Thursday, 4 January 2018 15:09:41 UTC, Keith Brown wrote:
>
> I am trying to Serve a webpage while running a ticker in the background. I 
> am trying to generate a random number, genRandom() , periodically and 
> publish it on a channel so generic() can see the results. I have something 
> like this https://play.golang.org/p/6d1xmqpUYY7 but I don't know how to 
> get channel results to generic()? Do I need to make my mc channel a global? 
>

-- 
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: net/http Server Shutdown does not free up the port upon return

2017-12-08 Thread Amnon Baron Cohen
netstat is your friend

On Wednesday, 29 November 2017 04:53:48 UTC, Albert Tedja wrote:
>
> net/http's Shutdown() does not free up the port upon return, or rather it 
> seems a bit undefined how long it takes for the port to be reusable again.
>
> server := {
> Addr: fmt.Sprintf(":9000"),
> }
> go func() {
> fmt.Println("hosting...")
> err := server.ListenAndServe()
> }()
> time.Sleep(1 * time.Second)
>
> fmt.Println("closing")
> err := server.Shutdown(nil)
> fmt.Println("shutdown error", err)
>
> fmt.Println("hosting again...")
> err = server.ListenAndServe()
> fmt.Println("host again err", err)
>
>
>
> The code above, for example, sometimes successfully hosting the http 
> server twice, but sometimes, the second one fails with "address already in 
> use" error
>
> $ go run main.go 
> hosting...
> closing
> shutdown error 
> hosting again...
> // This is okay
>
> $ go run main.go 
> hosting...
> closing
> shutdown error 
> hosting again...
> host again err listen tcp :9000: bind: address already in use
>
> My question is, is this a bug, or an expected undetermined behavior? If 
> it's the latter, how can I safely make sure that Shutdown() completely 
> frees up the port used?
>
>

-- 
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: Variable JSON format parsing, any best practice?

2017-09-29 Thread Amnon Baron Cohen
No silver bullet.
But you can try defining value as json.RawMessage
in order to delay the parsing till you know what you have got.

See
http://eagain.net/articles/go-dynamic-json/

On Friday, 29 September 2017 00:41:53 UTC+1, Yaroslav Molochko wrote:
>
> I have following json messages:
>
> {"status":"success","data":["val1","val2","val3"]}
>
> {"status":"success","data":{"resultType":"vector","result":[{"metric":{"host_name":"hss4"},"value":[1504157313.787,"24"]},{"metric":{"host_name":"hss508"},"value":[1504157313.787,"32"]}]}}
>
> where *data* can have several formats:
> first one can be interpreted as:
>
> []string
>
> second line's data can be parsed as:
>
> type Data struct {
> ResultType string   `json:"resultType"`
> Resultstruct {
>
> Metric map[string]string `json:"metric"`
> Values Values`json:"values,omitempty"`
> Value  interface{}   `json:"value,omitempty"`
>
> }
> }
>
> I need to parse those JSON strings, how can I do that? I've tried to make 
> some parser function, the only way I come to was to create some custom 
> unmarshaling function, which unmarshals one type, and if there is no such 
> thing tries to unmarshal using another struct. 
> I believe there must be some other way around to make it more straight 
> forward. 
>
> Any suggestions will be highly appreciated. 
>

-- 
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: Bytconv where art thou

2017-09-25 Thread Amnon Baron Cohen
https://github.com/golang/go/issues/2632

>
>>

-- 
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: Newbie How to read unmarshall a varient struct in Json

2017-06-04 Thread Amnon Baron Cohen
Thanks for bringing the article to my attention.
The final section "*Encoding and decoding generics*" was exactly what I was 
looking for.


On Sunday, 4 June 2017 12:53:42 UTC+1, Jon Calhoun wrote:
>
> See the last section of this article where it talks about generics - 
> https://blog.gopheracademy.com/advent-2016/advanced-encoding-decoding/
>
> It isn't exactly what you are doing but the same idea should work in your 
> use case. The encoding/decoding code becomes longer but it makes using the 
> data simpler. 
>

-- 
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.