package routes import ( "github.com/labstack/echo" "github.com/dgrijalva/jwt-go" "time" "net/http" ) func Login(c echo.Context) error { username := c.FormValue("username") password := c.FormValue("password") if username == "jon" && password == "shhh!" { // Create token token := jwt.New(jwt.SigningMethodHS256) // Set claims claims := token.Claims.(jwt.MapClaims) claims["name"] = "Jon Snow" claims["admin"] = true claims["exp"] = time.Now().Add(time.Hour * 72).Unix() // Generate encoded token and send it as response. t, err := token.SignedString([]byte("secret")) if err != nil { return err } return c.JSON(http.StatusOK, map[string]string{ "token": t, }) } return echo.ErrUnauthorized }