Created
April 19, 2016 16:33
-
-
Save mattn/af4afc6b3b6584e72c0dd43df87b83e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"time" | |
"github.com/labstack/echo" | |
mw "github.com/labstack/echo/middleware" | |
) | |
// 現在時刻を取得 | |
func getNow() string { | |
var loc, _ = time.LoadLocation("Asia/Tokyo") | |
var now = time.Now().In(loc).Format("2006-01-02 15:04:05") | |
return now | |
} | |
// Handler | |
func hello(c *echo.Context) error { | |
var content struct { | |
Response string `json:"response"` | |
Timestamp string `json:"timestamp"` | |
} | |
content.Response = "Hello, World!" | |
content.Timestamp = getNow() | |
return c.JSON(http.StatusOK, &content) | |
} | |
func main() { | |
// Echo instance | |
e := echo.New() | |
// Middleware | |
e.Use(mw.Logger()) | |
e.Use(mw.Recover()) | |
// Routes | |
e.Get("/", hello) | |
// Start server | |
e.Run(":1323") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"time" | |
"github.com/labstack/echo" | |
mw "github.com/labstack/echo/middleware" | |
) | |
var loc *time.Location | |
func init() { | |
loc, _ = time.LoadLocation("Asia/Tokyo") | |
} | |
// 現在時刻を取得 | |
func getNow() string { | |
var now = time.Now().In(loc).Format("2006-01-02 15:04:05") | |
return now | |
} | |
// Handler | |
func hello(c *echo.Context) error { | |
var content struct { | |
Response string `json:"response"` | |
Timestamp string `json:"timestamp"` | |
} | |
content.Response = "Hello, World!" | |
content.Timestamp = getNow() | |
return c.JSON(http.StatusOK, &content) | |
} | |
func main() { | |
// Echo instance | |
e := echo.New() | |
// Middleware | |
e.Use(mw.Logger()) | |
e.Use(mw.Recover()) | |
// Routes | |
e.Get("/", hello) | |
// Start server | |
e.Run(":1323") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
benchmark
time1
time2