Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyhede/632bbe180d56b2b4df37 to your computer and use it in GitHub Desktop.
Save tobyhede/632bbe180d56b2b4df37 to your computer and use it in GitHub Desktop.
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