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

2020-01-14 Thread GopherNewbie
Hello Gophers,

I programmed a server (A) that listens on 2 different ports, but I would 
like to change one of the ports to be sending the client's received 
requests to another server (B) so that when the server (B) replies the 
server (A) sends the answer to that specific client.

I got some issues with *goroutines and channels*

note: 
- We can have more than one client ( each client should only get what they 
sent )
- The comments in the codes show how I was thinking to do it.

Please help...

*code here: https://play.golang.org/p/ERvKIHfl_3A 
*

-- 
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/1a6c19b4-717e-4eeb-9636-7622659abd6e%40googlegroups.com.


[go-nuts] Re: What is idiomatic way to find if struct field is exported or not?

2020-01-14 Thread tmaclong0521


if !reflect.ValueOf(strct).Field(i).CanInterface() {
   continue
}


在 2016年4月27日星期三 UTC+8上午3:10:34,Tad Vizbaras写道:
>
> While reviewing number of popular packages online I noticed different 
> approaches to the same problem:
> how to find if struct field is exported or not?
>
> Some use PkgPath and check if it is empty:
>
> // skip unexported fields
> if len(f.PkgPath) != 0 {
> continue
> }
>
> Some check if field is settable something like:
>
> // Don't even bother for unexported fields.
> if !v.CanSet() {
> return nil
> }
>
> Stdlib does not seem to have IsExported() so question is: which way is 
> idiomatic?
>
>
>

-- 
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/91d7980c-f4ec-4a6c-ab74-2bbd898a714c%40googlegroups.com.


Re: [go-nuts] How to append all new messages in a slice?

2020-01-14 Thread Kurtis Rader
Line 55 creates a new slice1 object every time you execute the body of the
loop. So it's always empty when you do the append(slice1, dataT). Try
moving it to line 37. I didn't closely examine your code but it looks like
there are other problems with it. For example, you don't use slice2 and the
logic for assigning to it looks wrong.

On Tue, Jan 14, 2020 at 7:03 PM nks  wrote:

> Hello Gophers,
>
> I created a TCP server that gets all the requests from the client and
> replies, however, when I try to append those requests in a slice, *the
> next request erases the previous one.*
>
> *The server should get requests and continuously save them in a slice for
> future manipulation.*
>
> *here is the code: https://play.golang.org/p/iooHSaoUFS4
> *
>
>
> please help me to fix it...
>
>
> --
> 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/9211b53e-d3b2-4fdb-81a3-84bb757a585f%40googlegroups.com
> 
> .
>


-- 
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/CABx2%3DD9SvHT%3DFZBBoFdA%3DTDLfrD6VMceGtmrxx5PKKfv-6WRBA%40mail.gmail.com.


[go-nuts] How to append all new messages in a slice?

2020-01-14 Thread nks
Hello Gophers,

I created a TCP server that gets all the requests from the client and 
replies, however, when I try to append those requests in a slice, *the next 
request erases the previous one.*

*The server should get requests and continuously save them in a slice for 
future manipulation.*

*here is the code: https://play.golang.org/p/iooHSaoUFS4  
*


please help me to fix it...


-- 
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/9211b53e-d3b2-4fdb-81a3-84bb757a585f%40googlegroups.com.


Re: [go-nuts] Getting from a string to an object value - how?

2020-01-14 Thread Ian Lance Taylor
On Tue, Jan 14, 2020 at 10:27 AM 'Vinay Sajip' via golang-nuts
 wrote:
>
> I have a string value that I’d like to convert into an actual object in my 
> running program. The string would be read from a configuration file. For 
> example, the string "os:Stdin" should be processable somehow to get the 
> actual variable os.Stdin. Is that possible in Go? The reflect package seems 
> to only work on objects you already have; I’ve also had a look at the 
> go/importer package, but that seems to primarily deal with source-level 
> information and doesn’t seem to allow you to bridge from there to already 
> existing objects in memory. Other-language equivalents would be 
> Class.forName(...) in Java or Assembly.GetType(...) in C#. Can anyone supply 
> any useful pointers? I know about the plugin package, but AFAIK it doesn’t 
> work on Windows.

In general this is not possible in Go.  Sorry.

If you can restrict yourself to exported package-scope variables, then
you can probably use the debug/pe (on Windows) package to look up the
symbol name and use that value as the variable's address.

Or in some cases you can keep a registry of names that you need to find.

Note that by default the Go linker will discard unreferenced variables
and functions, so the fact that a variable exists in the package
doesn't mean it will exist in the final linked executable.

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/CAOyqgcW7ZBw2skQ%2BFX9_6hcrOtcOhsmGq3nJh-2Xs%3DYQcfXh-w%40mail.gmail.com.


[go-nuts] Re: crypto data types

2020-01-14 Thread R Srinivasan
Indeed. My search yielded:

go get -u -v github.com/ianmcmahon/encoding_ssh

which had exactly what I needed (and should probably be included in the 
standard ssh package)

The use case itself - a digital signature facility in our Over The Network 
software upgrade procedure. 

