当前位置: 首页>>代码示例>>Golang>>正文


Golang goji.Handle函数代码示例

本文整理汇总了Golang中github.com/zenazn/goji.Handle函数的典型用法代码示例。如果您正苦于以下问题:Golang Handle函数的具体用法?Golang Handle怎么用?Golang Handle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Handle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	goji.Get("/", IndexHandler) // Doesn't need CSRF protection (no POST/PUT/DELETE actions).

	signup := web.New()
	goji.Handle("/signup/*", signup)
	// But our signup forms do, so we add nosurf to their middleware stack (only).
	signup.Use(nosurf.NewPure)
	signup.Get("/signup/new", ShowSignupForm)
	signup.Post("/signup/submit", SubmitSignupForm)

	admin := web.New()
	// A more advanced example: we enforce secure cookies (HTTPS only),
	// set a domain and keep the expiry time low.
	a := nosurf.New(admin)
	a.SetBaseCookie(http.Cookie{
		Name:     "csrf_token",
		Domain:   "localhost",
		Path:     "/admin",
		MaxAge:   3600 * 4,
		HttpOnly: true,
		Secure:   true,
	})

	// Our /admin/* routes now have CSRF protection.
	goji.Handle("/admin/*", a)

	goji.Serve()
}
开发者ID:marswang,项目名称:nosurf,代码行数:28,代码来源:goji.go

示例2: static

func static() {
	g.Get("/", http.FileServer(http.Dir(config.C.PublicPath)))

	static := web.New()
	static.Get("/styles/*", http.StripPrefix("/styles/", http.FileServer(http.Dir(config.C.PublicPath+"/styles"))))
	static.Get("/scripts/*", http.StripPrefix("/scripts/", http.FileServer(http.Dir(config.C.PublicPath+"/scripts"))))
	static.Get("/images/*", http.FileServer(http.Dir(config.C.PublicPath+"/images")))
	static.Get("/robots.txt", http.FileServer(http.Dir(config.C.PublicPath)))

	g.Handle("/scripts/*", static)
	g.Handle("/styles/*", static)
	g.Handle("/images/*", static)
}
开发者ID:jancarloviray,项目名称:go-angular-proj,代码行数:13,代码来源:routes.go

示例3: main

func main() {
	admin := web.New()
	admin.Use(middleware.SubRouter)
	admin.Post("/login", login)
	goji.Handle("/admin/*", admin)

	dashboard := web.New()
	dashboard.Use(auth)
	dashboard.Use(middleware.SubRouter)
	dashboard.Get("/json", sampleJsonHandle)
	goji.Handle("/dashboard/*", dashboard)

	goji.Use(middleware.Logger)
	goji.Serve()
}
开发者ID:myohei,项目名称:sample-goji-server,代码行数:15,代码来源:main.go

示例4: main

func main() {

	// Handle debugging
	if debug || os.Getenv("DEBUG") == "true" {
		debug = true // Just in case
		debugOut = log.New(os.Stdout, "[DEBUG]", log.Lshortfile)
	}

	debugOut.Printf("Pre-Config:\n%+v\n", GlobalConfig.Map())

	// Load Configs
	if configFolder != "" {
		loadConfigs(configFolder)
	} else if cf := os.Getenv("CONFIGFOLDER"); cf != "" {
		loadConfigs(cf)
	}

	debugOut.Printf("Post-Config\n%+v\n", GlobalConfig.Map())

	// Setup AWS stuff
	initAWS()

	// Goji!!!
	if GlobalConfig.IsNotNull("serverHeader") {
		headerString := GlobalConfig.Get("serverHeader")
		if headerString != "yes" {
			FULLVERSION = headerString
		}
		goji.Use(ServerHeader)
	}

	goji.Get("/", http.RedirectHandler(GlobalConfig.Get("formURL"), 301))
	goji.Get("/health", healthHandler)
	goji.Post("/upload", uploadHandler)
	goji.Get("/upload", http.RedirectHandler(GlobalConfig.Get("getRedirect"), 301))

	// Allow handling of static content for webform, thank you page, etc.
	if GlobalConfig.IsNotNull("staticPath") && GlobalConfig.IsNotNull("staticURL") {
		debugOut.Printf("Static handling of '%s' mapped to '%s'\n", GlobalConfig.Get("staticURL"), GlobalConfig.Get("staticPath"))
		goji.Handle(GlobalConfig.Get("staticURL"),
			http.StripPrefix(strings.TrimRight(GlobalConfig.Get("staticURL"), "*"),
				http.FileServer(http.Dir(GlobalConfig.Get("staticPath")))))
	}

	goji.Handle("/*", defaultHandler)

	goji.Serve()
}
开发者ID:cognusion,项目名称:post2s3,代码行数:48,代码来源:main.go

