• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang httptreemux.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: NewHTTP

// NewHTTP returns a new instance of the HTTPDrive struct.
func NewHTTP(before []DriveMiddleware, after []DriveMiddleware) *HTTPDrive {
	var drive HTTPDrive
	drive.TreeMux = httptreemux.New()
	drive.globalMW = LiftWM(before...)
	drive.globalMWAfter = LiftWM(after...)
	return &drive
}
开发者ID:influx6,项目名称:gu,代码行数:8,代码来源:servers.go


示例2: loadHttpTreeMux

func loadHttpTreeMux(routes []route) http.Handler {
	router := httptreemux.New()
	for _, route := range routes {
		router.Handle(route.method, route.path, httpTreeMuxHandler)
	}
	return router
}
开发者ID:lamproae,项目名称:go-http-routing-benchmark,代码行数:7,代码来源:routers.go


示例3: New

// New create an Web value that handle a set of routes for the application.
// You can provide any number of middleware and they'll be used to wrap every
// request handler.
func New(mw ...Middleware) *Web {
	return &Web{
		TreeMux: httptreemux.New(),
		Ctx:     make(map[string]interface{}),
		mw:      mw,
	}
}
开发者ID:coralproject,项目名称:xenia,代码行数:10,代码来源:web.go


示例4: buildApp

func buildApp(z *Zest) error {
	deps := usecases.DependencyDirectory.Get()

	store := infrastructure.NewGormStore()
	accountRepo := resources.NewAccountRepo(store)
	aclRepo := resources.NewAclRepo(store)
	sessionRepo := resources.NewSessionRepo(store)

	deps = append(
		deps,

		store,
		accountRepo,
		aclRepo,
		sessionRepo,
		httptreemux.New(),
		infrastructure.NewRender(),
		infrastructure.NewCacheStore(),
		usecases.NewPermissionCacheInter(accountRepo, aclRepo, infrastructure.NewCacheStore(), infrastructure.NewCacheStore()),
		usecases.NewSessionCacheInter(sessionRepo, infrastructure.NewLRUCacheStore(1024)),
		usecases.NewRouteDirectory,
		usecases.NewPermissionInter,
	)

	z.Injector.RegisterMultiple(deps)

	err := z.Injector.Populate()
	if err != nil {
		return err
	}

	return nil
}
开发者ID:optimuse,项目名称:zest,代码行数:33,代码来源:zest.go


示例5: NewMux

// NewMux returns a Mux.
func NewMux() ServeMux {
	r := httptreemux.New()
	r.EscapeAddedRoutes = true
	return &mux{
		router:  r,
		handles: make(map[string]MuxHandler),
	}
}
开发者ID:konstantin-dzreev,项目名称:goa,代码行数:9,代码来源:mux.go


示例6: New

// New creates a new Router and returns it
func New() *Router {
	r := &Router{}
	r.index = make(map[string]string)
	r.prefix = "/"
	r.router = httptreemux.New()
	r.router.NotFoundHandler = http.HandlerFunc(r.notFoundHandler)

	return r
}
开发者ID:Billups,项目名称:goat,代码行数:10,代码来源:goat.go


示例7: Init

func (s *Server) Init() {

	s.logger = log.New(os.Stdout, "[GoWebApp] ", 0)
	mainController := controllers.NewMainController()

	s.router = httptreemux.New()
	s.router.GET("/", mainController.GetHandler)
	s.router.GET("/_version", mainController.GetVersionHandler)

	s.httpServer = negroni.Classic()
	s.httpServer.UseHandler(s.router)
}
开发者ID:cleitonmarx,项目名称:GoWebApp,代码行数:12,代码来源:server.go


示例8: initRoutes

func (s *Server) initRoutes() {
	s.router = httptreemux.New()
	s.router.GET("/", s.healthCheck)
	s.router.GET("/healthcheck", s.healthCheck)

	s.router.POST("/api/item-schemas", transaction.Handle(s.createItemSchema))
	s.router.GET("/api/item-schemas", transaction.Handle(s.findItemSchema))
	s.router.GET("/api/item-schemas/findOne", transaction.Handle(s.findOneItemSchema))
	s.router.GET("/api/item-schemas/:collectionName", transaction.Handle(s.findItemSchemaByCollectionName))
	s.router.DELETE("/api/item-schemas/:collectionName", transaction.Handle(s.deleteItemSchemaByCollectionName))

	s.router.POST("/api/:collectionName", s.createResource)
	s.router.GET("/api/:collectionName", s.findResource)
	s.router.GET("/api/:collectionName/findOne", s.findOneResource)
	s.router.GET("/api/:collectionName/:resourceId", s.findResourceById)
	s.router.DELETE("/api/:collectionName/:resourceId", s.deleteResourceById)
}
开发者ID:ricobl,项目名称:beat,代码行数:17,代码来源:server.go


示例9: main

