start on dedicated 'request' command

pull/1/head
vilmibm 2021-04-24 20:35:02 +00:00
parent c965c578bf
commit d29fabfa52
1 changed files with 87 additions and 0 deletions

87
request/main.go 100644
View File

@ -0,0 +1,87 @@
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
//email "git.tilde.town/tildetown/town/email"
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{}
errs = append(errs, processGitea(requestPath))
errs = append(errs, processGemini(requestPath))
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)
}
func processGitea(rp string) error {
return nil
}
func processGemini(requestRootPath string) error {
rp := filepath.Join(requestRootPath, "gemini")
files, err := ioutil.ReadDir(rp)
if err != nil {
return fmt.Errorf("failed to list directory %s: %w", rp, err)
}
usernames := []string{}
for _, file := range files {
usernames = append(usernames, file.Name())
}
if len(usernames) == 0 {
return nil
}
for _, username := range usernames {
// TODO check for public_gemini already in their home dir
// TODO create publiC_gemini
// TODO check for existing symlink
// TODO create symlink
}
return nil
}