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


Golang web.Mux类代码示例

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


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

示例1: route

func route(m *web.Mux) {
	// Add routes to the global handler
	setGetHandler(m, "/", Root)
	// Use Sinatra-style patterns in your URLs
	setGetHandler(m, "/novel/:ncode", responseCache(getNovelInfo))
	setGetHandler(m, "/novel_content/:ncode/:sublist_id", responseCache(getNovelContent))

	// 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.
	m.Use(Json)
}
开发者ID:twainy,项目名称:tiroler,代码行数:12,代码来源:server.go

示例2: router

func router(m *web.Mux) http.Handler {
	m.Get("/", UserRoot)
	user := web.New()
	goji.Handle("/user/*", user)
	user.Use(middleware.SubRouter)
	user.Get("/", UserIndex)
	user.Get("/new", UserNew)
	user.Post("/new", UserCreate)
	user.Get("/edit/:id", UserEdit)
	user.Post("/update/:id", UserUpdate)
	user.Get("/delete/:id", UserDelete)
	return m
}
开发者ID:woremacx,项目名称:go-crud-sample,代码行数:13,代码来源:route.go

示例3: Route

// Sets up the routes
func (api *Api) Route(m *web.Mux) {

	m.Get("/:topic/:username", api.NextMessage)
	m.Post("/:topic/:username", api.SubscribeToTopic)
	m.Delete("/:topic/:username", api.UnsubscribeFromTopic)

	m.Post("/:topic", api.PublishMessage)

}
开发者ID:mdevilliers,项目名称:take-home,代码行数:10,代码来源:api.go

示例4: getHandler

// attach r.Handler and r.Method to the correct verb function
func getHandler(wm *web.Mux, r *Route) error {
	switch strings.ToLower(r.Method) {
	case "get":
		wm.Get(r.Pattern, r.Handler)
	case "post":
		wm.Post(r.Pattern, r.Handler)
	case "put":
		wm.Put(r.Pattern, r.Handler)
	case "patch":
		wm.Patch(r.Pattern, r.Handler)
	case "delete":
		wm.Delete(r.Pattern, r.Handler)
	default:
		return errors.New("unsupported method: " + r.Method)
	}

	return nil
}
开发者ID:grounded042,项目名称:capacious,代码行数:19,代码来源:core.go

示例5: SetupMainServer

// SetupMainServer allocates a listener socket and starts a web server with graceful restart
// on the specified IP address and port. The ipPort has the format "ip_address:port" or
// ":port" for 0.0.0.0/port.
func SetupMainServer(ipPort string, mux *web.Mux) {
	listener, err := net.Listen("tcp4", ipPort)
	if err != nil {
		FatalError(err.Error())
	}

	// Install our handler at the root of the standard net/http default mux.
	// This allows packages like expvar to continue working as expected.
	mux.Compile()
	http.Handle("/", mux)

	graceful.HandleSignals()
	graceful.PreHook(func() { log15.Warn("Gracefully stopping on signal") })
	graceful.PostHook(func() { log.Printf("Gracefully stopped") })

	err = graceful.Serve(listener, http.DefaultServeMux)
	if err != nil {
		FatalError(err.Error())
	}

	graceful.Wait()
}
开发者ID:rightscale,项目名称:go-boilerplate,代码行数:25,代码来源:main.go

示例6: Add

func Add(mux *web.Mux) {

	/* Endpoint to handler config */
	mux.Get("/", home)
	mux.Get("/home", about)
	mux.Use(mux.Router)

}
开发者ID:tayste5000,项目名称:go-seed,代码行数:8,代码来源:routes.go

示例7: route

func route(m *web.Mux) {

	resultMux := web.New()
	resultMux.Get("/face_detect/:name", http.StripPrefix("/face_detect/", http.FileServer(http.Dir("./results/"))))
	resultMux.Use(renameID)

	m.Handle("/face_detect/:name", resultMux)
	m.Get(toolURI, controllers.ControllPannel)
	m.Post(toolURI, controllers.RegisterFace)
}
开发者ID:masu-mi,项目名称:face_detector,代码行数:10,代码来源:main.go

示例8: Generate

func (rm *RouterMold) Generate() *web.Mux {
	var mux *web.Mux
	if rm.SubRoutes == "" {
		mux = goji.DefaultMux
		mux.Abandon(middleware.Logger)
	} else {
		mux := web.New()
		mux.Use(middleware.RequestID)
		mux.Use(middleware.Recoverer)
		mux.Use(middleware.AutomaticOptions)
		goji.Handle(rm.SubRoutes, mux)
	}

	for _, m := range rm.Middlewares {
		mux.Use(m.MiddlewareFunc())
	}

	var handlerFunc func(Route) interface{}
	if rm.HandlerFunc == nil {
		handlerFunc = func(r Route) interface{} {
			return r.Handler
		}
	} else {
		handlerFunc = rm.HandlerFunc
	}

	for _, r := range rm.Routes {
		var pattern interface{}
		if r.RegExp != "" {
			pattern = regexp.MustCompile(r.RegExp)
		} else {
			pattern = r.Path
		}
		switch r.Method {
		case "HEAD":
			mux.Head(pattern, handlerFunc(r))
		case "GET":
			mux.Get(pattern, handlerFunc(r))
		case "POST":
			mux.Post(pattern, handlerFunc(r))
		case "PUT":
			mux.Put(pattern, handlerFunc(r))
		case "PATCH":
			mux.Patch(pattern, handlerFunc(r))
		case "DELETE":
			mux.Delete(pattern, handlerFunc(r))
		}
	}

	return mux
}
开发者ID:winespace,项目名称:goji-mold,代码行数:51,代码来源:router_mold.go

