I'm trying to learn Golang. I decided to try to write a simple server

In other words, I’ trying to run a simple exemple from Internet. Here is a code:
package main

import (
“fmt”
“log”
“net/http”
)

func foohandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, “Hello world”)
}

func main() {
http.HandlerFunc("/", foohandler)
log.Println(“Listenning…”)
http.ListenAndServe(":3000", nil)
}

When I am running this code I am getting = >

command-line-arguments

./comeon.go:14: too many arguments to conversion to http.HandlerFunc: http.HandlerFunc("/", foohandler)

What do I wrong?
My Golang version is 1.8

1 Like

Hi, change http.HandlerFunc to http.HandleFunc

5 Likes

OMG! Thank you very much!

2 Likes

Thought that you might like to know the difference, HandleFunc(path, funcHandler) registers a path with default serve mux or specific serve mux if used on an instance variable.

HandlerFunc(funcDesired) returns a function that conforms to the Handler interface given a function that doesn’t. It’s a way to use generic functions as handlers.

Here’s more information in the docs: http://godoc.org/net/http

5 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.