go get -u github.com/bdwilliams/go-jsonify/jsonify
go: downloading github.com/bdwilliams/go-jsonify v0.0.0-20141020182238-48749139e742
go get: added github.com/bdwilliams/go-jsonify v0.0.0-20141020182238-48749139e742
jsonify.Jsonify(sqlResultSet)
package main
import (
"database/sql"
"github.com/bdwilliams/go-jsonify/jsonify"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
)
func main() {
r := gin.Default()
r.GET("/selectSysTable", func(c *gin.Context) {
db, err := sql.Open("mysql", "id:pass@tcp(ip:port)/dbName")
if err != nil {
panic(err)
}
defer db.Close()
rows, err := db.Query("SELECT variable, value, set_time FROM sys_config WHERE variable = 'statement_truncate_len'")
c.JSON(200, jsonify.Jsonify(rows))
})
r.Run()
}
생각보다 API 서버 구축이 수월할 듯 보인다.