示例5: main

func main() {
	// setup
	models.Migrate()
	pongo2.DefaultSet.SetBaseDirectory("view")

	api := web.New()
	goji.Handle("/api/*", api)
	api.Use(middleware.SubRouter)
	api.Get("/entry/:id", controller.ShowArticle)
	api.Get("/album/:id", controller.ShowAlbum)

	goji.Handle("/", http.FileServer(http.Dir("./static")))
	goji.Handle(regexp.MustCompile("^/(css|js)"), http.FileServer(http.Dir("./static")))

	goji.Serve()
}
开发者ID:tkzwtks,项目名称:go_blog,代码行数:16,代码来源:main.go

示例6: NewRouter

func NewRouter(b *backend.Backend) {
	router = Router{
		Backend: b,
	}

	goji.Get("/ping", router.Ping)
	api := web.New()
	goji.Handle("/v1/*", api)

	api.Get("/overview", router.Overview)

	api.Get("/accounts", router.ShowAccount)
	api.Get("/accounts/:account_id", router.ShowAccount)
	api.Get("/categories", router.ShowCategory)
	api.Get("/categories/:category_id", router.ShowCategory)

	api.Post("/transaction", router.NewTransaction)
	api.Post("/account", router.NewAccount)
	api.Post("/category", router.NewCategory)

	api.Put("/transaction/:transaction_id", router.UpdateTransaction)
	api.Put("/account/:account_id", router.UpdateAccount)
	api.Put("/category/:category_id", router.UpdateCategory)

	api.Delete("/transaction/:transaction_id", router.DeleteTransaction)
	api.Delete("/account/:account_id", router.DeleteAccount)
	api.Delete("/category/:category_id", router.DeleteCategory)

	api.Use(goji.DefaultMux.Router)
	api.Use(middleware.SubRouter)
}
开发者ID:benspotatoes,项目名称:parsimonious-tempest,代码行数:31,代码来源:api.go

示例7: main

func main() {
	goji.Get("/hello/:name", hello)

	staticPattern := regexp.MustCompile("^/(css|js)")
	goji.Handle(staticPattern, http.FileServer(http.Dir("./static")))
	goji.Serve()
}
开发者ID:MacoTasu,项目名称:goji-and-go-xslate-sample,代码行数:7,代码来源:server.go

示例8: StartWebServer

func StartWebServer(bind, auth string) error {
	err := loadTemplates()
	if err != nil {
		return err
	}

	if auth != "" {
		authParts := strings.Split(auth, ":")
		goji.Use(httpauth.SimpleBasicAuth(authParts[0], authParts[1]))
	}

	goji.Get("/", homeRoute)
	goji.Get("/status", statusRoute)
	goji.Get("/robots.txt", robotsRoute)
	goji.Get("/setEnabled", setEnabledRoute)
	goji.Handle("/config", configRoute)

	listener, err := net.Listen("tcp", bind)
	if err != nil {
		return err
	}

	goji.ServeListener(listener)
	return nil
}
开发者ID:topscore,项目名称:sup,代码行数:25,代码来源:webserver.go

