本文整理匯總了Golang中github.com/codegangsta/negroni.Classic函數的典型用法代碼示例。如果您正苦於以下問題:Golang Classic函數的具體用法?Golang Classic怎麽用?Golang Classic使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Classic函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
host := os.Getenv("HOST")
templates.Init("templates")
// models.InitDb(os.Getenv("DATABASE_URL"))
// addon.Init(os.Getenv("HEROKU_ID"), os.Getenv("HEROKU_API_PASSWORD"), os.Getenv("HEROKU_SSO_SALT"))
r := mux.NewRouter()
// new(controllers.AccountsController).Init(r)
// new(controllers.HerokuResourcesController).Init(r)
new(controllers.HomeController).Init(r)
// new(controllers.ImagesController).Init(r)
new(controllers.TestController).Init(r)
// new(controllers.SessionsController).Init(r)
// new(controllers.SsoSessionsController).Init(r)
r.PathPrefix("/").Handler(http.FileServer(http.Dir("static")))
n := negroni.Classic()
n.UseHandler(r)
n.Run(host + ":" + port)
}
示例2: main
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", IndexController)
n := negroni.Classic()
n.UseHandler(mux)
n.Run(fmt.Sprintf(":%s", os.Getenv("PORT")))
}
示例3: Start
func Start(port int, fileLocation string) {
var router routers.Router
var graph inject.Graph
// Create database
db := data.NewJsonDB(fileLocation)
// Setup DI
if err := graph.Provide(
&inject.Object{Value: db},
&inject.Object{Value: repositories.NewCharacterRepository()},
&inject.Object{Value: &router}); err != nil {
log.Fatalf("Error providing dependencies: ", err.Error())
}
if err := graph.Populate(); err != nil {
log.Fatalf("Error populating dependencies: ", err.Error())
}
n := negroni.Classic()
n.UseHandler(router.NewRouter())
err := http.ListenAndServe(fmt.Sprintf(":%v", port), n)
if err != nil {
panic("Error: " + err.Error())
}
}
示例4: Serve
// Serve set the route handlers and serve
func Serve() {
// Setup middleware
middle := negroni.Classic()
store := cookiestore.New([]byte("keyboard cat"))
middle.Use(sessions.Sessions("hugoku", store))
router := httprouter.New()
router.GET("/", routes.Index)
router.GET("/auth/login", routes.GithubLogin)
router.GET("/auth/logout", routes.GithubLogout)
router.GET("/auth/callback", routes.GithubLoginCallback)
router.GET("/project/:id", routes.GetProject)
router.POST("/project", routes.PostProject)
router.DELETE("/project/:id", routes.DeleteProject)
router.GET("/about", routes.About)
router.GET("/faq", routes.FAQ)
// Apply middleware to the router
middle.UseHandler(router)
log.Println("Started running on http://127.0.0.1:8080")
// TODO: Get the port from flag, config file or environment var
log.Fatal(http.ListenAndServe(":8080", middle))
}
示例5: New
func New(tug *tugboat.Tugboat, config Config) http.Handler {
r := mux.NewRouter()
// auth is a function that can wrap an http.Handler with authentication.
auth := newAuthenticator(config)
// Mount GitHub webhooks
g := github.New(tug, config.GitHub.Secret)
r.MatcherFunc(githubWebhook).Handler(g)
// Mount the API.
a := api.New(tug, api.Config{
Auth: auth,
Secret: config.GitHub.Secret,
})
r.Headers("Accept", api.AcceptHeader).Handler(a)
// Pusher authentication.
p := auth(&pusherauth.Handler{
Key: config.Pusher.Key,
Secret: []byte(config.Pusher.Secret),
})
r.Handle("/pusher/auth", p)
// Fallback to serving the frontend.
f := frontend.New("")
f.PusherKey = config.Pusher.Key
r.NotFoundHandler = auth(f)
n := negroni.Classic()
n.UseHandler(r)
return n
}
示例6: main
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
host := os.Getenv("HOST")
templates.Init("templates")
models.InitDb(os.Getenv("DATABASE_URL"))
addon.Init(os.Getenv("HEROKU_ID"), os.Getenv("HEROKU_API_PASSWORD"), os.Getenv("HEROKU_SSO_SALT"))
rand.Seed(time.Now().UTC().UnixNano())
r := mux.NewRouter()
r.SkipClean(true) // have to use whatupdave/mux until Gorilla supports this
new(controllers.AccountsController).Init(r)
new(controllers.HerokuResourcesController).Init(r)
new(controllers.HomeController).Init(r)
new(controllers.ImagesController).Init(r)
new(controllers.RegistrationsController).Init(r)
new(controllers.SessionsController).Init(r)
new(controllers.SsoSessionsController).Init(r)
r.PathPrefix("/").Handler(http.FileServer(http.Dir("static")))
n := negroni.Classic()
n.UseHandler(r)
n.Run(host + ":" + port)
}
示例7: StartNegroniServer
func StartNegroniServer() {
mux := http.NewServeMux()
mux.HandleFunc("/", index)
n := negroni.Classic()
n.UseHandler(mux)
n.Run(":8080")
}
示例8: Test_LogoutOnAccessTokenExpiration
func Test_LogoutOnAccessTokenExpiration(t *testing.T) {
recorder := httptest.NewRecorder()
s := sessions.NewCookieStore([]byte("secret123"))
n := negroni.Classic()
n.Use(sessions.Sessions("my_session", s))
n.Use(Google(
goauth2.Client("foo", "foo"),
goauth2.RedirectURL("foo"),
))
mux := http.NewServeMux()
mux.HandleFunc("/addtoken", func(w http.ResponseWriter, req *http.Request) {
SetToken(req, "dummy token")
fmt.Fprintf(w, "OK")
})
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
tok := GetToken(req)
if tok != nil {
t.Errorf("User not logged out although access token is expired. %v\n", tok)
}
})
n.UseHandler(mux)
addtoken, _ := http.NewRequest("GET", "/addtoken", nil)
index, _ := http.NewRequest("GET", "/", nil)
n.ServeHTTP(recorder, addtoken)
n.ServeHTTP(recorder, index)
}
示例9: Test_SessionsDeleteValue
func Test_SessionsDeleteValue(t *testing.T) {
n := negroni.Classic()
store := cookiestore.New([]byte("secret123"))
n.Use(sessions.Sessions("my_session", store))
mux := http.NewServeMux()
mux.HandleFunc("/testsession", func(w http.ResponseWriter, req *http.Request) {
session := sessions.GetSession(req)
session.Set("hello", "world")
session.Delete("hello")
fmt.Fprintf(w, "OK")
})
mux.HandleFunc("/show", func(w http.ResponseWriter, req *http.Request) {
session := sessions.GetSession(req)
if session.Get("hello") == "world" {
t.Error("Session value deleting failed")
}
fmt.Fprintf(w, "OK")
})
n.UseHandler(mux)
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/testsession", nil)
n.ServeHTTP(res, req)
res2 := httptest.NewRecorder()
req2, _ := http.NewRequest("GET", "/show", nil)
req2.Header.Set("Cookie", res.Header().Get("Set-Cookie"))
n.ServeHTTP(res2, req2)
}
示例10: main
func main() {
configMiddleware, err := NewConfigMiddleware("config.toml")
if err != nil {
panic("Unable to open config file. Please check its path.")
}
dbMiddleware, err := NewDatabaseMiddleware("sqlite3", "database.db")
if err != nil {
panic("Unable to open database. Please check its path.")
}
host := configMiddleware.Host + ":" + strconv.Itoa(configMiddleware.Port)
r := mux.NewRouter()
r.HandleFunc("/", indexHandler)
r.HandleFunc("/upload", uploadHandler)
n := negroni.Classic()
n.Use(configMiddleware)
n.Use(dbMiddleware)
n.UseHandler(r)
n.Run(host)
}
示例11: main
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
sd, err := splattus.Lookup()
if err != nil {
http.Error(rw, err.Error(), 500)
return
}
data, err := json.Marshal([]string{
splattus.Englishify(sd[0].Stages[0]),
splattus.Englishify(sd[0].Stages[1]),
})
if err != nil {
http.Error(rw, err.Error(), 500)
return
}
rw.Write(data)
})
n := negroni.Classic()
n.UseHandler(mux)
http.ListenAndServe(":5000", n)
}
示例12: main
func main() {
// Instantiate a new router
r := httprouter.New()
n := negroni.Classic()
// Get a UserController instance
// uc := controllers.NewUserController(getSession())
// cc := controllers.NewCustomerController(getSession())
//
// // Get a user resource
// r.GET("/user/:id", uc.GetUser)
// r.GET("/customer/:id",cc.GetCustomer)
//
// // Create a new user
// r.POST("/user", uc.CreateUser)
// r.POST("/customer",cc.CreateCustomer)
//
// r.PUT("/customer/:id",cc.UpdateCustomer)
//
// // Remove an existing user
// r.DELETE("/user/:id", uc.RemoveUser)
// r.DELETE("/customer/:id",cc.RemoveCustomer)
// Fire up the server
r.HandlerFunc("GET", "/login", getToken)
r.Handler("GET", "/api",
negroni.New(negroni.HandlerFunc(AuthMiddleware1), negroni.HandlerFunc(APIHandler1), negroni.Handler(CreateCustomer1)))
// r.Handler("POST","/customer",
// negroni.New(negroni.HandlerFunc(AuthMiddleware1),negroni.HandlerFunc(APIHandler1),cc.CreateCustomer))
n.UseHandler(r)
http.ListenAndServe("localhost:8080", n)
}
示例13: main
func main() {
resolver, err := NewServiceResolver("192.168.99.100:8500")
if err != nil {
panic(err)
}
fmt.Printf("Starting Colour service....")
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
url, err := resolver.ResolveHttpUrl("name", "")
if err != nil {
panic(err)
}
resp, err := http.Get(url)
if err == nil {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err == nil {
svcName := os.Getenv("service-name")
fmt.Fprintf(w, "Hello, %s! from %s", body, svcName)
return
}
}
fmt.Fprintf(w, "Hello, unknown!")
})
n := negroni.Classic()
n.UseHandler(mux)
n.Run(":3000")
}
示例14: main
func main() {
mux := http.NewServeMux()
renderer := render.New(render.Options{
IndentJSON: true,
IsDevelopment: true,
Funcs: []template.FuncMap{prepareTemplateMap()},
})
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
TorrentHandler(w, r, renderer)
}
})
mux.HandleFunc("/showDiskSpace", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
ShowDiskSpaceHandler(w, r)
}
})
mux.HandleFunc("/listDownloads", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
ListDownloadsHandler(w, r, renderer)
}
})
n := negroni.Classic()
n.UseHandler(mux)
//n.Run(":3001")
go func() {
log.Fatal(http.ListenAndServe(plainPort, http.HandlerFunc(redirectToHTTPS)))
}()
log.Fatal(http.ListenAndServeTLS(sslPort, "cert_dietpi.pem", "key_dietpi.pem", n))
}
示例15: main
func main() {
if len(os.Args) != 3 {
fmt.Println("usage: copyweb [dir] [http://weburl(client) or port number(server)]")
os.Exit(1)
}
path := "./" + os.Args[1]
if strings.HasPrefix(os.Args[2], "http://") {
if _, err := os.Stat(path); os.IsNotExist(err) {
os.MkdirAll(path, 0666)
}
GetWeb()
} else {
if _, err := os.Stat(path); os.IsNotExist(err) {
fmt.Println("dir ", os.Args[1], " does not exist")
os.Exit(1)
}
port, err := strconv.Atoi(os.Args[2])
if err != nil || port < 1 || port > 65535 {
fmt.Println("port number wrong.")
os.Exit(1)
}
if jd, err := ioutil.ReadFile(os.Args[1] + ".map"); err == nil {
if json.Unmarshal(jd, &mapData) != nil {
fmt.Println("Loading map file failed")
}
}
var r = mux.NewRouter()
r.HandleFunc("/{url:.*}", SetWeb)
n := negroni.Classic()
n.UseHandler(r)
n.Run(":" + strconv.Itoa(port))
}
}