main.go 1.4 KB

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