Changeset 63 in code for trunk/cmd


Ignore:
Timestamp:
Jan 21, 2024, 3:23:44 AM (17 months ago)
Author:
yakumo.izuru
Message:

今すぐv1をリリースすべきでしょうか?

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

Location:
trunk/cmd/mai
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/mai/flag.go

    r59 r63  
    88func parseFlags() {
    99        flag.StringVar(&configfile, "f", "", "Configuration file")
     10        flag.BoolVar(&verbose, "v", false, "Verbose logging")
    1011        flag.Parse()
    1112}
  • trunk/cmd/mai/main.go

    r62 r63  
    33import (
    44        "bytes"
     5        "fmt"
    56        "net/http"
    67        "net/url"
     
    89        "time"
    910        "runtime"
    10 
     11        "syscall"
     12
     13        "marisa.chaotic.ninja/mai"
    1114        "marisa.chaotic.ninja/mai/engines"
     15
    1216        "github.com/gofiber/fiber/v2"
    1317        "github.com/gofiber/fiber/v2/middleware/logger"
     
    1721var (
    1822        configfile string
     23        verbose bool
    1924)
    2025var conf struct {
     26        group string
    2127        listen string
    22         redisuri string
    2328        staticpath string
    2429        tmplpath string
     30        user string
    2531}
    2632func main() {
     
    2834
    2935        if configfile != "" {
     36                if verbose {
     37                        fmt.Printf("[mai] Reading configuration file")
     38                }
    3039                readConf(configfile)
    3140        }
     
    3544        conf.staticpath = "./static"
    3645        conf.tmplpath = "./views"
     46
     47        if conf.user != "" {
     48                if verbose {
     49                        fmt.Printf("[mai] Dropping privileges to %s", conf.user)
     50                }
     51                uid, gid, err := usergroupids(conf.user, conf.group)
     52                if err != nil {
     53                        fmt.Println(err)
     54                        os.Exit(1)
     55                }
     56                syscall.Setuid(uid)
     57                syscall.Setgid(gid)
     58        }
    3759       
    3860        engine := html.New(conf.tmplpath, ".html")
     
    266288        })
    267289        app.Listen(conf.listen)
     290
     291        if verbose {
     292                fmt.Printf("Starting mai %v\n", mai.FullVersion())
     293                fmt.Printf("Listening on %s", conf.listen)
     294        }
    268295}
  • trunk/cmd/mai/readconf.go

    r61 r63  
    1212        }
    1313
     14        conf.group = cfg.Section("mai").Key("group").String()
    1415        conf.listen = cfg.Section("mai").Key("listen").String()
    1516        conf.staticpath = cfg.Section("mai").Key("static").String()
    1617        conf.tmplpath = cfg.Section("mai").Key("templates").String()
     18        conf.user = cfg.Section("mai").Key("user").String()
    1719
    1820        return nil
Note: See TracChangeset for help on using the changeset viewer.