當前位置: 首頁>>代碼示例>>Golang>>正文


Golang standard.New函數代碼示例

本文整理匯總了Golang中github.com/labstack/echo/engine/standard.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {

	c, err := importConfiguration("./config.json")
	if err != nil {
		fmt.Printf("Could not import the configuration file, check that it exists: %s\n", err.Error())
	}
	config = c

	e := echo.New()
	e.Pre(middleware.RemoveTrailingSlash())

	e.Post("/api/users", postUserHandler)
	e.Post("/api/users/:userID/clockin", clockInHandler)
	e.Post("/api/users/:userID/clockout", clockOutHandler)

	e.Get("/api/users/:userID", getUserHandler)
	e.Get("/api/users/:userID/lastpunch", getLastPunchHandler)
	e.Get("/api/users/:userID/punches", getPunchesHandler)

	e.Static("/pages", "Static")
	e.Static("/scripts", "Static/scripts")

	e.Run(standard.New(":8888"))

	//eventually we need to accept command line parameters.
}
開發者ID:xuther,項目名稱:timeclock,代碼行數:26,代碼來源:server.go

示例2: main

func main() {
	if displayVersion {
		fmt.Printf("Abraracourcix v%s\n", version.Version)
		return
	}
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}

	store, err := getStorage()
	if err != nil {
		log.Printf("[ERROR] [abraracourcix] %v", err)
		return
	}
	var auth *api.Authentication
	log.Printf("%s %s", username, password)
	if len(username) > 0 && len(password) > 0 {
		auth = &api.Authentication{
			Username: username,
			Password: password,
		}
	}
	ws := api.GetWebService(store, auth)
	if debug {
		ws.Debug()
	}
	log.Printf("[INFO] [abraracourcix] Launch Abraracourcix on %s using %s backend",
		port, backend)
	ws.Run(standard.New(fmt.Sprintf(":%s", port)))
}
開發者ID:nlamirault,項目名稱:abraracourcix,代碼行數:32,代碼來源:abraracourcix.go

示例3: main

func main() {
	if displayVersion {
		fmt.Printf("Tchoupi v%s\n", version.Version)
		return
	}
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}

	var auth *api.Authentication
	log.Printf("%s %s", username, password)
	if len(username) > 0 && len(password) > 0 {
		auth = &api.Authentication{
			Username: username,
			Password: password,
		}
	}
	ws := api.GetWebService(auth)
	if debug {
		ws.Debug()
	}
	log.Printf("[INFO] Launch on %s", port)
	ws.Run(standard.New(fmt.Sprintf(":%s", port)))
}
開發者ID:nlamirault,項目名稱:tchoupi,代碼行數:26,代碼來源:tchoupi.go

示例4: main

func main() {
	log.SetFormatter(&log.JSONFormatter{})
	log.SetOutput(os.Stdout)
	log.SetLevel(log.InfoLevel)

	config := Config{
		Port: 8080,
	}

	e := echo.New()

	err := InitializeWebsocket(e)

	if err != nil {
		panic(err)
	}

	err = InitializeRenderers(e)

	if err != nil {
		panic(err)
	}

	e.GET("/", func(c echo.Context) error {
		return c.Render(http.StatusOK, "view/index.html", "")
	})

	log.Info(config)
	e.Run(standard.New(fmt.Sprintf(":%d", config.Port)))
}
開發者ID:boundedinfinity,項目名稱:bi-echo,代碼行數:30,代碼來源:main.go

示例5: main

func main() {
	serv := echo.New()
	serv.Use(middleware.Logger())
	serv.Use(middleware.Recover())
	// store := session.NewCookieStore([]byte("secret"))
	store, err := session.NewRedisStore(32, "tcp", "localhost:6379", "", []byte("secret"))
	if err != nil {
		panic(err)
	}
	serv.Use(session.Sessions("GSESSION", store))
	serv.Get("/", func(ctx echo.Context) error {
		session := session.Default(ctx)
		var count int
		v := session.Get("count")
		if v == nil {
			count = 0
		} else {
			count = v.(int)
			count += 1
		}
		session.Set("count", count)
		session.Save()
		ctx.JSON(200, map[string]interface{}{
			"visit": count,
		})
		return nil
	})
	serv.Run(standard.New(":8081"))
}
開發者ID:ipfans,項目名稱:echo-session,代碼行數:29,代碼來源:readme_example.go

示例6: main

