samedi 23 mai 2015

Golang - Provide return after "if" statement when using framework

It give error missing return at end of function. I've tried add return nil, return "", and several others but none works.

package main

import (
    "http://ift.tt/1em6k0b"
    "http://ift.tt/19F86Xu"
    "net/http"
)

func main() {
    e := echo.New()

    e.Get("/", func(c *echo.Context, w http.ResponseWriter, r *http.Request) *echo.HTTPError {

        deviceType := goDevice.GetType(r)

        if deviceType == "Mobile" {
            return c.String(http.StatusOK, "Mobile!")
        } else if deviceType == "Web" {
            return c.String(http.StatusOK, "Desktop!")
        } else if deviceType == "Tab" {
            return c.String(http.StatusOK, "Tablet!")
        }

    })

    e.Run(":4444")
}

This one quite different that other case just like in here.

Without framework, it works fine.

Aucun commentaire:

Enregistrer un commentaire