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

Golang bone.New函数代码示例

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

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



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

示例1: main

func main() {
	boneSub := bone.New()
	gorrilaSub := mux.NewRouter()
	httprouterSub := httprouter.New()

	boneSub.GetFunc("/test", func(rw http.ResponseWriter, req *http.Request) {
		rw.Write([]byte("Hello from bone mux"))
	})

	gorrilaSub.HandleFunc("/test", func(rw http.ResponseWriter, req *http.Request) {
		rw.Write([]byte("Hello from gorilla mux"))
	})

	httprouterSub.GET("/test", func(rw http.ResponseWriter, req *http.Request, _ httprouter.Params) {
		rw.Write([]byte("Hello from httprouter mux"))
	})

	muxx := bone.New().Prefix("/api")

	muxx.SubRoute("/bone", boneSub)
	muxx.SubRoute("/gorilla", gorrilaSub)
	muxx.SubRoute("/http", httprouterSub)

	http.ListenAndServe(":8080", muxx)
}
开发者ID:viniciusfeitosa,项目名称:bone,代码行数:25,代码来源:example.go


示例2: main

func main() {

	db, err := bolt.Open("proxy.db", 0600, nil)

	if err != nil {
		log.Fatal("Fatal: %s\n", err.Error())
	}

	defer db.Close()

	adminServer := proxyAdminServer{db}

	adminMux := bone.New()
	adminMux.Get("/proxy", http.HandlerFunc(adminServer.GetProxies))
	adminMux.Delete("/proxy/:id", http.HandlerFunc(adminServer.DeleteProxyIteraction))
	adminMux.Post("/proxy", http.HandlerFunc(adminServer.NewProxyIteraction))

	proxyServer := proxyServer{&http.Client{}, db}

	mux := bone.New()

	mux.Handle("/*", http.HandlerFunc(proxyServer.ProxyHandler))

	go func(port string) {
		log.Println("Starting admin server")
		log.Fatal(http.ListenAndServe(port, adminMux))
	}(":9080")
	log.Println("Starting test proxy")
	log.Fatal(http.ListenAndServe(":9090", mux))
}
开发者ID:GreyRockSoft,项目名称:test-proxy,代码行数:30,代码来源:main.go


示例3: main

func main() {
	mux := bone.New()

	mux.GetFunc("/ctx/:var", rootHandler)

	http.ListenAndServe(":8080", mux)
}
开发者ID:nmarcetic,项目名称:mainflux,代码行数:7,代码来源:example.go


示例4: getBoneRouter

// getBoneRouter returns mux for admin interface
func getBoneRouter(d DBClient) *bone.Mux {
	mux := bone.New()

	mux.Get("/records", http.HandlerFunc(d.AllRecordsHandler))
	mux.Delete("/records", http.HandlerFunc(d.DeleteAllRecordsHandler))
	mux.Post("/records", http.HandlerFunc(d.ImportRecordsHandler))

	mux.Get("/count", http.HandlerFunc(d.RecordsCount))
	mux.Get("/stats", http.HandlerFunc(d.StatsHandler))
	mux.Get("/statsws", http.HandlerFunc(d.StatsWSHandler))

	mux.Get("/state", http.HandlerFunc(d.CurrentStateHandler))
	mux.Post("/state", http.HandlerFunc(d.StateHandler))

	if d.Cfg.Development {
		// since hoverfly is not started from cmd/hoverfly/hoverfly
		// we have to target to that directory
		log.Warn("Hoverfly is serving files from /static/dist instead of statik binary!")
		mux.Handle("/*", http.FileServer(http.Dir("../../static/dist")))
	} else {
		// preparing static assets for embedded admin
		statikFS, err := fs.New()

		if err != nil {
			log.WithFields(log.Fields{
				"Error": err.Error(),
			}).Error("Failed to load statikFS, admin UI might not work :(")
		}

		mux.Handle("/*", http.FileServer(statikFS))
	}

	return mux
}
开发者ID:daniel-bryant-uk,项目名称:hoverfly,代码行数:35,代码来源:admin.go


示例5: NewRestServer