The following is a go rewrite of the tool (from my previous project) :

https://github.com/RajaSrinivasan/disign.git

thanks, srini

On Tuesday, January 14, 2020 at 8:43:29 AM UTC-5, a2800276 wrote:
>
>
>> looking for guidance on how to get an rsa.PublicKey from id_rsa.pub
>> seems like I can parse the id_rsa.pub contents and get a ssh.PublicKey 
>> but how do I transform this into an rsa.PublicKey
>> i need the coersion in order to use other support services.
>>
>>
> Please consider whether this is really what you need to be doing. If 
> you're being provided with a id_rsa.pub file (presumably from a .ssh 
> configuration directory) you will very likely be performing ssh operations, 
> which are ideally left up to the ssh library to perform. 
>
> If you have a very exotic usecase an know what you are doing, the ssh 
> package uses the crypto.rsa package internally to parse the ssh keyfiles, 
> so just have a look at the implementation there: 
> https://github.com/golang/crypto/blob/master/ssh/keys.go#L262
>
> Good Luck! 
>

-- 
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/e1ab26d1-e5e6-44c3-9bda-4a2a20d5ec15%40googlegroups.com.


[go-nuts] Getting from a string to an object value - how?

2020-01-14 Thread 'Vinay Sajip' via golang-nuts
I have a string value that I’d like to convert into an actual object in my 
running program. The string would be read from a configuration file. For 
example, the string "os:Stdin" should be processable somehow to get the 
actual variable os.Stdin. Is that possible in Go? The reflect package seems 
to only work on objects you already have; I’ve also had a look at the 
go/importer package, but that seems to primarily deal with source-level 
information and doesn’t seem to allow you to bridge from there to already 
existing objects in memory. Other-language equivalents would be 
Class.forName(...) in Java or Assembly.GetType(...) in C#. Can anyone 
supply any useful pointers? I know about the plugin package, but AFAIK it 
doesn’t work on Windows.

Regards,

Vinay Sajip

-- 
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/c8e23c9a-04c2-4bbc-a14d-87ef45ed0009%40googlegroups.com.


[go-nuts] TLS connection cannot be used after timeout of "SetDealine"

2020-01-14 Thread petavy
Hi Gophers,

I have client code which test network transfer performance per second.

For that I use "conn.SetDeadline(time.Second)".
The performance testing is performed in a loop ot 5 rounds where each round 
sets a "SetDeadline" and then d a io.Copy/ZeroReader to the server and 
count the transfered bytes.

This works perfectly with a normal NON-TLS connection to a server. 
After each Timeout because of "SetDeadline" the NON-TLS connection is still 
valid and can be reused.

However, if I do the same with a TLS connection then after the first 
"SetDeadline" and timeout the connection is somehow broken and cannot be 
used anymore for further io.Copy's.

Here is some test code which tests 5 rounds of SetDeadline/ at 1st with a 
standard conneciton and then with TLS connection.
With the TLS connection it breaks and 0 bytes are transfered all the time.

Looking for help :-)

Thanks - Marcel.

package main

import (
"context"
"crypto/rand"
"crypto/tls"
"encoding/hex"
"io"
"io/ioutil"
"log"
"net"
"time"
)

