HandlerFunc is not a struct. You probably wanted to do this (line 17): demo := HandlerFunc(Add)
On 04/12/16 15:02, Neng Kong wrote: > i see this: > | > |type HandlerFuncfunc(ResponseWriter,*Request)// ServeHTTP calls f(w, > r).func (f HandlerFunc)ServeHTTP(w ResponseWriter,r *Request){ f(w,r)}| > | > > and i imitate it, but can't compile: > | > package main > > import "fmt" > > type Handler interface { > Call(x, y int) > } > func Add(x, y int) { > fmt.Println(x+y) > } > type HandlerFunc func(x, y int) > > func (f HandlerFunc) Call(x, y int) { > f(x, y) > } > func main() { > demo := HandlerFunc{} > var i Handler > i = demo > i.Call(1, 2) > } > > [john@localhost gweb]$ go run demo.go > # command-line-arguments > ./inspiration_by_golang_http.go:17: invalid type for composite > literal: HandlerFunc > > | > > > i do not understand it, this is way ? > -- > 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+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.