コード例 #1
0
ファイル: main.go プロジェクト: postfix/gostbook
func main() {
	var err error
	session, err = mgo.Dial(os.Getenv("DATABASE_URL"))
	if err != nil {
		panic(err)
	}
	database = session.DB("").Name

	//create an index for the username field on the users collection
	if err := session.DB("").C("users").EnsureIndex(mgo.Index{
		Key:    []string{"username"},
		Unique: true,
	}); err != nil {
		panic(err)
	}

	store = sessions.NewCookieStore([]byte(os.Getenv("KEY")))

	router = pat.New()
	router.Add("GET", "/login", handler(loginForm)).Name("login")
	router.Add("POST", "/login", handler(login))

	router.Add("GET", "/register", handler(registerForm)).Name("register")
	router.Add("POST", "/register", handler(register))

	router.Add("GET", "/logout", handler(logout)).Name("logout")

	router.Add("GET", "/", handler(hello)).Name("index")

	router.Add("POST", "/sign", handler(sign)).Name("sign")

	if err = http.ListenAndServe(":"+os.Getenv("PORT"), router); err != nil {
		panic(err)
	}
}
コード例 #2
0
ファイル: gopos.go プロジェクト: Mercor/gopos
func main() {

	flag.Usage = Usage
	flag.Parse()

	// connect to remserial
	destination := *remserialIP + ":" + *remserialPort // "127.0.0.1:23000"
	log.Print("main(): connect to remserial via ", destination)
	cn, err = net.Dial("tcp", destination)
	Test(err, "connecting....")

	// initialize printer object
	myPrinter = new(escpos)

	//set io.Writer Interface to printer
	myPrinter.SetDst(cn)

	// Setup router
	r := pat.New()

	// Handler for POST Requests is printHandler
	r.Post("/print", printHandler)

	// Normal handler
	r.Get("/", handler)

	// Routing all traffic to router
	http.Handle("/", r)

	// "main loop"
	http.ListenAndServe(":8080", nil)

}
コード例 #3
0
ファイル: main.go プロジェクト: minhajuddin/gosnip
func router() *pat.Router {
	r := pat.New()
	r.Get("/new", newHandler)
	r.Get("/show/{id}", showHandler)
	r.Get("/about", aboutHandler)
	r.Post("/create", createHandler)
	r.Post("/compile/{id}", compileHandler)
	r.Get("/", indexHandler)
	http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
	return r
}
コード例 #4
0
ファイル: main.go プロジェクト: bignoyrb/activitylog
func main() {
	var cfgfile *string = flag.String("config", "", "configuration file")
	flag.Parse()

	if *cfgfile == "" {
		flag.Usage()
		os.Exit(1)
	}

	log.Printf("this is activities, revision %s", gitRevision)
	log.Printf("GOMAXPROCS = %d", runtime.GOMAXPROCS(0))
	log.Printf("NumCPU = %d", runtime.NumCPU())

	cfg, err := goconf.ReadConfigFile(*cfgfile)

	// TODO: add error handling
	driver, _ := cfg.GetString("database", "driver")
	dsn, _ := cfg.GetString("database", "dsn")
	auth_key, _ := cfg.GetString("sessions", "authkey")
	enc_key, _ := cfg.GetString("sessions", "enckey")

	db_handle, err := sql.Open(driver, dsn)
	if err != nil {
		log.Fatalf("sql.Open: %v", err)
	}
	defer db_handle.Close()

	db := NewDatabase(db_handle)

	store := sessions.NewCookieStore([]byte(auth_key), []byte(enc_key))

	r := pat.New()

	r.Add("POST", "/auth/try", &TryAuthenticateHandler{Db: db, Store: store})
	r.Add("POST", "/auth/signup", &SignupHandler{Db: db})
	r.Add("POST", "/auth/logout", &LogoutHandler{Store: store})
	r.Add("POST", "/auth", &AuthenticateHandler{Db: db, Store: store})
	r.Add("POST", "/activity/add", &AddActivityHandler{Store: store, Db: db})
	r.Add("GET", "/activity/list/{page:[0-9]+}", &ListActivitiesHandler{Db: db, Store: store})
	r.Add("POST", "/activity/type/add", &AddActivityTypeHandler{Db: db, Store: store})
	r.Add("POST", "/activity/type/edit", &EditActivityTypeHandler{Db: db, Store: store})
	r.Add("POST", "/activity/type/del", &DeleteActivityTypeHandler{Db: db, Store: store})
	r.Add("GET", "/activity/type/list", &ListActivityTypesHandler{Db: db, Store: store})
	r.Add("GET", "/activity/latest", &LatestActivitiesHandler{Db: db, Store: store})
	r.Add("GET", "/", http.FileServer(http.Dir("htdocs")))

	httpsrv := &http.Server{Handler: Logger(r), Addr: ":8000"}
	if err := httpsrv.ListenAndServe(); err != nil {
		log.Fatalf("ListenAndServe: %v", err)
	}
}
コード例 #5
0
ファイル: activities.go プロジェクト: Gehry/activitylog
func main() {
	var cfgfile *string = flag.String("config", "", "configuration file")
	flag.Parse()

	if *cfgfile == "" {
		flag.Usage()
		os.Exit(1)
	}

	cfg, err := goconf.ReadConfigFile(*cfgfile)

	// TODO: add error handling
	driver, _ := cfg.GetString("database", "driver")
	dsn, _ := cfg.GetString("database", "dsn")
	auth_key, _ := cfg.GetString("sessions", "authkey")
	enc_key, _ := cfg.GetString("sessions", "enckey")

	db, err = sql.Open(driver, dsn)
	if err != nil {
		log.Fatalf("sql.Open: %v", err)
	}
	defer db.Close()

	store = sessions.NewCookieStore([]byte(auth_key), []byte(enc_key))

	r := pat.New()

	r.Post("/auth/try", http.HandlerFunc(TryAuthenticate))
	r.Post("/auth/signup", http.HandlerFunc(Signup))
	r.Post("/auth/logout", http.HandlerFunc(Logout))
	r.Post("/auth", http.HandlerFunc(Authenticate))
	r.Post("/activity/add", http.HandlerFunc(AddActivity))
	r.Get("/activity/list/{page:[0-9]+}", http.HandlerFunc(ListActivities))
	r.Post("/activity/type/add", http.HandlerFunc(AddActivityType))
	r.Post("/activity/type/edit", http.HandlerFunc(EditActivityType))
	r.Post("/activity/type/del", http.HandlerFunc(DeleteActivityType))
	r.Get("/activity/type/list", http.HandlerFunc(ListActivityTypes))

	r.Get("/activity/latest", http.HandlerFunc(LatestActivities))
	r.Add("GET", "/", http.FileServer(http.Dir("htdocs")))

	httpsrv := &http.Server{Handler: r, Addr: ":8000"}
	if err := httpsrv.ListenAndServe(); err != nil {
		log.Fatalf("ListenAndServe: %v", err)
	}
}
コード例 #6
0
ファイル: http.go プロジェクト: scotch/sapling-aego
func init() {

	r := pat.New()

	// Auth

	// Default config; shown here for demonstration.
	auth.BaseURL = "/-/auth/"
	auth.LoginURL = "/login"
	auth.LogoutURL = "/-/auth/logout"
	auth.SuccessURL = "/"

	// Register the providers
	auth.Register("appengine_openid", appengine_openid.New())
	auth.Register("password", password.New())

	// API

	// Root
	r.Get("/", index)

	http.Handle("/", r)
}
コード例 #7
0
ファイル: app.go プロジェクト: jbaikge/goci
	base_meta = &Meta{
		CSS: list{
			"bootstrap-superhero.min.css",
			// "bootstrap-responsive.min.css",
			"main.css",
		},
		JS: list{
			"jquery.min.js",
			"jquery-ui.min.js",
			"bootstrap.js",
			"status.js",
			"main.js",
		},
		BaseTitle: "GoCI",
	}
	router        = pat.New()
	status_images [3][]byte
)

func main() {
	//revert to development mode if debug is set
	if env("DEBUG", "") != "" {
		mode = tmplmgr.Development
	}

	//set our compiler mode
	tmplmgr.CompileMode(mode)

	//add blocks to base template
	base_template.Blocks(tmpl_root("*.block"))
	base_template.Call("reverse", reverse)
コード例 #8
0
ファイル: routes.go プロジェクト: tobhahn/gotalk
package gotalk

import (
	"code.google.com/p/gorilla/pat"
	"net/http"
)

var (
	Router *pat.Router = pat.New()
)

func init() {
	Router.Get("/compile", compile)
	Router.Get("/slides/{id}", slides)
	Router.Add("GET", "/css", http.FileServer(http.Dir("../assets")))
	Router.Add("GET", "/js", http.FileServer(http.Dir("../assets")))
	Router.Add("GET", "/img", http.FileServer(http.Dir("../assets")))
	Router.Add("GET", "/", http.RedirectHandler("/slides/title", http.StatusFound))
}