示例9: Route

// Route configures routing. it is also used in test-code
func Route(m *web.Mux) {

	m.Get("/hello/:name", hello)
	m.Get("/", root)
}
开发者ID:born-in-makuhari,项目名称:kanban,代码行数:6,代码来源:main.go

示例10: AddHandlers

// example handler
func AddHandlers(mux *web.Mux) {
	mux.Get("/api/xxxx", hello)
}
开发者ID:adulteratedjedi,项目名称:redishappy,代码行数:4,代码来源:main.go

示例11: route

func route(m *web.Mux) {
	m.Get("/hello/:name", hello)
}
开发者ID:otiai10,项目名称:gaego_sample,代码行数:3,代码来源:gaego_sample.go

示例12: Bookmarks

func Bookmarks(m *web.Mux) {
	goji.Handle("/bookmarks/*", m)
	goji.Get("/bookmarks", http.RedirectHandler("/bookmarks/", 301))

	m.Get("/bookmarks/", controllers.BookmarksHome)
}
开发者ID:hypebeast,项目名称:goji-boilerplate,代码行数:6,代码来源:routes.go

示例13: setRoutes

func setRoutes(mux *web.Mux, sde evego.Database, localdb db.LocalDB, xmlAPI evego.XMLAPI,
	eveCentral evego.Market, sessionizer server.Sessionizer, cache evego.Cache) {

	if c.Dev {
		bower := http.FileServer(http.Dir("bower_components"))
		mux.Get("/bower_components/*", http.StripPrefix("/bower_components/", bower))
	}

	mux.Get("/autocomplete/system/:name", api.AutocompleteSystems(sde))
	mux.Get("/autocomplete/station/:name", api.AutocompleteStations(sde, localdb, xmlAPI))
	mux.Post("/pastebin", api.ParseItems(sde))
	marketHandler := api.ItemsMarketValue(sde, eveCentral, xmlAPI)
	// For now these do the same thing. That may change.
	mux.Post("/market/region/:location", marketHandler)
	mux.Post("/market/system/:location", marketHandler)
	mux.Post("/market/station/:id", marketHandler)
	mux.Get("/market/jita", api.ReprocessOutputValues(sde, eveCentral, xmlAPI, cache))

	mux.Post("/reprocess", api.ReprocessItems(sde, eveCentral))
	// SSO!
	auth := evesso.MakeAuthenticator(evesso.Endpoint, c.ClientID, c.ClientSecret,
		c.RedirectURL, evesso.PublicData)
	mux.Get("/crestcallback", api.CRESTCallbackListener(localdb, auth, sessionizer))
	mux.Get("/authenticate", api.AuthenticateHandler(auth, sessionizer))
	mux.Get("/session", api.SessionInfo(auth, sessionizer, localdb))
	mux.Post("/logout", api.LogoutHandler(localdb, auth, sessionizer))

	// API keys
	listHandler, deleteHander, addHandler, refreshHandler := api.XMLAPIKeysHandlers(localdb, sessionizer)
	mux.Get("/apikeys/list", listHandler)
	mux.Post("/apikeys/delete/:keyid", deleteHander)
	mux.Post("/apikeys/add", addHandler)
	mux.Post("/apikeys/refresh", refreshHandler)

	// Standings and skills
	mux.Get("/standings/:charID/:npcCorpID", api.StandingsHandler(localdb, sessionizer))
	mux.Get("/skills/:charID/group/:skillGroupID", api.SkillsHandler(localdb, sessionizer))

	// Blueprints and industry
	_, getBPs := api.BlueprintsHandlers(localdb, sde, sessionizer)
	mux.Get("/blueprints/:charID", getBPs)
	mux.Get("/assets/unusedSalvage/:charID", api.UnusedSalvage(localdb, sde, sessionizer))

	// Static assets
	assets := http.FileServer(http.Dir("dist"))
	mux.Get("/*", assets)
}
开发者ID:backerman,项目名称:eveindy,代码行数:47,代码来源:routes.go

示例14: RootRouter

func RootRouter(m *web.Mux) {
	m.Get("/", Root)
}
开发者ID:kentatogashi,项目名称:go-memo,代码行数:3,代码来源:main.go

示例15: rooter

func rooter(m *web.Mux) http.Handler {

	m.Get("/admin/", ad.AdminIndex)

	m.Get("/user/index", cntr.UserIndex)
	m.Post("/user/add", cntr.UserAdd)
	m.Post("/user/auth", cntr.UserAuth)

	m.Get("/player/joblist", cntr.JobList)
	m.Post("/player/joblist", cntr.JobList)
	m.Get("/player/base_make", cntr.PlayerBaseMake)
	m.Post("/player/base_make", cntr.PlayerBaseMake)
	m.Post("/player/generate", cntr.PlayerGenerate)
	m.Post("/player/skill_setting", cntr.SkillSetting)
	m.Post("/player/skill_submit", cntr.SkillSubmit)

	m.Post("/home/user/info", cntr.UserInfo)
	m.Get("/home/scenario/list", cntr.ScenarioList)
	m.Post("/home/player/list", cntr.PlayerList)

	return m
}
开发者ID:syo-sa1982,项目名称:SeacherServerSide,代码行数:22,代码来源:main.go


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