// NewServer creates a server that will listen for requests over HTTP and interact with the RCON server specified
// non-/api prefixed routes are served from static files compiled into bindata_assetfs.go
func NewRestServer(c *ServerConfig) {
	var err error
	rcon_client, err = mcrcon.NewClient(c.RCON_address, c.RCON_port, c.RCON_password)

	if err != nil {
		panic(fmt.Errorf("Could not connect to RCON server at %s:%d. (Error was: %s)", c.RCON_address, c.RCON_port, err))
	}

	router := bone.New()

	// Redirect static resources, and then handle the static resources (/gui/) routes with the static asset file
	router.Handle("/", http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
		http.Redirect(response, request, "/gui/", 302)
	}))
	router.Get("/gui/", http.StripPrefix("/gui/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: ""})))

	// Define the API (JSON) routes
	router.GetFunc("/api", apiRootHandler)
	router.GetFunc("/api/users", usersRootHandler)
	router.GetFunc("/api/users/:username", usernameHandler)

	// TODO: Require a http basic auth username and password if passed in.

	// Start the server
	fmt.Println("Starting server on port", c.Port)
	http.ListenAndServe(fmt.Sprintf(":%d", c.Port), router)
}
开发者ID:joshproehl,项目名称:minecontrol,代码行数:29,代码来源:server.go


示例6: main

func main() {
	db, err := sql.Open("postgres", "user=laptop dbname=estelle_test sslmode=disable")
	if err != nil {
		log.Fatal(err)
	}

	r := render.New(render.Options{
		Directory:  "views",
		Extensions: []string{".html"},
	})

	mux := bone.New()
	ServeResource := assets.ServeResource
	mux.HandleFunc("/img/", ServeResource)
	mux.HandleFunc("/css/", ServeResource)
	mux.HandleFunc("/js/", ServeResource)

	mux.HandleFunc("/pages", func(w http.ResponseWriter, req *http.Request) {
		rows, err := db.Query("SELECT id, title FROM pages")
		if err != nil {
			log.Fatal(err)
		}
		defer rows.Close()
		type yourtype struct {
			Id    int
			Title string
		}

		s := []yourtype{}
		for rows.Next() {
			var t yourtype
			if err := rows.Scan(&t.Id, &t.Title); err != nil {
				log.Fatal(err)
			}
			fmt.Printf("%s", t.Title)
			s = append(s, t)
		}
		r.HTML(w, http.StatusOK, "foofoo", s)
	})

	mux.HandleFunc("/bar", func(w http.ResponseWriter, req *http.Request) {
		r.HTML(w, http.StatusOK, "bar", nil)
	})

	mux.HandleFunc("/home/:id", func(w http.ResponseWriter, req *http.Request) {
		id := bone.GetValue(req, "id")
		r.HTML(w, http.StatusOK, "index", id)
	})

	mux.HandleFunc("/foo", func(w http.ResponseWriter, req *http.Request) {
		r.HTML(w, http.StatusOK, "foo", nil)
	})

	mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		r.HTML(w, http.StatusOK, "index", nil)
	})

	http.ListenAndServe(":8080", mux)
}
开发者ID:AppyCat,项目名称:go-crud-app,代码行数:59,代码来源:main.go


示例7: main

func main() {
	mux := bone.New()

	mux.GetFunc("/image/:rows", ImageHandler)
	mux.GetFunc("/html/:rows", HtmlHandler)

	http.ListenAndServe(":3000", mux)
}
开发者ID:matthewdu,项目名称:rule110-go,代码行数:8,代码来源:rule110.go


示例8: getBoneRouter

func getBoneRouter(h HTTPClientHandler) *bone.Mux {
	mux := bone.New()
	mux.Get("/query", http.HandlerFunc(h.queryTwitter))
	mux.Get("/", http.HandlerFunc(h.homeHandler))
	// handling static files
	mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

	return mux
}
开发者ID:tjcunliffe,项目名称:twitter-app,代码行数:9,代码来源:server.go


示例9: main

func main() {
	router := bone.New()

	router.GetFunc("/", index)
	router.GetFunc("/hello/:name", hello)

	log.Println("Starting server on port 9090")
	log.Fatal(http.ListenAndServe(":9090", router))
}
开发者ID:dimiro1,项目名称:experiments,代码行数:9,代码来源:main.go


示例10: main

