[go-nuts] Run a method with nil pointer

2018-09-03 Thread Dat Huynh
Just a question.

Why does Go allow to call a method with a nil pointer?

https://play.golang.org/p/xPehesnfK9b

Thanks,
Dat.

-- 
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] encoding/csv: Is this a bug?

2017-07-17 Thread Dat Huynh
Hi all,

I have a problem with parsing a .csv file using the library "encoding/csv".

I wonder if that is the problem of Microsoft Excel or the Go library.

I am using Microsoft Excel version 14.2.2 on MacOS and go1.8.3 darwin/amd64

What did I do?

Firstly I input the below values into an Excel sheet, and save as a .csv
file.
value 11 value 12
value 21 value 22
value 31 value 32

If I choose "Comma Separated Values (.csv)" in the option "Format", type
the file name "data.csv", and run my Go app, it returns:

$ go run demo.go
value 31 value 32]12

If I choose "Window Comma Separated (.csv)" in the option "Format", type
the file name "data.csv", and run my Go app, it works well.

$ go run demo.go
0 [value 11 value 12]
1 [value 21 value 22]
2 [value 31 value 32]

Could you please confirm if this is a bug of the library or MS Excel?

Below is my code.

package main

import (
"encoding/csv"
"fmt"
"os"
)

func main() {
file, _ := os.Open("data.csv")
defer file.Close()
csvReader := csv.NewReader(file)
records, _ := csvReader.ReadAll()
for index, record := range records {
fmt.Println(index, record)
}
}

Thank you very much.

Regards,
Dat Huynh.

-- 
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] Marshal and unmarshal data using in encoding/xml and encoding/json packages

2017-06-20 Thread Dat Huynh
Hi,

I think something is wrong here.

If it is not a bug of the library, I think we will need to re-think why we
need to build the library.

Why do we need to marshal something and then we cannot unmarshal it?

Thank you very much.

Regards,
Dat.






On Wed, Jun 21, 2017 at 11:57 AM, Kiki Sugiaman <ksugia...@gmail.com> wrote:

