Last active
August 29, 2015 14:01
-
-
Save tobyhede/632bbe180d56b2b4df37 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 ( | |
// "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