func main() {
	e := echo.New()

	// Middleware
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// Login route
	e.POST("/login", login)

	// Unauthenticated route
	e.GET("/", accessible)

	// Restricted group
	r := e.Group("/restricted")

	// Configure middleware with the custom claims type
	config := middleware.JWTConfig{
		Claims:     &jwtCustomClaims{},
		SigningKey: []byte("secret"),
	}
	r.Use(middleware.JWTWithConfig(config))
	r.GET("", restricted)

	e.Run(standard.New(":1323"))
}
開發者ID:AlekSi,項目名稱:echo,代碼行數:26,代碼來源:server.go

示例7: main

func main() {
	e := echo.New()

	// Debug mode
	e.SetDebug(true)

	//-------------------
	// Custom middleware
	//-------------------
	// Stats
	s := NewStats()
	e.Use(s.Process)
	e.GET("/stats", s.Handle) // Endpoint to get stats

	// Server header
	e.Use(ServerHeader)

	// Handler
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})

	// Start server
	e.Run(standard.New(":1323"))
}
開發者ID:AlekSi,項目名稱:echo,代碼行數:25,代碼來源:server.go

示例8: main

func main() {

	demoData := Data{
		Id:   5,
		Name: "User name",
		Tags: []string{"people", "customer", "developer"},
	}

	e := echo.New()
	e.SetDebug(true)
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	s := stats.New()
	e.Use(standard.WrapMiddleware(s.Handler))

	e.GET("/xml", func(c echo.Context) error {
		return c.XML(200, demoData)
	})

	e.GET("/json", func(c echo.Context) error {
		return c.JSON(200, demoData)
	})

	e.GET("/error", func(c echo.Context) error {
		return echo.NewHTTPError(500, "Error here")
	})

	e.Run(standard.New(":8888"))

}
開發者ID:plumbum,項目名稱:go-samples,代碼行數:31,代碼來源:main.go

示例9: main

func main() {
	cfg := readConfig()
	jwtKey := []byte(cfg.JwtKey)

	mongoSession := createMongoSession()
	defer mongoSession.Close()

	db := mongoSession.DB(cfg.Database)
	userCollection := db.C(collections.UserCollectionName)

	e := echo.New()

	e.Get("/ping", func(c echo.Context) error {
		return c.String(http.StatusOK, "pong")
	})

	restService := rest.NewService(db)
	restGroup := e.Group("/collection")
	restGroup.Get("/:collection", restService.Get)
	restGroup.Post("/:collection", restService.Post)
	restGroup.Put("/:collection", restService.Put)
	restGroup.Delete("/:collection", restService.Delete)

	userService := user.NewService(userCollection, jwtKey)
	userGroup := e.Group("/user")
	userGroup.Post("/signup", userService.Signup)
	userGroup.Post("/confirm", userService.ConfirmSignup)
	userGroup.Post("/signin", userService.Signin)
	userGroup.Post("/forgot-password", userService.ForgotPassword)
	userGroup.Post("/reset-password", userService.ResetPassword)

	sessionService := session.NewService(userCollection, jwtKey)
	sessionMiddleware := middleware.CreateSessionMiddleware(userCollection, jwtKey)
	sessionGroup := e.Group("/session", sessionMiddleware)
	sessionGroup.Post("/signout", sessionService.Signout)
	sessionGroup.Post("/change-password", sessionService.ChangePassword)
	sessionGroup.Post("/change-email", sessionService.ChangeEmail)
	sessionGroup.Post("/set-profile", sessionService.SetProfile)

	adminService := admin.NewService(userCollection, jwtKey)
	adminSessionMiddleware := middleware.CreateAdminSessionMiddleware(userCollection, jwtKey)
	adminGroup := e.Group("/admin", adminSessionMiddleware)
	adminGroup.Get("/get-users", adminService.GetUsers)
	adminGroup.Post("/create-user", adminService.CreateUser)
	adminGroup.Post("/change-user-password", adminService.ChangeUserPassword)
	adminGroup.Post("/change-user-email", adminService.ChangeUserEmail)
	adminGroup.Post("/set-user-roles", adminService.SetUserRoles)
	adminGroup.Post("/set-user-profile", adminService.SetUserProfile)
	adminGroup.Delete("/remove-users", adminService.RemoveUsers)
	adminGroup.Post("/signout-users", adminService.SignoutUsers)
	adminGroup.Post("/suspend-users", adminService.SuspendUsers)
	adminGroup.Post("/unsuspend-users", adminService.UnsuspendUsers)
	adminGroup.Delete("/remove-unconfirmed-users", adminService.RemoveUnconfirmedUsers)
	adminGroup.Post("/remove-expired-reset-keys", adminService.RemoveExpiredResetKeys)

	fmt.Println("Listening at http://localhost:5025")
	std := standard.New(":5025")
	std.SetHandler(e)
	graceful.ListenAndServe(std.Server, 5*time.Second)
}
開發者ID:getdiskette,項目名稱:diskette,代碼行數:60,代碼來源:main.go

