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


Golang bone.New函数代码示例

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


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


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