> According to the docs, the library marshals according to the following
> criteria:
>
> The name for the XML elements is taken from, in order of preference:
> - 
> - the name of the marshaled type
>
> As a result, the library translates a sequence of slice elements of go
> basic types into a sequence of xml elements with differing tags.
>
> When unmarshaling into a go slice, the library doesn't have a criteria to
> follow on how to unmarshal such sequence of xml elements.
>
> I myself would rather see the lib throw an error during the marshaling
> step. However, the lib works as intended as of now in the sense that:
> - it doesn't promise a roundtrip-ing ability
> - it follows its marshaling and unmarshaling criteria
>
> Modifying the current marshaling steps would break go1compat (
> https://golang.org/doc/go1compat).
>
>
>
> On 21/06/17 11:19, Dat Huynh wrote:
>
>> Hi Kiki,
>>
>> Ian has bought it back and I replied it.
>>
>> Thanks,
>> Dat.
>>
>>
>>
>> On Wed, Jun 21, 2017 at 10:58 AM, Kiki Sugiaman <ksugia...@gmail.com
>> <mailto:ksugia...@gmail.com>> wrote:
>>
>> May I bring this email back into the mailing list so other people
>> could refer to it?
>>
>>
>>
>> On 20/06/17 19:52, Dat Huynh wrote:
>>
>> No worries.
>>
>> It is actually a bug. I reported it here.
>> https://github.com/golang/go/issues/20735
>> <https://github.com/golang/go/issues/20735>
>>
>> Regards,
>> Dat.
>>
>>
>>
>>
>> On Tue, Jun 20, 2017 at 7:49 PM, Kiki Sugiaman
>> <ksugia...@gmail.com <mailto:ksugia...@gmail.com>
>> <mailto:ksugia...@gmail.com <mailto:ksugia...@gmail.com>>> wrote:
>>
>>  Didn't realize that I replied only to you instead of the
>> mailing
>>  listapologies!
>>
>>
>>
>>  On 20/06/17 17:05, Kiki Sugiaman wrote:
>>
>>  In both cases, you unmarshal into a go slice.
>>
>>  [1,2,"Third element","2009-11-10T23:00:00Z",true]
>>  ... looks like an array
>>
>>  12Third
>> element2009-11-
>> 10T23:00:00Ztrue
>>  ... does not
>>
>>  There is no bug in this case.
>>
>>
>>
>>  On 20/06/17 08:40, Dat Huynh wrote:
>>
>>  Hi all,
>>
>>  I am using the libraries "encoding/xml" and
>> "encoding/json"
>>  to marshal and unmarshal a slice.
>>
>>  I wonder why the method Unmarshal in encoding/xml
>> does not
>>  return a slice as what I have from encoding/json.
>>
>>  The below is my example.
>> https://play.golang.org/p/ZlALkyCbzX
>> <https://play.golang.org/p/ZlALkyCbzX>
>>  <https://play.golang.org/p/ZlALkyCbzX
>> <https://play.golang.org/p/ZlALkyCbzX>>
>>
>>  Do I miss something or is this a bug of the library?
>>
>>  Thank you very much.
>>
>>  Sincerely,
>>  Dat.
>>
>>  -- 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
>> <mailto:golang-nuts%2bunsubscr...@googlegroups.com>
>>  <mailto:golang-nuts%2bunsubscr...@googlegroups.com
>> <mailto:golang-nuts%252bunsubscr...@googlegroups.com>>
>>  <mailto:golang-nuts+unsubscr...@googlegroups.com
>> <mailto:golang-nuts%2bunsubscr...@googlegroups.com>
>>  <mailto:golang-nuts%

Re: [go-nuts] Marshal and unmarshal data using in encoding/xml and encoding/json packages

2017-06-20 Thread Dat Huynh
I created an issue for this on github.

https://github.com/golang/go/issues/20735

Regards,
Dat.





On Wed, Jun 21, 2017 at 9:30 AM, Ian Lance Taylor <i...@golang.org> wrote:

> On Mon, Jun 19, 2017 at 3:40 PM, Dat Huynh <audathu...@gmail.com> wrote:
> >
> > I am using the libraries "encoding/xml" and "encoding/json" to marshal
> and
> > unmarshal a slice.
> >
> > I wonder why the method Unmarshal in encoding/xml does not return a
> slice as
> > what I have from encoding/json.
> >
> > The below is my example.
> > https://play.golang.org/p/ZlALkyCbzX
> >
> > Do I miss something or is this a bug of the library?
>
> I'm not sure how to answer this other than to say that XML and JSON
> are different representations that serve different needs and work in
> different ways.  They aren't intended to be interchangeable.  See
> https://golang.org/pkg/encoding/xml/#pkg-note-BUG .
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Create methods for structs at runtime

2017-06-20 Thread Dat Huynh
Hi Ian,

The struct instance I create for an interface will actually take the role
of transport layer.
I will not implement the real logic of the methods of the interface in
client side.
The real implementation for the logic of the methods will be implemented on
the server side only.

In the implementation of the methods for the struct instance, I write code
to send interface name, method name and parameters to the server via my own
protocol (e.g HTTP).
Then it also receives and returns results to the place where we call
methods.

After we have such a library, we can use it with any interfaces and any
methods, client side and server side will talk each other in our own
protocol.
You can encrypt data, compress data and do whatever with the data before
you transfer it.

Programers in client side just need to know which interface they want to
use and they just  use the library "servicefactory" to create a struct
instance and use it to talk to the server. Before that, they must specify
the IP to tell where the server is.

I have successfully implemented the idea in Java and used it in my system
with hundreds of interfaces.
I wonder why I cannot do it in Go easily as what I did with Java.

Regards,
Dat.







On Wed, Jun 21, 2017 at 6:00 AM, Ian Lance Taylor <i...@golang.org> wrote:

> On Mon, Jun 19, 2017 at 8:38 PM, Dat Huynh <audathu...@gmail.com> wrote:
> >
> > On Tuesday, June 20, 2017 at 4:07:46 AM UTC+10, Ian Lance Taylor wrote:
> >>
> >> On Sat, Jun 17, 2017 at 5:17 PM, Dat Huynh <audat...@gmail.com> wrote:
> >> > Why do you need this feature?
> >
> >
> > I have already answered the question in my email replying Lutz Horn.
>
> Thanks.  Unfortunately, I don't understand your answer.  You still
> have to write the methods somewhere.  reflect.MakeStruct is not going
> to write the methods for you.  And once you write the methods, you
> have a type that implements the interface that you want.
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Create methods for structs at runtime

2017-06-19 Thread Dat Huynh

On Tuesday, June 20, 2017 at 4:07:46 AM UTC+10, Ian Lance Taylor wrote:
>
> On Sat, Jun 17, 2017 at 5:17 PM, Dat Huynh <audat...@gmail.com 
> > wrote: 
> > Why do you need this feature? 
>

I have already answered the question in my email replying Lutz Horn.

Thank you very much.

Sincerely,
Dat.

-- 
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] Marshal and unmarshal data using in encoding/xml and encoding/json packages

