Re: [go-nuts] How to convert C unsigned char * to golang string
On Mon, Dec 16, 2019 at 8:51 PM wrote: > > I am using CGO to call a .so library written by C, and it has a param > unsigned char *result_buffer > > I use a C.uchar to receive its result, but how to convert it a Go string? You should receive the result in a *C.uchar. You can get a Go string by calling something like C.GoString((*C.char)(unsafe.Pointer(p))). See https://golang.org/cmd/cgo. 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/CAOyqgcWF554MBHVnjpMt6ex_XpM0V%2BfiqoTv6nqe_Nq-3nN0vw%40mail.gmail.com.
[go-nuts] How to convert C unsigned char * to golang string
I am using CGO to call a .so library written by C, and it has a param unsigned char *result_buffer I use a C.uchar to receive its result, but how to convert it a Go 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ec83bbd7-1580-4d32-8c2b-1ad11d3a6335%40googlegroups.com.
Re: [go-nuts] Re: bufio.Reader.Buffered returns 0
Thanks Marvin, I think I understand now. Sorry Ian I didn't even notice, but still... I was using a net.Conn as the underlying reader. What I really needed was the Peek() function but the documentation for Buffered() made it seem more appropriate. I only needed to know the number of bytes received over the connection before evicting and interpreting them. intBytes, err := reader.Peek(4) if err == nil { // Decode integer reader.Discard(4) } -Sam On Mon, Dec 16, 2019 at 7:27 AM Marvin Renich wrote: > * Ian Lance Taylor [191215 23:05]: > > The Buffered method [snip] tells you how > > many bytes you can Read without causing a call to the underlying > > Reader. > > I think this would be a significant improvement over the current > ambiguous documentation. It should adequately dispel any unrealistic > expectations on the part of programmers who are reading the > documentation. > > ...Marvin > > -- > 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/1smBsPOdFT0/unsubscribe. > To unsubscribe from this group and all its topics, 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/20191216122707.4nx3gueuibk4dpua%40basil.wdw > . > -- 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/CAFr%2B4KQe%3D4B%2BHF0k9y72RaW0NYZ_N2Jvap_moWtSdWiHmbDaLQ%40mail.gmail.com.
[go-nuts] [ANN] go-jsonstruct: generate Go structs from multiple JSON objects
Do you have a bunch of JSON objects with no schema that you want to idiomatically unmarshall in Go? Existing JSON-to-Go struct generators take one object as input. This one takes all the JSON objects you can throw at it, be they API responses, unstructured JSON column values in a database, or a document dump from CouchDB or MongoDB. You get back the most-specific Go type that you can unmarshall all the observed values into with encoding/json. https://github.com/twpayne/go-jsonstruct Feedback and improvements welcome :) Tom -- 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/1b171f33-37d8-472a-b775-d2068f7c7f7d%40googlegroups.com.
[go-nuts] Re: TLS Cipher suites TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
There is always github.com/spacemonkeygo/openssl (even then, openssl deprecates non-recommended crypto, so you may need to build against an old version) -- 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/8cdb1026-e8d8-42ff-aafe-1870914a11c8%40googlegroups.com.
Re: [go-nuts] Re: bufio.Reader.Buffered returns 0
* Ian Lance Taylor [191215 23:05]: > The Buffered method [snip] tells you how > many bytes you can Read without causing a call to the underlying > Reader. I think this would be a significant improvement over the current ambiguous documentation. It should adequately dispel any unrealistic expectations on the part of programmers who are reading the documentation. ...Marvin -- 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/20191216122707.4nx3gueuibk4dpua%40basil.wdw.
[go-nuts] Re: Kafka with ssl is not working
Yes i am able to connect using that command. The server is working fine with python code. from kafka import KafkaProducer, KafkaConsumer from time import gmtime, strftime import io import io #print "Start 'test'" + strftime("%Y-%m-%d %H:%M:%S", gmtime()) broker_string = "*"; kafka_brokers_list = broker_string.split(',') print kafka_brokers_list print "Creating consumer" consumer = KafkaConsumer(bootstrap_servers=kafka_brokers_list, group_id='test', security_protocol='SSL', ssl_check_hostname=False, ssl_cafile='ca.pem', ssl_certfile='bo-rsa.pem', ssl_keyfile='bo-rsa.key') print consumer.topics() consumer.subscribe(['*']) for msg in consumer: #buf2 = io.BytesIO(msg.value) print msg #consumer.commit(); #print load(buf2,avro.schema) On Monday, 16 December 2019 12:22:31 UTC+5:30, sounthar cs wrote: > > Hi All, > > I am trying to consume data from the existing kafka server. > > *I am able to consume it successfully through python code*. > > But i want the same to be working with golang. > > > i have tried sarama, confluent-kafka-go & github.com/segmentio/kafka-go. > > i am getting the below error: > > 2019/12/16 06:28:32 client/metadata fetching metadata for all topics from > broker *.*.*.*:9093 > > 2019/12/16 06:28:32 Failed to connect to broker *.*.*.*:9093: tls: first > record does not look like a TLS handshake > > 2019/12/16 06:28:32 client/metadata got error from broker -1 while > fetching metadata: tls: first record does not look like a TLS handshake > > 2019/12/16 06:28:32 client/metadata no available broker to send metadata > request to > > 2019/12/16 06:28:32 client/brokers resurrecting 3 dead seed brokers > > 2019/12/16 06:28:32 Closing Client > > 2019/12/16 06:28:32 unable to create kafka client: "kafka: client has run > out of available brokers to talk to (Is your cluster reachable?)" > > > > package main > > > // Run with: > > // go build examples/base-client/*.go > > // ./base-client > > > import ( > > "crypto/tls" > > "crypto/x509" > > "io/ioutil" > > "log" > > "os" > > "os/signal" > > "sync" > > > "github.com/Shopify/sarama" > > ) > > > func main() { > > logger := log.New(os.Stderr, "", log.LstdFlags) > > sarama.Logger = logger > > tlsConfig, err := NewTLSConfig("bo-rsa.pem", > > "bo-rsa.key", > > "ca.pem") > > if err != nil { > > log.Fatal(err) > > } > > // This can be used on test server if domain does not match cert: > > // tlsConfig.InsecureSkipVerify = true > > > consumerConfig := sarama.NewConfig() > > consumerConfig.Net.TLS.Enable = true > > consumerConfig.Net.TLS.Config = tlsConfig > > > client, err := sarama.NewClient([]string{"*.*.*.*:9093","*.*.*.*:9093"," > *.*.*.*:9093"}, consumerConfig) > > if err != nil { > > log.Fatalf("unable to create kafka client: %q", err) > > } > > > consumer, err := sarama.NewConsumerFromClient(client) > > if err != nil { > > log.Fatal(err) > > } > > defer consumer.Close() > > > consumerLoop(consumer, "rlcmData__ONOS__CTC31") > > } > > > // NewTLSConfig generates a TLS configuration used to authenticate on > server with > > // certificates. > > // Parameters are the three pem files path we need to authenticate: client > cert, client key and CA cert. > > func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string) > (*tls.Config, error) { > > tlsConfig := tls.Config{} > > > // Load client cert > > cert, err := tls.LoadX509KeyPair(clientCertFile, clientKeyFile) > > if err != nil { > > return , err > > } > > tlsConfig.Certificates = []tls.Certificate{cert} > > tlsConfig.InsecureSkipVerify =true > > // Load CA cert > > caCert, err := ioutil.ReadFile(caCertFile) > > if err != nil { > > return , err > > } > > caCertPool := x509.NewCertPool() > > caCertPool.AppendCertsFromPEM(caCert) > > tlsConfig.RootCAs = caCertPool > > > tlsConfig.BuildNameToCertificate() > > return , err > > } > > > func consumerLoop(consumer sarama.Consumer, topic string) { > > partitions, err := consumer.Partitions(topic) > > if err != nil { > > log.Println("unable to fetch partition IDs for the topic", topic, err) > > return > > } > > > // Trap SIGINT to trigger a shutdown. > > signals := make(chan os.Signal, 1) > > signal.Notify(signals, os.Interrupt) > > > var wg sync.WaitGroup > > for partition := range partitions { > > wg.Add(1) > > go func() { > > consumePartition(consumer, int32(partition), signals) > > wg.Done() > > }() > > } > > wg.Wait() > > } > > > func consumePartition(consumer sarama.Consumer, partition int32, signals > chan os.Signal) { > > log.Println("Receving on partition", partition) > > partitionConsumer, err := consumer.ConsumePartition("test", partition, > sarama.OffsetNewest) > > if err != nil { > > log.Println(err) > > return > > } > > defer func() { > > if err := partitionConsumer.Close(); err != nil { > > log.Println(err) > > } > > }() > > > consumed := 0 > > ConsumerLoop: > > for { >
[go-nuts] Re: Kafka with ssl is not working
Are you sure that the Kafka instance you're connecting to does use TLS? openssl s_client -connect ...:9093 can connect? 2019. december 16., hétfő 7:52:31 UTC+1 időpontban sounthar cs a következőt írta: > > Hi All, > > I am trying to consume data from the existing kafka server. > > *I am able to consume it successfully through python code*. > > But i want the same to be working with golang. > > > i have tried sarama, confluent-kafka-go & github.com/segmentio/kafka-go. > > i am getting the below error: > > 2019/12/16 06:28:32 client/metadata fetching metadata for all topics from > broker *.*.*.*:9093 > > 2019/12/16 06:28:32 Failed to connect to broker *.*.*.*:9093: tls: first > record does not look like a TLS handshake > > 2019/12/16 06:28:32 client/metadata got error from broker -1 while > fetching metadata: tls: first record does not look like a TLS handshake > > 2019/12/16 06:28:32 client/metadata no available broker to send metadata > request to > > 2019/12/16 06:28:32 client/brokers resurrecting 3 dead seed brokers > > 2019/12/16 06:28:32 Closing Client > > 2019/12/16 06:28:32 unable to create kafka client: "kafka: client has run > out of available brokers to talk to (Is your cluster reachable?)" > > > > package main > > > // Run with: > > // go build examples/base-client/*.go > > // ./base-client > > > import ( > > "crypto/tls" > > "crypto/x509" > > "io/ioutil" > > "log" > > "os" > > "os/signal" > > "sync" > > > "github.com/Shopify/sarama" > > ) > > > func main() { > > logger := log.New(os.Stderr, "", log.LstdFlags) > > sarama.Logger = logger > > tlsConfig, err := NewTLSConfig("bo-rsa.pem", > > "bo-rsa.key", > > "ca.pem") > > if err != nil { > > log.Fatal(err) > > } > > // This can be used on test server if domain does not match cert: > > // tlsConfig.InsecureSkipVerify = true > > > consumerConfig := sarama.NewConfig() > > consumerConfig.Net.TLS.Enable = true > > consumerConfig.Net.TLS.Config = tlsConfig > > > client, err := sarama.NewClient([]string{"*.*.*.*:9093","*.*.*.*:9093"," > *.*.*.*:9093"}, consumerConfig) > > if err != nil { > > log.Fatalf("unable to create kafka client: %q", err) > > } > > > consumer, err := sarama.NewConsumerFromClient(client) > > if err != nil { > > log.Fatal(err) > > } > > defer consumer.Close() > > > consumerLoop(consumer, "rlcmData__ONOS__CTC31") > > } > > > // NewTLSConfig generates a TLS configuration used to authenticate on > server with > > // certificates. > > // Parameters are the three pem files path we need to authenticate: client > cert, client key and CA cert. > > func NewTLSConfig(clientCertFile, clientKeyFile, caCertFile string) > (*tls.Config, error) { > > tlsConfig := tls.Config{} > > > // Load client cert > > cert, err := tls.LoadX509KeyPair(clientCertFile, clientKeyFile) > > if err != nil { > > return , err > > } > > tlsConfig.Certificates = []tls.Certificate{cert} > > tlsConfig.InsecureSkipVerify =true > > // Load CA cert > > caCert, err := ioutil.ReadFile(caCertFile) > > if err != nil { > > return , err > > } > > caCertPool := x509.NewCertPool() > > caCertPool.AppendCertsFromPEM(caCert) > > tlsConfig.RootCAs = caCertPool > > > tlsConfig.BuildNameToCertificate() > > return , err > > } > > > func consumerLoop(consumer sarama.Consumer, topic string) { > > partitions, err := consumer.Partitions(topic) > > if err != nil { > > log.Println("unable to fetch partition IDs for the topic", topic, err) > > return > > } > > > // Trap SIGINT to trigger a shutdown. > > signals := make(chan os.Signal, 1) > > signal.Notify(signals, os.Interrupt) > > > var wg sync.WaitGroup > > for partition := range partitions { > > wg.Add(1) > > go func() { > > consumePartition(consumer, int32(partition), signals) > > wg.Done() > > }() > > } > > wg.Wait() > > } > > > func consumePartition(consumer sarama.Consumer, partition int32, signals > chan os.Signal) { > > log.Println("Receving on partition", partition) > > partitionConsumer, err := consumer.ConsumePartition("test", partition, > sarama.OffsetNewest) > > if err != nil { > > log.Println(err) > > return > > } > > defer func() { > > if err := partitionConsumer.Close(); err != nil { > > log.Println(err) > > } > > }() > > > consumed := 0 > > ConsumerLoop: > > for { > > select { > > case msg := <-partitionConsumer.Messages(): > > log.Printf("Consumed message offset %d\nData: %s\n", msg.Offset, msg.Value) > > consumed++ > > case <-signals: > > break ConsumerLoop > > } > > } > > log.Printf("Consumed: %d\n", consumed) > > } > -- 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/66e6341d-4f40-4e2e-8bc3-aa3a2368c42c%40googlegroups.com.