town/request/main.go

62 lines
952 B
Go
Raw Normal View History

2021-04-24 20:35:02 +00:00
package main
import (
"errors"
"fmt"
"os"
"os/user"
2021-04-27 16:14:15 +00:00
2021-04-24 20:35:02 +00:00
townUser "git.tilde.town/tildetown/town/user"
)
const requestPath = "/town/requests"
func _main(args []string) error {
currentUser, err := user.Current()
if err != nil {
return err
}
ok, err := townUser.IsAdmin(currentUser)
if err != nil {
return err
}
if !ok {
return errors.New("must be a town admin")
}
errs := []error{}
2021-04-27 16:14:15 +00:00
err = processGitea(requestPath)
if err != nil {
errs = append(errs, err)
}
err = processGemini(requestPath)
if err != nil {
errs = append(errs, err)
}
2021-04-24 20:35:02 +00:00
if len(errs) > 0 {
errMsg := "errors encountered during request processing: "
for _, e := range errs {
errMsg += e.Error() + " "
}
return fmt.Errorf("errors encountered during request processing: %s", errMsg)
}
return nil
}
func main() {
retcode := 0
err := _main(os.Args)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
retcode = 1
}
os.Exit(retcode)
}