func main() {
	// looking for option args when starting App
	// like ./overeer -port=":3000" would start on port 3000
	var port = flag.String("port", ":3000", "Server port")
	var dbActions = flag.String("db", "", "Database actions - create, migrate, drop")
	flag.Parse() // parse the flag

	// init connection
	db, err := gorm.Open("sqlite3", "gorm.db")
	if err != nil {
		log.WithFields(log.Fields{"error": err.Error()}).Fatal("Failed to open sqlite DB")
	}
	defer db.Close()
	db.DB()
	db.DB().Ping()
	db.DB().SetMaxIdleConns(10)
	db.DB().SetMaxOpenConns(100)

	// flag to do something with the database
	if *dbActions != "" {
		log.WithFields(log.Fields{"action": dbActions}).Info("Database action initiated.")
		d := DBActions{db: &db}

		// create tables
		if *dbActions == "create" {
			d.createTables()
		}
		// drop tables
		if *dbActions == "drop" {
			d.dropTables()
		}
		return
	}
	r := render.New(render.Options{Layout: "layout"})
	h := DBHandler{db: &db, r: r}

	mux := bone.New()
	mux.Get("/", http.HandlerFunc(homeHandler))
	mux.Post("/stubos", http.HandlerFunc(h.stubosCreateHandler))
	mux.Get("/stubos", http.HandlerFunc(h.stuboShowHandler))
	mux.Delete("/stubos/:id", http.HandlerFunc(h.stuboDestroyHandler))
	mux.Get("/stubos/:id", http.HandlerFunc(h.stuboDetailedHandler))
	mux.Get("/stubos/:id/scenarios/:scenario", http.HandlerFunc(h.scenarioDetailedHandler))
	mux.Get("/stubos/:id/scenarios/:scenario/stubs", http.HandlerFunc(h.scenarioStubsHandler))
	// handling static files
	mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
	n := negroni.Classic()
	n.Use(negronilogrus.NewMiddleware())
	n.UseHandler(mux)

	log.WithFields(log.Fields{
		"port": port,
	}).Info("Overseer is starting")

	n.Run(*port)
}
开发者ID:rusenask,项目名称:overseer,代码行数:56,代码来源:server.go


示例11: init

func init() {
	mux := bone.New()

	mux.PostFunc("/buy_request", BuyRequestHandler)
	mux.GetFunc("/request/:key", RequestHandler)
	mux.GetFunc("/delivery_status/:key", DeliveryHandler)
	mux.PostFunc("/accept_request/:key", AcceptRequestHandler)
	mux.PostFunc("/get_cl", GetCL)
	http.Handle("/", mux)
}
开发者ID:matthewdu,项目名称:powerplug,代码行数:10,代码来源:server.go


示例12: runServer

func runServer() error {
	mux := bone.New()
	mux.HandleFunc("/", inputs)
	mux.HandleFunc("/api/", serveArticle)

	mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

	err := http.ListenAndServe(*listenAddr, httpLogger(mux))

	return err
}
开发者ID:frankMilde,项目名称:rol,代码行数:11,代码来源:server.go


示例13: init

func init() {
	mux := bone.New()

	mux.GetFunc("/image/:rows", ImageHandler)
	mux.GetFunc("/html/:rows", HtmlHandler)
	mux.GetFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.Redirect(w, r, "http://github.com/matthewdu/rule110-go", 301)
	})

	http.Handle("/", mux)
}
开发者ID:matthewdu,项目名称:rule110-go,代码行数:11,代码来源:rule110.go


示例14: getBoneRouter

func getBoneRouter(h HTTPClientHandler) *bone.Mux {
	mux := bone.New()
	mux.Get("/1.1/search/tweets.json", http.HandlerFunc(h.tweetSearchEndpoint))
	mux.Get("/admin", http.HandlerFunc(h.adminHandler))
	mux.Post("/admin/state", http.HandlerFunc(h.stateHandler))
	mux.Get("/admin/state", http.HandlerFunc(h.getStateHandler))
	// handling static files
	mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

	return mux
}
开发者ID:tjcunliffe,项目名称:twitter-proxy,代码行数:11,代码来源:server.go


示例15: getBoneRouter

// getBoneRouter returns mux for admin interface
func (this *AdminApi) getBoneRouter(d *Hoverfly) *bone.Mux {
	mux := bone.New()

	authHandler := &handlers.AuthHandler{
		d.Authentication,
		d.Cfg.SecretKey,
		d.Cfg.JWTExpirationDelta,
		d.Cfg.AuthEnabled,
	}

	authHandler.RegisterRoutes(mux)

	handlers := GetAllHandlers(d)
	for _, handler := range handlers {
		handler.RegisterRoutes(mux, authHandler)
	}

	if d.Cfg.Development {
		// since hoverfly is not started from cmd/hoverfly/hoverfly
		// we have to target to that directory
		log.Warn("Hoverfly is serving files from /static/admin/dist instead of statik binary!")
		mux.Handle("/js/*", http.StripPrefix("/js/", http.FileServer(http.Dir("../../static/admin/dist/js"))))

		mux.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
			http.ServeFile(w, r, "../../static/admin/dist/index.html")
		})

	} else {
		// preparing static assets for embedded admin
		statikFS, err := fs.New()

		if err != nil {
			log.WithFields(log.Fields{
				"Error": err.Error(),
			}).Error("Failed to load statikFS, admin UI might not work :(")
		}
		mux.Handle("/js/*", http.FileServer(statikFS))
		mux.Handle("/app.32dc9945fd902da8ed2cccdc8703129f.css", http.FileServer(statikFS))
		mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			file, err := statikFS.Open("/index.html")
			if err != nil {
				w.WriteHeader(500)
				log.WithFields(log.Fields{
					"error": err,
				}).Error("got error while opening index file")
				return
			}
			io.Copy(w, file)
			w.WriteHeader(200)
		})
	}
	return mux
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:54,代码来源:admin.go