func main() {
	// get config var
	port := envMustGet("JUNO_PORT")
	murl := envMustGet("JUNO_MONGO_URL")

	// initialize mongo
	s := storage.MgoMustConnect(murl)
	defer s.Close()

	// controller have to work with storage
	c := controller.New(s)

	// init router. httptreemux is fast and convinient
	r := httptreemux.New()

	// some of the endpoints are available in anonymous mode and some of them aren't.
	// we can perform different middleware operations - with auth checks and without.

	// build middleware that creates context and pass it to handlers
	rc := middle.Context(r, s)
	// add version
	rc = middle.Version(rc, VER)
	rc.Handle("POST", "/user", c.UserCreate)
	rc.Handle("GET", "/user/:userid/confirm", c.UserConfirm)

	rc.Handle("GET", "/profile/:profid", c.ProfileGet)
	rc.Handle("GET", "/profile/all", c.ProfileAll)

	// Add middleware that checks authentication.
	ra := middle.Authentication(rc, s)
	ra.Handle("PUT", "/profile", c.ProfileUpdate)
	ra.Handle("GET", "/profile/:profid/history", c.ProfileHistory)

	// add middleware that decorates router and checks that Content-Type is application/json
	rj := middle.JSONContentType(r)

	// Fire up the server
	log.Panic(http.ListenAndServe("localhost:"+port, rj))
}
开发者ID:Kaign,项目名称:juno,代码行数:39,代码来源:juno.go


示例10: loadHttpTreeMuxSingle

func loadHttpTreeMuxSingle(method, path string, handler httptreemux.HandlerFunc) http.Handler {
	router := httptreemux.New()
	router.Handle(method, path, handler)
	return router
}
开发者ID:lamproae,项目名称:go-http-routing-benchmark,代码行数:5,代码来源:routers.go


示例11: NewMux

// NewMux returns a Mux.
func NewMux() ServeMux {
	return &mux{
		router:  httptreemux.New(),
		handles: make(map[string]MuxHandler),
	}
}
开发者ID:ajoulie,项目名称:goa,代码行数:7,代码来源:mux.go


示例12: New

// New create an App value that handle a set of routes for the application.
// You can provide any number of middleware and they'll be used to wrap every
// request handler.
func New(mw ...Middleware) *App {
	return &App{
		TreeMux: httptreemux.New(),
		mw:      mw,
	}
}
开发者ID:ramakrishna580,项目名称:kit,代码行数:9,代码来源:app.go


示例13: starthttpTreeMux

func starthttpTreeMux() {
	mux := httptreemux.New()
	mux.GET("/hello", httpTreeMuxHandler)
	http.ListenAndServe(":"+strconv.Itoa(port), mux)
}
开发者ID:cokeboL,项目名称:go-web-framework-benchmark,代码行数:5,代码来源:server.go


示例14: New

// New create an App value that handle a set of routes for the application.
func New() *App {
	return &App{
		TreeMux: httptreemux.New(),
	}
}
开发者ID:rlugojr,项目名称:gotraining,代码行数:6,代码来源:app.go


示例15: main

