本文整理匯總了Golang中github.com/go-martini/martini.Logger函數的典型用法代碼示例。如果您正苦於以下問題:Golang Logger函數的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Logger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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))
}
示例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()
}
示例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)
}
示例4: init
func init() {
m = martini.New()
//setup middleware
m.Use(martini.Recovery())
m.Use(martini.Logger())
m.Use(martini.Static("public"))
}
示例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()
}
示例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)
}
}
示例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)
}
示例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))
}
示例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)
}
示例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")
}
示例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()
}
示例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)
}
}
示例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)
}
}
示例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}
}
示例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()
}