2017-06-19 Thread Dat Huynh
Hi all,

I am using the libraries "encoding/xml" and "encoding/json" to marshal and
unmarshal a slice.

I wonder why the method Unmarshal in encoding/xml does not return a slice
as what I have from encoding/json.

The below is my example.
https://play.golang.org/p/ZlALkyCbzX

Do I miss something or is this a bug of the library?

Thank you very much.

Sincerely,
Dat.

-- 
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] Create methods for structs at runtime

2017-06-17 Thread Dat Huynh
Hi Ian,

Could you please let me know if there is any plan to fix the limitation?

Indeed, I am considering if it is worthwhile to rewrite my projects in Go.
I have hundreds of interfaces in my Java apps and this feature will help me
a lot.

Thank you very much.

Sincerely,
Dat.






On Wed, Jun 14, 2017 at 2:34 PM, Ian Lance Taylor <i...@golang.org> wrote:

> On Tue, Jun 13, 2017 at 9:27 PM, Dat Huynh <audathu...@gmail.com> wrote:
> >
> > I have a question about Go.
> >
> > Given an interface, how can I create a struct instance with the methods
> of
> > the interface at runtime?
> >
> > After reading the document of Go on the web page
> > https://golang.org/pkg/reflect/#StructOf
> > I see the below statement.
> >
> > "StructOf currently does not generate wrapper methods for embedded
> fields.
> > This limitation may be lifted in a future version."
> >
> > It means that I cannot do it with the current version of Go.
> > Am I correct?
>
> I believe you are correct.
>
> 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Create methods for structs at runtime

2017-06-14 Thread Dat Huynh
Hi,

What I want is to use interfaces to describe services for client side of my 
app.
Then, I implement the services on the server side and allow client side to 
call the services via my pre-defined protocol (e.g HTTP, ...)

In Java, I used the method newProxyInstance( ) of the class 
 java.lang.reflect.Proxy to implement the idea.
However, I don't know how to implement it easily in Go.

Below is what I expect to write in Go in client side.


type MyFooInterface interface {
  Method1() int
  Method2(a int, b int) string
   // any methods
}
func main() {
servicefactory.Init("http://URL/transport;)

var myService MyFooInterface

// pass any interface and obtain a struct instance which implements 
the methods of the interface.
   //In java, I just write myservice = 
ServiceFactory.CreateService(MyFooInterface.class) 

myService = servicefactory.CreateService((*MyFooInterface)(nil)).(
MyFooInterface) 
myService.Method2(10, 20) 
}


Enter code here...

Thank you very much.

Regards,
Dat.





On Wednesday, June 14, 2017 at 4:28:59 PM UTC+10, Lutz Horn wrote:
>
> Hi, 
>
> > Given an interface, how can I create a struct instance with the 
> > methods of the interface at runtime? 
>
> What is your usecase for this? What problem are you trying to solve? 
>
> Lutz 
>
>

-- 
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] Create methods for structs at runtime

2017-06-13 Thread Dat Huynh
Hi all,

I have a question about Go.

Given an interface, how can I create a struct instance with the methods of 
the interface at runtime?

After reading the document of Go on the web page
https://golang.org/pkg/reflect/#StructOf
I see the below statement.

"StructOf currently does not generate wrapper methods for embedded fields. 
This limitation may be lifted in a future version."

It means that I cannot do it with the current version of Go.
Am I correct?

Thank you very much.

Sincerely,
Dat.

-- 
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: IDE for GOLANG

2016-08-02 Thread Dat Huynh
I use vimgo
https://github.com/fatih/vim-go



On Tuesday, August 2, 2016 at 10:25:21 PM UTC+10, kritika...@indiamart.com 
wrote:
>
> Hi, 
> is there IDE for creating a web service in GOLANG by using Revel framework 
>  which follows MVC architecture.
>
> i am using Ubuntu ..
>
>
>
> *Watch our latest TV Commercial #IndiaKiKhoj 
> *
>

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