2016. december 4., vasárnap 15:14:44 UTC+1 időpontban Neng Kong a következőt írta: > > I replace > demo := HandlerFunc{} > to > var demo HandlerFunc > > also can not > [john@localhost gweb]$ go run inspiration_by_golang_http.go > panic: runtime error: invalid memory address or nil pointer dereference > [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x401035] > > goroutine 1 [running]: > panic(0x47a9a0, 0xc42000a090) > /home/john/go/src/runtime/panic.go:500 +0x1a1 > main.HandlerFunc.Call(0x0, 0x1, 0x2) > /home/john/gweb/inspiration_by_golang_http.go:14 +0x35 > main.main() > /home/john/gweb/inspiration_by_golang_http.go:20 +0x40 > exit status 2 > > > Maube i can not imitate it > >> >>> Please start with tour.golang.org, learn the definition of pointer! In Go everything is initialized with it's type's zereo value - for an function (HandlerFunc is a function), it is nil. As the runtime kindly says, you try to dereference it by calling it, that results in panic.
So, as I've said, try demo := HandlerFunc(func(x,y int) { fmt.Println("Called", x, y) }) -- 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.