本文整理汇总了Golang中github.com/dimfeld/httptreemux.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: loadHttpTreeMux
func loadHttpTreeMux(routes []route) http.Handler {
router := httptreemux.New()
for _, route := range routes {
router.Handle(route.method, route.path, httpTreeMuxHandler)
}
return router
}
示例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,
}
}
示例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
}
示例5: NewMux
// NewMux returns a Mux.
func NewMux() ServeMux {
r := httptreemux.New()
r.EscapeAddedRoutes = true
return &mux{
router: r,
handles: make(map[string]MuxHandler),
}
}
示例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
}
示例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)
}
示例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)
}
示例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))
}
示例10: loadHttpTreeMuxSingle
func loadHttpTreeMuxSingle(method, path string, handler httptreemux.HandlerFunc) http.Handler {
router := httptreemux.New()
router.Handle(method, path, handler)
return router
}
示例11: NewMux
// NewMux returns a Mux.
func NewMux() ServeMux {
return &mux{
router: httptreemux.New(),
handles: make(map[string]MuxHandler),
}
}
示例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,
}
}
示例13: starthttpTreeMux
func starthttpTreeMux() {
mux := httptreemux.New()
mux.GET("/hello", httpTreeMuxHandler)
http.ListenAndServe(":"+strconv.Itoa(port), mux)
}
示例14: New
// New create an App value that handle a set of routes for the application.
func New() *App {
return &App{
TreeMux: httptreemux.New(),
}
}
示例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
//.........这里部分代码省略.........