本文整理汇总了Golang中github.com/go-martini/martini.Logger函数的典型用法代码示例。如果您正苦于以下问题:Golang Logger函数的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Logger函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
username, password := waitForPostgres(serviceName)
db, err := postgres.Open(serviceName, fmt.Sprintf("dbname=postgres user=%s password=%s", username, password))
if err != nil {
log.Fatal(err)
}
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(render.Renderer())
m.Action(r.Handle)
m.Map(db)
r.Post("/databases", createDatabase)
r.Get("/ping", ping)
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
if err := discoverd.Register(serviceName+"-api", addr); err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(addr, m))
}
开发者ID:kelsieflynn,项目名称:flynn-postgres,代码行数:30,代码来源:server.go
示例2: launchFrontend
func launchFrontend() {
m := martini.New()
m.Use(martini.Static("static"))
m.Use(martini.Recovery())
m.Use(martini.Logger())
r := martini.NewRouter()
r.Get("/", indexHandler)
r.Get("/following", followHandler)
r.Get("/stat", statHandler)
r.Get("/channel/:streamer", channelHandler)
r.Get("/add/:streamer", addHandler)
r.Get("/del/:streamer", delHandler)
r.Get("/api/stat/:streamer", apiStat)
r.Get("/api/channel/:streamer", apiStat)
r.Get("/api/following", apiFollowing)
db := getDB()
redis := getRedis()
m.Map(db)
m.Map(redis)
m.Action(r.Handle)
log.Print("Started Web Server")
m.Run()
}
开发者ID:grsakea,项目名称:kappastat,代码行数:25,代码来源:web.go
示例3: main
func main() {
m := martini.Classic()
conf := config.LoadConf(martini.Env)
//create new session middleware
store := sessions.NewCookieStore([]byte("MushareSecret"))
store.Options(sessions.Options{
Path: "/",
Domain: conf.App.Host,
MaxAge: 60 * 60 * 60 * 24,
HttpOnly: true,
})
//middleware
m.Handlers(
middlewares.LogOutput,
middlewares.Recovery(),
martini.Logger(),
sessions.Sessions("_session", store),
martini.Static("static", martini.StaticOptions{}),
middlewares.InjectRedis(),
middlewares.InjectDB(),
)
m.Map(conf)
//routers
router.Include(m)
//start server
m.RunOnAddr(conf.App.Host + ":" + conf.App.Port)
}
开发者ID:ts25504,项目名称:MuShare,代码行数:29,代码来源:app.go
示例4: init
func init() {
m = martini.New()
//setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(martini.Static("public"))
}
开发者ID:heltonmarx,项目名称:thermistor,代码行数:7,代码来源:main.go
示例5: main
func main() {
m := martini.Classic()
m.Map(SetupDB())
m.Use(martini.Logger())
m.Use(render.Renderer(render.Options{
Layout: "layout",
}))
store := sessions.NewCookieStore([]byte(CookieSecret))
m.Use(sessions.Sessions("bunkaisession", store))
log.Println("env is", martini.Env)
m.Map(martini.Env)
m.Group("/", func(m martini.Router) {
m.Get("", Home)
}, AssetMap)
m.Group("/api", func(m martini.Router) {
m.Post("/login", PostLogin)
m.Post("/users", UserCreate)
m.Group("/sentences", func(m martini.Router) {
m.Post("", SentenceCreate)
m.Get("", SentenceList)
m.Delete("/:id", SentenceDelete)
}, RequireLogin)
m.Group("/users", func(m martini.Router) {
m.Post("/logout", Logout)
m.Get("/me", UserGet)
}, RequireLogin)
})
m.Run()
}
开发者ID:ukitazume,项目名称:bunkai,代码行数:35,代码来源:server.go
示例6: main
func main() {
conf.Env().Flag()
r := martini.NewRouter()
m := martini.New()
if conf.UBool("debug") {
m.Use(martini.Logger())
}
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
session, err := mgo.Dial(conf.UString("mongo.uri"))
if err != nil {
panic(err)
}
session.SetMode(mgo.Monotonic, true)
db := session.DB(conf.UString("mongodb.database"))
logger := log.New(os.Stdout, "\x1B[36m[cdn] >>\x1B[39m ", 0)
m.Map(logger)
m.Map(db)
r.Group("", cdn.Cdn(cdn.Config{
MaxSize: conf.UInt("maxSize"),
ShowInfo: conf.UBool("showInfo"),
TailOnly: conf.UBool("tailOnly"),
}))
logger.Println("Server started at :" + conf.UString("port", "5000"))
_err := http.ListenAndServe(":"+conf.UString("port", "5000"), m)
if _err != nil {
logger.Printf("\x1B[31mServer exit with error: %s\x1B[39m\n", _err)
os.Exit(1)
}
}
开发者ID:gitter-badger,项目名称:cdn-1,代码行数:34,代码来源:cdn.go
示例7: init
func init() {
m = martini.New()
// I could probably just use martini.Classic() instead of configure these manually
// Static files
m.Use(martini.Static(`public`))
// Setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
// m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// Setup routes
r := martini.NewRouter()
r.Get(`/albums`, server.GetAlbums)
r.Get(`/albums/:id`, server.GetAlbum)
r.Post(`/albums`, server.AddAlbum)
r.Put(`/albums/:id`, server.UpdateAlbum)
r.Delete(`/albums/:id`, server.DeleteAlbum)
// Inject database
m.MapTo(server.DBInstance, (*server.DB)(nil))
// Add the router action
m.Action(r.Handle)
}
开发者ID:ivanbportugal,项目名称:go-albums,代码行数:26,代码来源:main.go
示例8: Start
func Start() {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
// Gitchain API
r.Post("/rpc", jsonRpcService().ServeHTTP)
r.Get("/info", info)
// Git Server
r.Post("^(?P<path>.*)/git-upload-pack$", func(params martini.Params, req *http.Request) string {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return params["path"]
})
r.Post("^(?P<path>.*)/git-receive-pack$", func(params martini.Params, req *http.Request) string {
fmt.Println(req)
return params["path"]
})
r.Get("^(?P<path>.*)/info/refs$", func(params martini.Params, req *http.Request) (int, string) {
body, _ := ioutil.ReadAll(req.Body)
fmt.Println(req, body)
return 404, params["path"]
})
log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", env.Port), m))
}
开发者ID:josephyzhou,项目名称:gitchain,代码行数:34,代码来源:http.go
示例9: init
func init() {
m = martini.New()
//set up middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(auth.Basic(AuthToken, ""))
m.Use(MapEncoder)
// set up routes
r := martini.NewRouter()
r.Get(`/albums`, GetAlbums)
r.Get(`/albums/:id`, GetAlbum)
r.Post(`/albums`, AddAlbum)
r.Put(`/albums/:id`, UpdateAlbum)
r.Delete(`/albums/:id`, DeleteAlbum)
// inject database
// maps db package variable to the DB interface defined in data.go
// The syntax for the second parameter may seem weird,
// it is just converting nil to the pointer-to-DB-interface type,
// because all the injector needs is the type to map the first parameter to.
m.MapTo(db, (*DB)(nil))
// add route action
// adds the router’s configuration to the list of handlers that Martini will call.
m.Action(r.Handle)
}
开发者ID:pyanfield,项目名称:martini_demos,代码行数:28,代码来源:server.go
示例10: main
/*
Application entry point
*/
func main() {
m := martini.New()
//Set middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"OPTIONS", "HEAD", "POST", "GET", "PUT"},
AllowHeaders: []string{"Authorization", "Content-Type"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
//Create the router
r := martini.NewRouter()
//Options matches all and sends okay
r.Options(".*", func() (int, string) {
return 200, "ok"
})
api.SetupTodoRoutes(r)
api.SetupCommentRoutes(r)
mscore.StartServer(m, r)
fmt.Println("Started NSQ Test service")
}
开发者ID:newsquid,项目名称:newsquidtest,代码行数:32,代码来源:main.go
示例11: main
func main() {
var v Vcap
err := json.Unmarshal([]byte(os.Getenv("VCAP_APPLICATION")), &v)
if err != nil {
log.Fatal(err)
}
m := martini.Classic()
app_uri := v.Uris[0]
cfhost := strings.SplitAfterN(app_uri, ".", 2)[1]
oauthOpts := &gooauth2.Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
RedirectURL: "https://" + app_uri + "/oauth2callback",
Scopes: []string{""},
}
cf := oauth2.NewOAuth2Provider(
oauthOpts,
"https://login."+cfhost+"/oauth/authorize",
"http://uaa."+cfhost+"/oauth/token",
)
m.Get("/oauth2error", func() string {
log.Fatal("oAuth error")
return "oAuth error :("
})
m.Handlers(
sessions.Sessions("session", sessions.NewCookieStore([]byte("secret123"))),
cf,
oauth2.LoginRequired,
martini.Logger(),
martini.Static("public"),
)
m.Get("/", func(tokens oauth2.Tokens) string {
if tokens.IsExpired() {
return "Not logged in, or the access token is expired"
}
// oAuth user information from the UAA
body := oauth_get("http://uaa."+cfhost+"/userinfo", tokens)
var u User
err := json.Unmarshal(body, &u)
if err != nil {
log.Fatal(err)
}
// Example actual API call to get the list of spaces the user belongs to
space_body := oauth_get("http://api."+cfhost+"/v2/users/"+u.User_id+"/spaces", tokens)
return fmt.Sprintf("User ID: %s\n\nSpaces info: %s", u.User_id, space_body)
})
m.Run()
}
开发者ID:Jonty,项目名称:cf-oauth-example,代码行数:59,代码来源:main.go
示例12: main
func main() {
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.Use(martini.Static("public"))
r := martini.NewRouter()
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
// Instantiate OAuthService with the OAuth App Client Id & Secret from the Environment Variables
o, err := coinbase.OAuthService(os.Getenv("COINBASE_CLIENT_ID"), os.Getenv("COINBASE_CLIENT_SECRET"), "https://localhost:8443/tokens")
if err != nil {
panic(err)
return
}
// At https://localhost:8443/ we will display an "authorize" link
r.Get("/", func() string {
authorizeUrl := o.CreateAuthorizeUrl([]string{
"user",
"balance",
})
link := "<a href='" + authorizeUrl + "'>authorize</a>"
return link
})
// AuthorizeUrl redirects to https://localhost:8443/tokens with 'code' in its
// query params. If you dont have SSL enabled, replace 'https' with 'http'
// and reload the page. If successful, the user's balance will show
r.Get("/tokens", func(res http.ResponseWriter, req *http.Request) string {
// Get the tokens given the 'code' query param
tokens, err := o.NewTokensFromRequest(req) // Will use 'code' query param from req
if err != nil {
return err.Error()
}
// instantiate the OAuthClient
c := coinbase.OAuthClient(tokens)
amount, err := c.GetBalance()
if err != nil {
return err.Error()
}
return strconv.FormatFloat(amount, 'f', 6, 64)
})
// HTTP
go func() {
if err := http.ListenAndServe(":8080", m); err != nil {
log.Fatal(err)
}
}()
// HTTPS
// To generate a development cert and key, run the following from your *nix terminal:
// go run $(go env GOROOT)/src/pkg/crypto/tls/generate_cert.go --host="localhost"
if err := http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", m); err != nil {
log.Fatal(err)
}
}
开发者ID:jmptrader,项目名称:coinbase-go,代码行数:58,代码来源:OAuthExample.go
示例13: main
func main() {
config, err := config.Load()
if err != nil {
log.Fatal(err)
}
fishhubService, err := fishhub.NewService(config.MongoURL)
if err != nil {
log.Fatal(err)
}
sessionService, err := session.NewService(config.MongoURL)
if err != nil {
log.Fatal(err)
}
store := sessions.NewCookieStore([]byte("@!#$%^&*"))
m := martini.Classic()
m.Map(fishhubService)
m.Map(sessionService)
m.Use(sessions.Sessions("go_session", store))
// Setup routes
m.Get("/", home)
m.Group("/users", func(r martini.Router) {
r.Post("", binding.Bind(UserForm{}), NewUser)
r.Get("/:id", GetUser)
r.Put("/update/:id", UpdateUser)
r.Delete("/delete/:id", DeleteUser)
})
m.Group("/login", func(r martini.Router) {
r.Post("", binding.Bind(LoginForm{}), CheckCredential)
})
m.Handlers(
render.Renderer(render.Options{
Delims: render.Delims{"<%", "%>"},
}),
martini.Logger(),
martini.Static("public"),
)
m.NotFound(func(r render.Render) {
r.HTML(404, "404", nil)
})
err = http.ListenAndServe(":"+config.Port, m)
if err != nil {
log.Fatal(err)
}
}
开发者ID:Alpa-vantage,项目名称:fishhub,代码行数:58,代码来源:main.go
示例14: newMartini
func newMartini() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}
开发者ID:abdulsattar,项目名称:golloquy,代码行数:9,代码来源:app.go
示例15: main
func main() {
c := &gosteno.Config{
Sinks: []gosteno.Sink{
gosteno.NewIOSink(os.Stdout),
},
Level: gosteno.LOG_DEBUG,
Codec: gosteno.NewJsonPrettifier(0),
EnableLOC: true,
}
gosteno.Init(c)
logger := gosteno.NewLogger("atk_instances")
conf := config.NewConfig()
m := martini.Classic()
key, err := atkoauth2.TokenKey(conf.TokenKeyUrl)
if err != nil {
logger.Error(err.Error())
return
}
m.Handlers(
atkoauth2.ResourceServer(key),
martini.Logger(),
render.Renderer(render.Options{IndentJSON: true}),
)
m.Get("/rest/orgs/:id/atkinstances", func(params martini.Params, t *jwt.Token, r render.Render) {
cloudController := cc.NewRestCloudController(conf.ApiUrl, t.Raw)
spaceSummaryHelper := service.NewSpaceSummaryHelper()
srv := service.NewAtkListService(cloudController, spaceSummaryHelper)
if len(conf.CommonService) == 0 {
conf.CommonService = "postgres"
}
//TODO: check id param
instances, err := srv.GetAllInstances(conf.ServiceLabel,
conf.ScoringEngineLabel,
conf.CommonService,
params["id"])
if err != nil {
r.JSON(500, err.Error())
}
r.JSON(200, instances)
})
m.Run()
}
开发者ID:blkrs,项目名称:app-launcher-helper,代码行数:56,代码来源:main.go
示例16: getSilentMartini
// getSilentMartini returns a ClassicMartini with logging disabled.
func getSilentMartini() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
if *verboseMartini {
m.Use(martini.Logger())
}
m.Use(martini.Recovery())
m.Use(martini.Static("public"))
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}
开发者ID:ivanol,项目名称:go-martini-api,代码行数:13,代码来源:helpers_test.go
示例17: newClassic
func newClassic() *martini.ClassicMartini {
r := martini.NewRouter()
m := martini.New()
// 日志
if Conf.Debug {
m.Use(martini.Logger())
}
// 捕获所有错误
m.Use(martini.Recovery())
// 静态处理
m.Use(martini.Static(Conf.StaticDir, Conf.StaticOptions))
// Session
store, _ := sessions.NewRediStore(10, "tcp", Conf.RedisAddress, "", []byte(Conf.SessionSecret))
store.Options(Conf.SessionOptions)
m.Use(sessions.Sessions(Conf.SessionName, store))
// csrf
m.Use(csrf.CsrfInstance.Generate(Conf.CsrfOptions))
// 缓存中间件
m.Use(func(c martini.Context, req *http.Request, w http.ResponseWriter) {
// 覆写ResponseWriter接口
res := Lib.Http.NewResponseWriter(req, w)
c.MapTo(res, (*http.ResponseWriter)(nil))
// Api请求
if strings.HasPrefix(req.URL.String(), "/api") {
// 响应类型:Json
w.Header().Set("Content-Type", "application/json; charset=utf-8")
// GET请求读取缓存
if !Conf.Debug && req.Method == "GET" {
// 缓存没过期
if cache, err := redis.RedisInstance.Get("url-" + req.URL.String()); err == nil {
w.Write(cache)
return
}
}
} else {
// 其他类型请求响应类型:Html
w.Header().Set("Content-Type", "text/html; charset=utf-8")
}
})
// 返回可以直接调用的路由
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return &martini.ClassicMartini{m, r}
}
开发者ID:tmchojo,项目名称:as,代码行数:53,代码来源:martini.go
示例18: main
func main() {
m := martini.New()
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(render.Renderer())
r := conf.Router()
m.MapTo(r, (*martini.Router)(nil))
m.Action(r.Handle)
m.Run()
}
开发者ID:kosuda,项目名称:martini-test,代码行数:13,代码来源:main.go
示例19: NewServer
func NewServer() *Server {
s := &Server{}
r := martini.NewRouter()
r.Get("/ping", s.Ping)
r.Post("/exec", s.ExecCommand)
r.Put("/upload", s.PutFile)
m := martini.New()
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
s.m = m
return s
}
开发者ID:jsternberg,项目名称:ansible-agent,代码行数:15,代码来源:server.go
示例20: makeDirtyMartini
func makeDirtyMartini() (*martini.Martini, martini.Router) {
r := martini.NewRouter()
m := martini.New()
m.Use(func(c martini.Context, req *http.Request) {
c.MapTo(appengine.NewContext(req), (*appengine.Context)(nil))
})
m.Use(martini.Logger())
m.Use(martini.Recovery())
m.MapTo(r, (*martini.Routes)(nil))
m.Action(r.Handle)
return m, r
}
开发者ID:riannucci,项目名称:fish_basket,代码行数:15,代码来源:routes.go
注:本文中的github.com/go-martini/martini.Logger函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论