FAQ
I want to create a client library which reads a list of functions from a
service and exposes those functions to the caller.

Is it possible to create methods during runtime? E.g.:

type Foo struct {}

func main() {

// Create new method Bar on Foo here at runtime

           reflect.MakeMethod("Foo", "Bar", func(){} )

f := Foo{}

f.Bar()

}


The other way I'm thinking of doing this is by static code generation.
  Looks like that's how Google is doing it<https://code.google.com/p/google-api-go-client/>,
so that's probably the way to go, right?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rob Pike at Jun 25, 2013 at 1:19 pm
    There is no way to add a method to a type at run time. The method set
    is a compile-time concept.

    -rob

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 25, '13 at 6:32a
activeJun 25, '13 at 1:19p
posts2
users2
websitegolang.org

2 users in discussion

Rob Pike: 1 post Samxnguyen: 1 post

People

Translate

site design / logo © 2022 Grokbase