mirror of
https://github.com/labstack/echo.git
synced 2024-12-26 20:54:00 +02:00
c60f207279
Signed-off-by: Vishal Rana <vr@labstack.com>
32 lines
591 B
Go
32 lines
591 B
Go
package main
|
|
|
|
import (
|
|
"math/rand"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/labstack/echo"
|
|
)
|
|
|
|
func main() {
|
|
// Setup
|
|
e := echo.New()
|
|
e.ServeDir("/", "public")
|
|
|
|
e.Get("/jsonp", func(c *echo.Context) error {
|
|
callback := c.Query("callback")
|
|
var content struct {
|
|
Response string `json:"response"`
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Random int `json:"random"`
|
|
}
|
|
content.Response = "Sent via JSONP"
|
|
content.Timestamp = time.Now().UTC()
|
|
content.Random = rand.Intn(1000)
|
|
return c.JSONP(http.StatusOK, callback, &content)
|
|
})
|
|
|
|
// Start server
|
|
e.Run(":3999")
|
|
}
|