Re: [go-nuts] Re: pass interface
I think what the OP wants is: type A interface{} type B interface{} ... PrintInterface(A) Meaning they want to pass the interface definition to some method. At least that’s what I am guessing. > On Dec 9, 2018, at 9:22 PM, Space A. wrote: > > reflect/* is a bit tricky. Use pointer to get interface itself. > > package main > > import ( > "fmt" > "reflect" > ) > > func main() { > test := interface{}("test") > printInterfaceValue(test) > } > > func printInterfaceValue(i interface{}) { > switch testing := i.(type) { > case interface{}: > fmt.Println("is interface, with value:", testing) > case string: > fmt.Println("is not interface") > } > > fmt.Println("reflect.Type is", reflect.TypeOf().Elem()) > } > > Output: > is interface, with value: test > reflect.Type is interface {} > > > > > > понедельник, 10 декабря 2018 г., 5:05:12 UTC+3 пользователь Robert Engels > написал: >> >> I mean reflect.Type not a type that is an interface. >> >>> On Dec 9, 2018, at 6:53 PM, Space A. wrote: >>> >>> Of course. When you "pass a value whose type implements the interface" as >>> an interface argument to a function, you in fact pass an interface. >>> >>> >>> воскресенье, 9 декабря 2018 г., 23:23:41 UTC+3 пользователь Mark Volkmann >>> написал: Is it possible to pass an interface to a function in Go? I don’t want to pass a value whose type implements the interface, I want to pass the interface. -- R. Mark Volkmann Object Computing, Inc. >>> >>> -- >>> 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. -- 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: pass interface
reflect/* is a bit tricky. Use pointer to get interface itself. package main import ( "fmt" "reflect" ) func main() { test := interface{}("test") printInterfaceValue(test) } func printInterfaceValue(i interface{}) { switch testing := i.(type) { case interface{}: fmt.Println("is interface, with value:", testing) case string: fmt.Println("is not interface") } fmt.Println("reflect.Type is", reflect.TypeOf().Elem()) } Output: is interface, with value: test reflect.Type is interface {} понедельник, 10 декабря 2018 г., 5:05:12 UTC+3 пользователь Robert Engels написал: > > I mean reflect.Type not a type that is an interface. > > On Dec 9, 2018, at 6:53 PM, Space A. > > wrote: > > Of course. When you "pass a value whose type implements the interface" as > an interface argument to a function, you in fact pass an *interface*. > > > воскресенье, 9 декабря 2018 г., 23:23:41 UTC+3 пользователь Mark Volkmann > написал: >> >> Is it possible to pass an interface to a function in Go? I don’t want to >> pass a value whose type implements the interface, I want to pass the >> interface. >> >> -- >> R. Mark Volkmann >> Object Computing, Inc. >> > -- > 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] net/http why drop the leading dot of cookie.Domain
I know this is an old question but it hasn't changed and I believe this was for compatibility with RFC 2109 (which is obsoleted by RFC 6265). Section 4.2.2 states: Domain=domain Optional. The Domain attribute specifies the domain for which the cookie is valid. An explicitly specified domain must always start with a dot. On Sunday, 8 February 2015 23:19:45 UTC-5, Nigel Tao wrote: > > On Tue, Jan 27, 2015 at 1:44 AM, > > wrote: > > > https://github.com/golang/go/blob/master/src/net/http/cookie.go#L144-L151 > > It's been a while since I've looked at this, but the relevant spec for > HTTP Cookies is RFC 6265, and sections 4 and 5 deal with servers and > clients. > > Section 4.1.2.3. The Domain Attribute says that: > Note that a leading %x2E ("."), if present, is ignored even though > that character is not permitted. > > Section 5.2.3. The Domain Attribute says that: > If the first character of the attribute-value string is %x2E ("."): > Let cookie-domain be the attribute-value without the leading %x2E > (".") character. > -- 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: pass interface
I mean reflect.Type not a type that is an interface. > On Dec 9, 2018, at 6:53 PM, Space A. wrote: > > Of course. When you "pass a value whose type implements the interface" as an > interface argument to a function, you in fact pass an interface. > > > воскресенье, 9 декабря 2018 г., 23:23:41 UTC+3 пользователь Mark Volkmann > написал: >> >> Is it possible to pass an interface to a function in Go? I don’t want to >> pass a value whose type implements the interface, I want to pass the >> interface. >> >> -- >> R. Mark Volkmann >> Object Computing, Inc. > > -- > 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. -- 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: pass interface
Of course. When you "pass a value whose type implements the interface" as an interface argument to a function, you in fact pass an *interface*. воскресенье, 9 декабря 2018 г., 23:23:41 UTC+3 пользователь Mark Volkmann написал: > > Is it possible to pass an interface to a function in Go? I don’t want to > pass a value whose type implements the interface, I want to pass the > interface. > > -- > R. Mark Volkmann > Object Computing, Inc. > -- 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: [SUSPECTED SPAM][go-nuts] pass interface
If you want the interface to be interpreted as an interface value and your parameter type is interface{}, you can pass a pointer to the interface value and then work with that. On Sun, 2018-12-09 at 14:23 -0600, Mark Volkmann wrote: > Is it possible to pass an interface to a function in Go? I don’t want > to > pass a value whose type implements the interface, I want to pass the > interface. > > -- > R. Mark Volkmann > Object Computing, Inc. > -- 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] pass interface
Just declare the parameter as type Type and then in the method check if it is an interface. The caller uses the interface type. > On Dec 9, 2018, at 2:43 PM, Jan Mercl <0xj...@gmail.com> wrote: > > On Sun, Dec 9, 2018 at 9:23 PM Mark Volkmann > wrote: > > > Is it possible to pass an interface to a function in Go? I don’t want to > > pass a value whose type implements the interface, I want to pass the > > interface. > > I think the question is not clear enough. Could you please provide an example > of what you would like to write, what you tried and where the compiler error > occurs, if any? > > -- > -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. > 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] pass interface
On Sun, Dec 9, 2018 at 9:23 PM Mark Volkmann wrote: > Is it possible to pass an interface to a function in Go? I don’t want to pass a value whose type implements the interface, I want to pass the interface. I think the question is not clear enough. Could you please provide an example of what you would like to write, what you tried and where the compiler error occurs, if any? -- -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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] pass interface
Is it possible to pass an interface to a function in Go? I don’t want to pass a value whose type implements the interface, I want to pass the interface. -- R. Mark Volkmann Object Computing, Inc. -- 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] How to add a new operator
This is how I do it (and go/src/cmd/compile/internal/gc) , but I still get errors "expected operand" . I would like a little more details from those who have already done this. воскресенье, 9 декабря 2018 г., 19:48:58 UTC+3 пользователь Aram Hăvărneanu написал: > > Start with go/src/cmd/compile/internal/syntax and go from there. > > -- > Aram Hăvărneanu > -- 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] \n new line feed
In fmt.Println function, \n is used. Is \n safe to use in different platforms? -- 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] How to add a new operator
Start with go/src/cmd/compile/internal/syntax and go from there. -- Aram Hăvărneanu -- 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] How to add a new operator
What do you mean by "-wgr" воскресенье, 9 декабря 2018 г., 18:31:11 UTC+3 пользователь Wagner Riffel написал: > > define operator. > -wgr > > On Sun, Dec 9, 2018, 10:27 AM Claygod > > wrote: > >> Hello, >> >> I want to try adding a new operator. Tell me, in which packages you need >> to edit the code? >> Maybe once a similar question was discussed, then please give a link >> >> -- >> 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] How to add a new operator
define operator. -wgr On Sun, Dec 9, 2018, 10:27 AM Claygod wrote: > Hello, > > I want to try adding a new operator. Tell me, in which packages you need > to edit the code? > Maybe once a similar question was discussed, then please give a link > > -- > 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. > -- 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] convert *byte to []byte
[0] -- 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] convert *byte to []byte
Thanks, C.GoBytes Works well. Another question. How to convert []byte to *byte backward? Ian Lance Taylor 于2018年12月3日周一 下午1:01写道: > On Sat, Dec 1, 2018 at 9:39 AM wrote: > > > > I am using swig wrap a c++ module , the generated go code is like this: > > > > type MediaFrame interface { > > GetLength() uint > > GetData() (*byte) > > } > > > > I want to convert the *byte to []byte, How to do this? > > One approach is > > s := > (*[1<<30]byte)(unsafe.Pointer(mf.GetData())[:mf.GetLength():mf.GetLength()] > > 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.
[go-nuts] How to add a new operator
Hello, I want to try adding a new operator. Tell me, in which packages you need to edit the code? Maybe once a similar question was discussed, then please give a link -- 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.