main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "github.com/kataras/iris/v12"
  4. "github.com/kataras/iris/v12/middleware/accesslog"
  5. "xps/bootstrap"
  6. "xps/web/middleware/identity"
  7. "xps/web/router"
  8. )
  9. const maxSize = 20 * 1024 * 1024
  10. func newApp() *bootstrap.Bootstrapper {
  11. app := bootstrap.New("web", "yafeng")
  12. app.Bootstrap()
  13. //ac := makeAccessLog()
  14. //defer ac.Close()
  15. //app.UseRouter(ac.Handler)
  16. app.Configure(identity.Configure, router.Configure)
  17. return app
  18. }
  19. // Read the example and its comments carefully.
  20. func makeAccessLog() *accesslog.AccessLog {
  21. // Initialize a new access log middleware.
  22. ac := accesslog.File("./access.log")
  23. // Remove this line to disable logging to console:
  24. //ac.AddOutput(os.Stdout)
  25. // The default configuration:
  26. ac.Delim = '|'
  27. ac.TimeFormat = "2006-01-02 15:04:05"
  28. ac.Async = false
  29. ac.IP = true
  30. ac.BytesReceivedBody = true
  31. ac.BytesSentBody = true
  32. ac.BytesReceived = false
  33. ac.BytesSent = false
  34. ac.BodyMinify = true
  35. ac.RequestBody = true
  36. ac.ResponseBody = false
  37. ac.KeepMultiLineError = true
  38. ac.PanicLog = accesslog.LogHandler
  39. // Default line format if formatter is missing:
  40. // Time|Latency|Code|Method|Path|IP|Path Params Query Fields|Bytes Received|Bytes Sent|Request|Response|
  41. //
  42. // Set Custom Formatter:
  43. ac.SetFormatter(&accesslog.JSON{
  44. Indent: " ",
  45. HumanTime: true,
  46. })
  47. return ac
  48. }
  49. func main() {
  50. app := newApp()
  51. app.Listen(":8001", iris.WithPostMaxMemory(maxSize))
  52. }