Skip to content

Instantly share code, notes, and snippets.

@tobyhede tobyhede/martini.go
Last active Aug 29, 2015

Embed
What would you like to do?
package main
import (
// "fmt"
"log"
"net/http"
"runtime"
"github.com/go-martini/martini"
"github.com/jmoiron/sqlx"
"github.com/martini-contrib/render"
_ "github.com/lib/pq"
)
type App struct {
Id string
Name string
CallbackUrl string
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
m := martini.Classic()
m.Use(render.Renderer())
m.Get("/", func(r render.Render) {
db, err := sqlx.Open("postgres", "postgres://root:@localhost:1532/twofactor_dev?sslmode=disable")
if err != nil {
log.Fatal(err)
}
apps := []App{}
err = db.Select(&apps, "SELECT id, name, callback_url AS CallbackUrl FROM apps ORDER BY name ASC")
if err != nil {
log.Fatal(err)
}
r.JSON(http.StatusOK, apps)
})
m.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.