Go – function() used as value compile error

go

I'm trying to learn the basics of Go by tweaking examples as I go along the tutorial located here:

http://tour.golang.org/#9


Here's a small function I wrote that just turns ever character to all caps.

package main

import (
    "fmt"
    "strings"
)

func capitalize(name string) {
    name = strings.ToTitle(name)
    return
}

func main() {
    test := "Sergio"    
    fmt.Println(capitalize(test))
}

I'm getting this exception:

prog.go:15: capitalize(test) used as value

Any glaring mistakes?

Best Answer

You are missing the return type for capitalize():

package main

import (
        "fmt"
        "strings"
)

func capitalize(name string) string {
        return strings.ToTitle(name)
}

func main() {
        test := "Sergio"
        fmt.Println(capitalize(test))
}

Playground


Output:

SERGIO