示例16: getBoneRouter

// getBoneRouter returns mux for admin interface
func getBoneRouter(d DBClient) *bone.Mux {
	mux := bone.New()

	mux.Get("/records", http.HandlerFunc(d.AllRecordsHandler))
	mux.Delete("/records", http.HandlerFunc(d.DeleteAllRecordsHandler))
	mux.Post("/records", http.HandlerFunc(d.ImportRecordsHandler))

	mux.Get("/state", http.HandlerFunc(d.CurrentStateHandler))
	mux.Post("/state", http.HandlerFunc(d.stateHandler))

	return mux
}
开发者ID:rusenask,项目名称:genproxy,代码行数:13,代码来源:admin.go


示例17: NewHostBasedDispatcher

func NewHostBasedDispatcher(
	cfg *config.Configuration,
	log *logging.Logger,
	prx *proxy.ProxyHandler,
) (Dispatcher, error) {
	disp := new(hostBasedDispatcher)
	disp.cfg = cfg
	disp.log = log
	disp.prx = prx
	disp.mux = bone.New()
	disp.handlers = make(map[string]handlerPair)

	return disp, nil
}
开发者ID:martin-helmich,项目名称:servicegateway,代码行数:14,代码来源:hostbased.go


示例18: getRouter

func getRouter(h HandlerHTTPClient) *bone.Mux {
	mux := bone.New()
	mux.Post("/stubo/api/put/stub", http.HandlerFunc(h.putStubHandler))
	mux.Post("/stubo/api/get/response", http.HandlerFunc(h.getStubResponseHandler))
	mux.Get("/stubo/api/get/stublist", http.HandlerFunc(h.stublistHandler))
	mux.Get("/stubo/api/delete/stubs", http.HandlerFunc(h.deleteStubsHandler))
	mux.Get("/stubo/api/put/delay_policy", http.HandlerFunc(h.putDelayPolicyHandler))
	mux.Get("/stubo/api/get/delay_policy", http.HandlerFunc(h.getDelayPolicyHandler))
	mux.Get("/stubo/api/delete/delay_policy", http.HandlerFunc(h.deleteDelayPolicyHandler))
	mux.Get("/stubo/api/begin/session", http.HandlerFunc(h.beginSessionHandler))
	mux.Get("/stubo/api/end/sessions", http.HandlerFunc(h.endSessionsHandler))
	mux.Get("/stubo/api/get/scenarios", http.HandlerFunc(h.getScenariosHandler))
	return mux
}
开发者ID:rusenask,项目名称:lgc,代码行数:14,代码来源:server.go


示例19: NewPathBasedDispatcher

func NewPathBasedDispatcher(
	cfg *config.Configuration,
	log *logging.Logger,
	prx *proxy.ProxyHandler,
) (*pathBasedDispatcher, error) {
	dispatcher := new(pathBasedDispatcher)
	dispatcher.cfg = cfg
	dispatcher.mux = bone.New()
	dispatcher.log = log
	dispatcher.prx = prx
	dispatcher.behaviours = make([]DispatcherBehaviour, 0, 8)

	return dispatcher, nil
}
开发者ID:martin-helmich,项目名称:servicegateway,代码行数:14,代码来源:pathbased.go


示例20: main

func main() {
	flagParse()

	mux := bone.New()
	mux.NotFound(func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("knick-knack paddywhack give a dog a bone, this old man is no longer home"))
	})

	go databaseDumper(workers)

	mux.Get("/database/:name", http.HandlerFunc(dumpHandler))

	log.Printf("Listening on %s\n", host)
	log.Fatal(http.ListenAndServe(host, mux))
}
开发者ID:JustAdam,项目名称:dbsync,代码行数:15,代码来源:server.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang bone.Mux类代码示例发布时间:2022-05-23
下一篇:
Golang bone.GetValue函数代码示例发布时间: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