今すぐv1をリリースすべきでしょうか?
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/mai/trunk@63 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
This commit is contained in:
parent
dc9a839f54
commit
b10a5036d8
5
Makefile
5
Makefile
@ -1,7 +1,10 @@
|
||||
PREFIX ?= /usr/local
|
||||
GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT}"
|
||||
VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "VERSION"`
|
||||
COMMIT = `git rev-parse --short HEAD || echo "COMMIT"`
|
||||
|
||||
build:
|
||||
go build -v ./cmd/mai
|
||||
go build ${GOFLAGS} ./cmd/mai
|
||||
clean:
|
||||
rm -f mai
|
||||
install:
|
||||
|
@ -7,5 +7,6 @@ import (
|
||||
|
||||
func parseFlags() {
|
||||
flag.StringVar(&configfile, "f", "", "Configuration file")
|
||||
flag.BoolVar(&verbose, "v", false, "Verbose logging")
|
||||
flag.Parse()
|
||||
}
|
||||
|
@ -2,13 +2,17 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"marisa.chaotic.ninja/mai"
|
||||
"marisa.chaotic.ninja/mai/engines"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||||
@ -16,17 +20,22 @@ import (
|
||||
)
|
||||
var (
|
||||
configfile string
|
||||
verbose bool
|
||||
)
|
||||
var conf struct {
|
||||
group string
|
||||
listen string
|
||||
redisuri string
|
||||
staticpath string
|
||||
tmplpath string
|
||||
user string
|
||||
}
|
||||
func main() {
|
||||
parseFlags()
|
||||
|
||||
if configfile != "" {
|
||||
if verbose {
|
||||
fmt.Printf("[mai] Reading configuration file")
|
||||
}
|
||||
readConf(configfile)
|
||||
}
|
||||
|
||||
@ -35,6 +44,19 @@ func main() {
|
||||
conf.staticpath = "./static"
|
||||
conf.tmplpath = "./views"
|
||||
|
||||
if conf.user != "" {
|
||||
if verbose {
|
||||
fmt.Printf("[mai] Dropping privileges to %s", conf.user)
|
||||
}
|
||||
uid, gid, err := usergroupids(conf.user, conf.group)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
syscall.Setuid(uid)
|
||||
syscall.Setgid(gid)
|
||||
}
|
||||
|
||||
engine := html.New(conf.tmplpath, ".html")
|
||||
engine.AddFunc("inc", func(i int) int { return i + 1 })
|
||||
|
||||
@ -265,4 +287,9 @@ func main() {
|
||||
Browse: true,
|
||||
})
|
||||
app.Listen(conf.listen)
|
||||
|
||||
if verbose {
|
||||
fmt.Printf("Starting mai %v\n", mai.FullVersion())
|
||||
fmt.Printf("Listening on %s", conf.listen)
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ func readConf(file string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
conf.group = cfg.Section("mai").Key("group").String()
|
||||
conf.listen = cfg.Section("mai").Key("listen").String()
|
||||
conf.staticpath = cfg.Section("mai").Key("static").String()
|
||||
conf.tmplpath = cfg.Section("mai").Key("templates").String()
|
||||
conf.user = cfg.Section("mai").Key("user").String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
25
cmd/mai/usergroupids.go
Normal file
25
cmd/mai/usergroupids.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func usergroupids(username string, groupname string) (int, int, error) {
|
||||
u, err := user.Lookup(username)
|
||||
if err != nil {
|
||||
return -1, -1, err
|
||||
}
|
||||
|
||||
uid, _ := strconv.Atoi(u.Uid)
|
||||
gid, _ := strconv.Atoi(u.Gid)
|
||||
|
||||
if conf.group != "" {
|
||||
g, err := user.LookupGroup(groupname)
|
||||
if err != nil {
|
||||
return uid, -1, err
|
||||
}
|
||||
gid, _ = strconv.Atoi(g.Gid)
|
||||
}
|
||||
return uid, gid, nil
|
||||
}
|
4
doc.go
Normal file
4
doc.go
Normal file
@ -0,0 +1,4 @@
|
||||
// Package mai is an usable frontend for popular translation engines
|
||||
// Originally based on SimplyTranslate, and took inspiration from the following projects:
|
||||
// Partage, PixivFE, etc.
|
||||
package mai
|
@ -7,6 +7,9 @@
|
||||
.Sh OPTIONS
|
||||
.Ss [mai] section
|
||||
.Bl -tag -width 11n
|
||||
.It group
|
||||
Group ID for dropping privileges to.
|
||||
If unset, assume the GID of user
|
||||
.It listen
|
||||
HTTP port for the server to listen.
|
||||
Default is "localhost:5000"
|
||||
@ -16,6 +19,8 @@ Default is "./static"
|
||||
.It templates
|
||||
Directory where the templates are located.
|
||||
Default is "./views"
|
||||
.It user
|
||||
User ID for dropping privileges to.
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width 11n
|
||||
|
18
version.go
Normal file
18
version.go
Normal file
@ -0,0 +1,18 @@
|
||||
package mai
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version release version
|
||||
Version = "0.0.1"
|
||||
|
||||
// Commit will be overwritten automatically by the build system
|
||||
Commit = "HEAD"
|
||||
)
|
||||
|
||||
// FullVersion display the full version and build
|
||||
func FullVersion() string {
|
||||
return fmt.Sprintf("%s@%s", Version, Commit)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user