town/cmd/request/main.go

61 lines
987 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
2022-07-30 13:39:48 +00:00
"git.tilde.town/tildetown/town/request"
2021-04-24 20:35:02 +00:00
townUser "git.tilde.town/tildetown/town/user"
)
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
2022-07-30 13:42:33 +00:00
err = request.ProcessGitea(request.RequestPath)
2021-04-27 16:14:15 +00:00
if err != nil {
errs = append(errs, err)
}
2022-07-30 13:42:33 +00:00
err = request.ProcessGemini(request.RequestPath)
2021-04-27 16:14:15 +00:00
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)
}