- Timestamp:
- Apr 17, 2025, 6:18:24 PM (7 weeks ago)
- Location:
- trunk/cmd
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cmd/mai/main.go
r70 r71 13 13 "syscall" 14 14 15 "ma risa.chaotic.ninja/mai"16 "ma risa.chaotic.ninja/mai/engines"15 "mahou-no-mori.yakumo.dev/mai" 16 "mahou-no-mori.yakumo.dev/mai/engines" 17 17 18 18 "github.com/gofiber/fiber/v2" … … 25 25 var ( 26 26 configfile string 27 groupname string 28 username string 27 verbose bool 29 28 ) 30 29 var conf struct { 31 danmaku int30 group string 32 31 listen string 33 staticpath string 34 tmplpath string 32 requests int 33 static string 34 templates string 35 user string 35 36 } 36 37 func MaiSkipLimiter(c *fiber.Ctx) bool { 37 38 // Paths listed here are not considered for rate limiting 38 39 path := c.Path() 39 return strings.HasPrefix(path, "/static") || 40 strings.HasPrefix(path, "/docs") 40 return strings.HasPrefix(path, "/static") 41 41 } 42 42 func main() { 43 43 parseFlags() 44 44 45 conf.listen = "127.0.0.1:5000" 46 conf.requests = 5 47 conf.static = "./static" 48 conf.templates = "./views" 49 45 50 if configfile != "" { 51 if verbose { 52 log.Printf("Reading configuration from %s", configfile) 53 } 46 54 readConf(configfile) 47 55 } 48 56 49 // Default settings 50 conf.danmaku = 10 51 conf.listen = "127.0.0.1:5000" 52 conf.staticpath = "./static" 53 conf.tmplpath = "./views" 54 55 if username != "" { 56 uid, gid, err := usergroupids(username, groupname) 57 if conf.user != "" { 58 uid, gid, err := usergroupids(conf.user, conf.group) 57 59 if err != nil { 58 60 log.Fatal(err) … … 62 64 } 63 65 64 engine := html.New(conf.t mplpath, ".html")66 engine := html.New(conf.templates, ".html") 65 67 engine.AddFunc("inc", func(i int) int { return i + 1 }) 66 68 … … 86 88 server.Use(favicon.New( 87 89 favicon.Config{ 88 File: conf.static path+ "/favicon.ico",90 File: conf.static + "/favicon.ico", 89 91 }, 90 92 )) … … 101 103 server.Use(limiter.New(limiter.Config{ 102 104 Next: MaiSkipLimiter, 103 Max: conf. danmaku,105 Max: conf.requests, 104 106 Expiration: 30 * time.Second, 105 107 LimiterMiddleware: limiter.SlidingWindow{}, … … 297 299 298 300 server.Get("/toomanyrequests", func(c *fiber.Ctx) error { 299 return c.SendFile(conf.t mplpath+ "/429.html")301 return c.SendFile(conf.templates + "/429.html") 300 302 return c.SendStatus(429) 301 303 }) … … 326 328 return c.Redirect("/") 327 329 }) 328 server.Static("/static", conf.staticpath, fiber.Static{ 329 Compress: true, 330 server.Static("/static", conf.static, fiber.Static{ 330 331 ByteRange: true, 331 332 Browse: true, 332 333 }) 333 334 334 server.Static("/docs", "./docs", fiber.Static{})335 336 335 server.Listen(conf.listen) 337 336 } -
trunk/cmd/mai/parseflags.go
r67 r71 8 8 func parseFlags() { 9 9 flag.StringVar(&configfile, "f", "", "Configuration file") 10 flag.StringVar(&username, "u", "", "Sets the user to which privilege dropping is done") 11 flag.StringVar(&groupname, "g", "", "Sets the group to which privilege dropping is done") 10 flag.BoolVar(&verbose, "v", false, "Be verbose") 12 11 flag.Parse() 13 12 } -
trunk/cmd/mai/readconf.go
r70 r71 11 11 return err 12 12 } 13 conf.danmaku, _ = cfg.Section("mai").Key("danmaku").Int()14 conf.listen = cfg.Section("mai").Key("listen").String()15 conf.staticpath = cfg.Section("mai").Key("static").String()16 conf.tmplpath = cfg.Section("mai").Key("templates").String()17 13 14 conf.group = cfg.Section("mai").Key("group").String() 15 conf.listen = cfg.Section("http").Key("listen").String() 16 conf.requests, _ = cfg.Section("http").Key("requests").Int() 17 conf.static = cfg.Section("paths").Key("static").String() 18 conf.templates = cfg.Section("paths").Key("templates").String() 19 conf.user = cfg.Section("mai").Key("user").String() 18 20 return nil 19 21 }
Note:
See TracChangeset
for help on using the changeset viewer.