示例10: main

func main() {
	// 支持根據參數打印版本信息
	global.PrintVersion(os.Stdout)

	savePid()

	logger.Init(ROOT+"/log", ConfigFile.MustValue("global", "log_level", "DEBUG"))

	go ServeBackGround()

	e := echo.New()

	serveStatic(e)

	e.Use(thirdmw.EchoLogger())
	e.Use(mw.Recover())
	e.Use(pwm.Installed(filterPrefixs))
	e.Use(pwm.HTTPError())
	e.Use(pwm.AutoLogin())

	frontG := e.Group("", thirdmw.EchoCache())
	controller.RegisterRoutes(frontG)

	frontG.GET("/admin", echo.HandlerFunc(admin.AdminIndex), pwm.NeedLogin(), pwm.AdminAuth())
	adminG := e.Group("/admin", pwm.NeedLogin(), pwm.AdminAuth())
	admin.RegisterRoutes(adminG)

	std := standard.New(getAddr())
	std.SetHandler(e)

	gracefulRun(std)
}
開發者ID:studygolang,項目名稱:studygolang,代碼行數:32,代碼來源:main.go

示例11: main

func main() {
	e := echo.New()
	e.SetDebug(true)

	// enable any filename to be loaded from in-memory file system
	e.GET("/*", standard.WrapHandler(myEmbeddedFiles.Handler))

	// read ufo.html from in-memory file system
	htmlb, err := myEmbeddedFiles.ReadFile("ufo.html")
	if err != nil {
		log.Fatal(err)
	}

	// convert to string
	html := string(htmlb)

	// serve ufo.html through "/"
	e.GET("/", func(c echo.Context) error {

		// serve it
		return c.HTML(http.StatusOK, html)
	})

	// try it -> http://localhost:1337/
	// http://localhost:1337/ufo.html
	// http://localhost:1337/public/README.md
	open.Run("http://localhost:1337/")
	e.Run(standard.New(":1337"))

}
開發者ID:UnnoTed,項目名稱:fileb0x,代碼行數:30,代碼來源:main.go

示例12: NewServer

func NewServer(
	port uint16,
	registry Registry,
	transferCreator TransferCreator,
) *Server {
	addr := fmt.Sprintf(":%d", port)

	s := &Server{
		addr: addr,

		registry:        registry,
		transferCreator: transferCreator,
	}

	e := echo.New()
	e.Get("/ping", s.handleGetPing)
	e.Get("/version", s.handleGetVersion)
	e.Get("/transfers/:state", s.handleGetTransfers)
	e.Get("/transfer_results", s.handleGetTransferResults)
	e.Get("/transfer_results/:IP", s.handleGetTransferResultsByIP)
	e.Post("/transfers", s.handlePostTransfers)

	s.httpServer = standard.New(addr)
	s.httpServer.SetHandler(e)

	return s
}
開發者ID:glestaris,項目名稱:clique,代碼行數:27,代碼來源:server.go

示例13: main

func main() {
	// Parse command line arguments
	kingpin.Version("0.0.1")
	kingpin.Parse()

	// Prepare (optionally) embedded resources
	templateBox := rice.MustFindBox("template")
	staticHTTPBox := rice.MustFindBox("static").HTTPBox()
	staticServer := http.StripPrefix("/static/", http.FileServer(staticHTTPBox))

	e := echo.New()

	t := &Template{
		templates: template.Must(template.New("base").Parse(templateBox.MustString("base.html"))),
	}
	e.SetRenderer(t)

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.GET("/static/*", standard.WrapHandler(staticServer))

	edit := e.Group("/edit")
	edit.Get("/*", EditHandler)
	edit.Post("/*", EditHandlerPost)

	go WaitForServer()
	e.Run(standard.New(fmt.Sprintf("127.0.0.1:%d", *args.Port)))
}
開發者ID:nochso,項目名稱:gomd,代碼行數:29,代碼來源:gomd.go

示例14: main

func main() {
	e := echo.New()
	e.SetRenderer(common.Template)
	common.InitRoutes(e)
	common.InitPostgres()
	e.Run(standard.New(":8080"))
}
開發者ID:nathana1,項目名稱:FrameworkBenchmarks,代碼行數:7,代碼來源:main.go

示例15: main

func main() {
	// the appengine package provides a convenient method to handle the health-check requests
	// and also run the app on the correct port. We just need to add Echo to the default handler
	s := standard.New(":8080")
	s.SetHandler(e)
	http.Handle("/", s)
	appengine.Main()
}
開發者ID:AlekSi,項目名稱:echo,代碼行數:8,代碼來源:app-managed.go


注:本文中的github.com/labstack/echo/engine/standard.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。