示例9: main

func main() {
	awsSession := session.New()
	awsSession.Config.WithRegion(os.Getenv("AWS_REGION"))

	tree = &dynamotree.Tree{
		TableName: "hstore-example-shortlinks",
		DB:        dynamodb.New(awsSession),
	}
	err := tree.CreateTable()
	if err != nil {
		log.Fatalf("hstore: %s", err)
	}

	goji.Get("/:link", ServeLink)
	goji.Post("/signup", CreateAccount)

	authMux := web.New()
	authMux.Use(RequireAccount)
	authMux.Post("/", CreateLink)
	authMux.Get("/", ListLinks)
	authMux.Delete("/:link", DeleteLink) // TODO(ross): this doesn't work (!)
	goji.Handle("/", authMux)

	goji.Serve()
}
开发者ID:crewjam,项目名称:dynamotree,代码行数:25,代码来源:shortlink.go

示例10: Start

func Start(conn *CGRConnector, user, pass string) {
	connector = conn
	username = user
	password = pass
	templates = template.Must(template.ParseGlob("templates/*.tmpl"))

	rpc.Register(conn)

	goji.Get(LOGIN_PATH, loginGet)
	goji.Post(LOGIN_PATH, loginPost)

	goji.Get("/app/*", http.FileServer(http.Dir("./static")))

	auth := web.New()
	goji.Handle("/*", auth)
	auth.Use(SessionAuth)
	auth.Handle("/ws", websocket.Handler(func(ws *websocket.Conn) {
		jsonrpc.ServeConn(ws)
	}))
	auth.Post("/import/", importPost)
	auth.Post("/exportcdrs/", exportCdrsPost)
	auth.Post("/exporttpcsv/", exportTpToCsvPost)
	auth.Get("/accounts/logout", logoutGet)
	auth.Get("/", http.RedirectHandler("/app/", 301))
}
开发者ID:MartinChenjq,项目名称:cgradmin,代码行数:25,代码来源:cgradmin.go

示例11: SetupRoutes

func SetupRoutes() {
	for _, route := range routes {
		for _, method := range route.methods {
			switch method {
			case "GET":
				goji.Get(route.url, route.handler)
				break
			case "POST":
				goji.Post(route.url, route.handler)
				break
			case "PUT":
				goji.Put(route.url, route.handler)
				break
			case "PATCH":
				goji.Patch(route.url, route.handler)
				break
			case "DELETE":
				goji.Delete(route.url, route.handler)
				break
			default:
				goji.Handle(route.url, route.handler)
			}
		}
	}
}
开发者ID:shonenada-archives,项目名称:heron,代码行数:25,代码来源:urls.go

示例12: main

