Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function() used as value compile error

Tags:

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?

like image 653
sergserg Avatar asked Dec 21 '22 05:12

sergserg


1 Answers

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
like image 75
zzzz Avatar answered Jan 09 '23 11:01

zzzz