const (
ciddr= ":5000"
keyInHex = 
"2d2d2d2d2d424547494e2050524956415445204b45592d2d2d2d2d0d0a4d494945764149424144414e42676b71686b6947397730424151454641415343424b59776767536941674541416f49424151444f4259315353616b386c7955530d0a384f597252477334314b7456554c647439516e71597169555636465a4e4b764f7a6c56717274506e76355a564d4a5462334d75326a4f2f54694b32366b5647440d0a2f584b61436b564e6b7647687a4e514736467a426a4d67734d72616f5a59472f49523744333663724847344553717251713645326647706c4766716d526643370d0a4c53744f487a364a4f476250715670346c645a546d70335334565857786a73326e4a4d3637576d577061436975566351376a703976576f50325657664659426a0d0a447a49547633574d6f477451466c42614947307934395a68626e32793056414e304c4b6c4775476244386b6543764a66372b65414b5a6a7668746364612b586b0d0a72496d4e51544a4d4f624c2b6e5455305a7771666a4574754c46736336696a306f5278384543584475585a73537731536b784e4c4d494576315843577531434d0d0a31447042626b4b2f41674d424141454367674541496e356b6c6b316a363644672b437a5166736b5a524c56566a794f46622b594e6571324e314d477757750d0a6a6957417866516f73"
 +

"6c712f43522b4d7136366b716762424b525268744b33776a73655762314944493544356a35357a2f4b7849387257534a78714e6443736d0d0a714e626e464864524e6530705546544f593761775372673931344a4a494e336d5a4674534d5465766236503641746c7053346b4d736d2f5a596441672b5750350d0a422f663177736b69356944684d582f3364773532454830574d5743554e3256414a2f696d316e365732616e6c3054494f4a69774d30336a732b767a61367048650d0a59443347345366702f5a53303573576f2f7846796677384245565673655535736d70545852775379544f484d763178714835584c4f4b367845615173386c42560d0a4b6b77676f794849364c334b6975756d6a45396656667a6a5a686968682f443241616570753262446d514b426751447a2b4e3662476e73693468744f3347394a0d0a36743870776d39475565346f764f367131377132396f726d31426751322f516462674c785641417442336436544939586b566c516f744a58756562537a3674510d0a66763971674d6c6b5a6552413965367a49416668553457526b5270557448584c3047476875583546696954363532316b456f657833726b6747417437593353670d0a2b314749645a3474774252616b536434474b7556775a514d41774b42675144594c62646479773543486178596c"
 +

"5275593874477945616f726a564e4e4c440d0a6d5030374748726a6c343970697a4e54775a493770666833466c4f36504a3544664d6b4c7231487853416f394151376f44585470506e716457433637544279670d0a50387a325544434164786d442b4d4872766b2f7070536c356a5944394f3839777133417166326b7767634f35554150484a47367a304a4f45366477482b4f48350d0a79437747684755586c514b426748516a767553624949386b6a39646b7646323176334b447172455241347a46452b436b5062416e6755774e487a2b33565768460d0a48495742645776364a2f684352654a72774e6251433833544933797265325167634c706b674871597671586c375447385238514f484947465438474f2f7078390d0a6f4678366a772f506958636667455770524974352b5371384234732f64782f44513762774e744b556f35765269625a3047417038556c7539416f4741427554650d0a5669566c6e525168536b4c47634537456e43476a5771415a324f4c495865694247754e61392b736262626738754d305268736c794e516f4850596331584e32620d0a343732426c58704171565668546c4576693069737a4676466b622b4a6f69716d744b77312f384c4d6b344c5a5846564459795962506e3865762f537156754f410d0a766a6f313970414d31396f505a4d6871703131"
 +

"646476326d514c4c564d67774b4b324d4a666b6b43675942504243304b6579624736444964356d5a4a7056394b0d0a4238575a5663727945447a786f75486473517145686637666c355a7532467a38326b656d41686a616b3531554546525437674e596b4b414753673877507453610d0a75614c2f2b4c626174504d2b5a6c716a51417859354f3454392b4e56305875546d4644744f4c366765493054665374306a6179754e654b6c68374c63516c6e510d0a6270495853574c2b707850655a6858774e2b316972773d3d0d0a2d2d2d2d2d454e442050524956415445204b45592d2d2d2d2d0d0a"
pemInHex = 

[go-nuts] Re: crypto data types

2020-01-14 Thread a2800276

>
>
> looking for guidance on how to get an rsa.PublicKey from id_rsa.pub
> seems like I can parse the id_rsa.pub contents and get a ssh.PublicKey but 
> how do I transform this into an rsa.PublicKey
> i need the coersion in order to use other support services.
>
>
Please consider whether this is really what you need to be doing. If you're 
being provided with a id_rsa.pub file (presumably from a .ssh configuration 
directory) you will very likely be performing ssh operations, which are 
ideally left up to the ssh library to perform. 

If you have a very exotic usecase an know what you are doing, the ssh 
package uses the crypto.rsa package internally to parse the ssh keyfiles, 
so just have a look at the implementation there: 
https://github.com/golang/crypto/blob/master/ssh/keys.go#L262

Good Luck! 

-- 
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/1d89c44c-10a4-4379-87a1-0b5da6c81460%40googlegroups.com.


Re: [go-nuts] Shell alias to get latest go versions?

2020-01-14 Thread Paul Jolly
I think you're after something like (for your OS/arch):

wget https://dl.google.com/go/$(curl -s
https://golang.org/dl/?mode=json | jq -r
.[0].version).linux-amd64.tar.gz

The JSON mode of the download page being the key here.

On Tue, 14 Jan 2020 at 09:22, Steve Mynott  wrote:
>
> Does anyone have a simple shell alias, function or similar to get the
> latest released versions of go?
>
> Is there a cleaner way of going this than screen scraping the website
> or looking at tags in git?
>
> --
> Steve Mynott 
> cv25519/ECF8B611205B447E091246AF959E3D6197190DD5
>
> --
> 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/CANuZA8R2j8_0pgbNw13qAq82dTJonCsXgnNS0vhKD_dxzwhwfw%40mail.gmail.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/CACoUkn5080_QzQiP%3D-gn8E1h7k837FCRr7WQ_D0bBxiyw01QmQ%40mail.gmail.com.


[go-nuts] Shell alias to get latest go versions?

2020-01-14 Thread Steve Mynott
Does anyone have a simple shell alias, function or similar to get the
latest released versions of go?

Is there a cleaner way of going this than screen scraping the website
or looking at tags in git?

-- 
Steve Mynott 
cv25519/ECF8B611205B447E091246AF959E3D6197190DD5

-- 
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/CANuZA8R2j8_0pgbNw13qAq82dTJonCsXgnNS0vhKD_dxzwhwfw%40mail.gmail.com.