func main() {
	log.Println("Starting go-sig/web")

	if path := os.Getenv("IMG_PATH"); path != "" {
		imageRoot = path
	}
	log.Printf("Using image root: %s", imageRoot)
	if _, err := os.Stat(imageRoot); os.IsNotExist(err) {
		os.MkdirAll(imageRoot, 0750)
	}

	if procs := os.Getenv("PROCS"); procs != "" {
		if p, err := strconv.Atoi(procs); err != nil {
			runtime.GOMAXPROCS(p)
		}
	}

	if key := os.Getenv("AES_KEY"); key != "" {
		util.AES_KEY = []byte(key)
	}

	disableLogging := os.Getenv("DISABLE_LOGGING")
	if disableLogging == "1" || disableLogging == "true" {
		log.SetOutput(new(NullWriter))
	}

	// Routes
	log.Println("Mapping routes...")
	goji.Get("/", index)

	// Setup static files
	static := web.New()
	static.Get("/assets/*", http.StripPrefix("/assets/", http.FileServer(http.Dir(publicPath))))
	http.Handle("/assets/", static)

	profile := os.Getenv("ENABLE_DEBUG")
	if profile == "1" || profile == "true" {
		log.Println("Mapping debug routes...")
		goji.Handle("/debug/pprof/", pprof.Index)
		goji.Handle("/debug/pprof/cmdline", pprof.Cmdline)
		goji.Handle("/debug/pprof/profile", pprof.Profile)
		goji.Handle("/debug/pprof/symbol", pprof.Symbol)
		goji.Handle("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
		goji.Handle("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
		goji.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
		goji.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
	}

	// Generators
	log.Println("Registering generators...")
	registerGenerator(new(rs3.BoxGoalGenerator))
	registerGenerator(new(multi.MultiGoalGenerator))
	//registerGenerator(new(rs3.ExampleGenerator))

	// Serve
	goji.Serve()
}
开发者ID:cubeee,项目名称:go-sig,代码行数:57,代码来源:web.go

示例13: New

//New intialises tweet routes
func New() {
	fmt.Println("Setup Tweets")
	tweets := web.New()
	goji.Handle("/tweets/*", tweets)

	tweets.Use(middleware.SubRouter)
	tweets.Use(conneg)

	tweets.Get("/", helloTweet)
	tweets.Get("/:id", getTweetByID)

}
开发者ID:jchannon,项目名称:FarGo,代码行数:13,代码来源:tweetmodule.go

示例14: main

func main() {
	godotenv.Load()

	access := Access{api.New(os.Getenv("DATABASE_URL"))}
	defer access.Close()

	goji.Post("/post", access.log)

	goji.Handle("/*", http.FileServer(http.Dir("./static")))

	goji.Serve()
}
开发者ID:Flatbook,项目名称:electron_crash_reporter,代码行数:12,代码来源:web.go

示例15: main

func main() {
	// Add routes to the global handler
	goji.Get("/", Root)
	// Fully backwards compatible with net/http's Handlers
	goji.Get("/greets", http.RedirectHandler("/", 301))
	// Use your favorite HTTP verbs
	goji.Post("/greets", NewGreet)
	// Use Sinatra-style patterns in your URLs
	goji.Get("/users/:name", GetUser)
	// Goji also supports regular expressions with named capture groups.
	goji.Get(regexp.MustCompile(`^/greets/(?P<id>\d+)$`), GetGreet)

	// Middleware can be used to inject behavior into your app. The
	// middleware for this application are defined in middleware.go, but you
	// can put them wherever you like.
	goji.Use(PlainText)

	// If the patterns ends with "/*", the path is treated as a prefix, and
	// can be used to implement sub-routes.
	admin := web.New()
	goji.Handle("/admin/*", admin)

	// The standard SubRouter middleware helps make writing sub-routers
	// easy. Ordinarily, Goji does not manipulate the request's URL.Path,
	// meaning you'd have to repeat "/admin/" in each of the following
	// routes. This middleware allows you to cut down on the repetition by
	// eliminating the shared, already-matched prefix.
	admin.Use(middleware.SubRouter)
	// You can also easily attach extra middleware to sub-routers that are
	// not present on the parent router. This one, for instance, presents a
	// password prompt to users of the admin endpoints.
	admin.Use(SuperSecure)

	admin.Get("/", AdminRoot)
	admin.Get("/finances", AdminFinances)

	// Goji's routing, like Sinatra's, is exact: no effort is made to
	// normalize trailing slashes.
	goji.Get("/admin", http.RedirectHandler("/admin/", 301))

	// Use a custom 404 handler
	goji.NotFound(NotFound)

	// Sometimes requests take a long time.
	goji.Get("/waitforit", WaitForIt)

	// Call Serve() at the bottom of your main() function, and it'll take
	// care of everything else for you, including binding to a socket (with
	// automatic support for systemd and Einhorn) and supporting graceful
	// shutdown on SIGINT. Serve() is appropriate for both development and
	// production.
	goji.Serve()
}
开发者ID:FihlaTV,项目名称:bridge-server,代码行数:53,代码来源:main.go


注:本文中的github.com/zenazn/goji.Handle函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。