func main() {
	// Setup
	var err error

	// GOMAXPROCS - Maybe not needed
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Write log to file if the log flag was provided
	if flags.Log != "" {
		logFile, err := os.OpenFile(flags.Log, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			log.Fatal("Error: Couldn't open log file: " + err.Error())
		}
		defer logFile.Close()
		log.SetOutput(logFile)
	}

	// Configuration is read from config.json by loading the configuration package

	// Database
	err = database.Initialize()
	if err != nil {
		log.Fatal("Error: Couldn't initialize database:", err)
		return
	}

	// Global blog data
	err = methods.GenerateBlog()
	if err != nil {
		log.Fatal("Error: Couldn't generate blog data:", err)
		return
	}

	// Templates
	err = templates.Generate()
	if err != nil {
		log.Fatal("Error: Couldn't compile templates:", err)
		return
	}

	// Plugins
	err = plugins.Load()
	if err == nil {
		// Close LuaPool at the end
		defer plugins.LuaPool.Shutdown()
		log.Println("Plugins loaded.")
	}

	// HTTP(S) Server
	httpPort := configuration.Config.HttpHostAndPort
	httpsPort := configuration.Config.HttpsHostAndPort
	// Check if HTTP/HTTPS flags were provided
	if flags.HttpPort != "" {
		components := strings.SplitAfterN(httpPort, ":", 2)
		httpPort = components[0] + flags.HttpPort
	}
	if flags.HttpsPort != "" {
		components := strings.SplitAfterN(httpsPort, ":", 2)
		httpsPort = components[0] + flags.HttpsPort
	}
	// Determine the kind of https support (as set in the config.json)
	switch configuration.Config.HttpsUsage {
	case "AdminOnly":
		checkHttpsCertificates()
		httpRouter := httptreemux.New()
		httpsRouter := httptreemux.New()
		// Blog and pages as http
		server.InitializeBlog(httpRouter)
		server.InitializePages(httpRouter)
		// Blog and pages as https
		server.InitializeBlog(httpsRouter)
		server.InitializePages(httpsRouter)
		// Admin as https and http redirect
		// Add redirection to http router
		httpRouter.GET("/admin/", httpsRedirect)
		httpRouter.GET("/admin/*path", httpsRedirect)
		// Add routes to https router
		server.InitializeAdmin(httpsRouter)
		// Start https server
		log.Println("Starting https server on port " + httpsPort + "...")
		go func() {
			err := http.ListenAndServeTLS(httpsPort, filenames.HttpsCertFilename, filenames.HttpsKeyFilename, httpsRouter)
			if err != nil {
				log.Fatal("Error: Couldn't start the HTTPS server:", err)
			}
		}()
		// Start http server
		log.Println("Starting http server on port " + httpPort + "...")
		err := http.ListenAndServe(httpPort, httpRouter)
		if err != nil {
			log.Fatal("Error: Couldn't start the HTTP server:", err)
		}
	case "All":
		checkHttpsCertificates()
		httpsRouter := httptreemux.New()
		httpRouter := httptreemux.New()
		// Blog and pages as https
		server.InitializeBlog(httpsRouter)
		server.InitializePages(httpsRouter)
		// Admin as https
//.........这里部分代码省略.........
开发者ID:itkpi,项目名称:journey,代码行数:101,代码来源:main.go


示例16: NewEndPoints

//NewEndPoints creates new prefixed endpoints
func NewEndPoints(not *notifier.Notifier, store *sqlstore.Store, convs feeder.Conventions, cfg config.Rest, org config.Internships) EndPoints {
	ed := EndPoints{
		store:        store,
		router:       httptreemux.New(),
		prefix:       strings.TrimSuffix(cfg.Prefix, "/"),
		cfg:          cfg,
		organization: org,
		conventions:  convs,
		notifier:     not,
	}
	ed.router.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) {
		http.Error(w, "", http.StatusNotFound)
	}
	//Set the endpoints
	ed.get("/users/", users)
	ed.post("/users/", newUser)
	ed.post("/users/:u/email", setEmail)
	ed.post("/users/:u/person", setUserPerson)
	ed.post("/users/:u/role", setUserRole)
	ed.del("/users/:u", delUser)
	ed.get("/users/:u", user)
	ed.del("/users/:u/session", ed.delSession)
	ed.post("/students/:s/major", setMajor)
	ed.post("/students/:s/promotion", setPromotion)
	ed.post("/students/:s/male", setMale)
	ed.post("/students/:s/alumni", setAlumni)
	ed.post("/students/:s/skip", setStudentSkippable)
	ed.get("/students/", students)
	ed.post("/students/", newStudent)

	ed.router.GET(ed.prefix+"/internships/", ed.anon(internships))
	ed.get("/internships/:s", internship)
	ed.post("/internships/:s/company", setCompany)
	ed.post("/internships/:s/supervisor", setSupervisor)
	ed.post("/internships/:s/tutor", setTutor)
	ed.del("/internships/:s/defense", rmDefense)
	ed.post("/internships/:s/defense", setStudentDefense)
	ed.put("/internships/:s/defense", updateStudentDefense)
	ed.get("/internships/:s/defense", studentDefense)
	ed.post("/internships/:s/defense/grade", setDefenseGrade)
	ed.post("/internships/", ed.newInternship)

	ed.del("/surveys/:s/:k", resetSurvey)
	ed.post("/surveys/:s/:k", requestSurvey)
	ed.get("/reports/:s/:k/", report)
	ed.get("/reports/:s/:k/content", reportContent)
	ed.post("/reports/:s/:k/content", setReportContent)
	ed.post("/reports/:s/:k/deadline", setReportDeadline)
	ed.post("/reports/:s/:k/grade", setReportGrade)
	ed.post("/reports/:s/:k/private", setReportPrivacy)

	ed.get("/conventions/", conventions)
	ed.get("/conventions/:s", convention)

	ed.get("/logs/:k", streamLog)
	ed.get("/logs/", logs)

	ed.get("/defenses/", defenseSessions)
	ed.post("/defenses/", newDefenseSession)
	ed.get("/defenses/:id/:r/", defenseSession)
	ed.del("/defenses/:id/:r", rmDefenseSession)
	ed.post("/defenses/:id/:r/jury/", newDefenseSessionJury)
	ed.del("/defenses/:id/:r/jury/:j", rmDefenseSessionJury)

	ed.router.GET(ed.prefix+"/program/", ed.anon(ed.program))
	ed.router.POST(ed.prefix+"/signin", ed.anon(ed.signin))
	ed.router.POST(ed.prefix+"/resetPassword", ed.anon(ed.resetPassword))
	ed.router.POST(ed.prefix+"/newPassword", ed.anon(ed.newPassword))
	ed.router.GET(ed.prefix+"/config", ed.anon(ed.config))
	ed.router.GET(ed.prefix+"/surveys/:t", ed.anon(ed.survey))
	ed.router.POST(ed.prefix+"/surveys/:t", ed.anon(ed.setSurvey))
	return ed
}
开发者ID:fhermeni,项目名称:wints,代码行数:74,代码来源:rest.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang httptreemux.TreeMux类代码示例发布时间:2022-05-23
下一篇:
Golang middleware.Context类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap