forked from tildetown/town
41 lines
582 B
Go
41 lines
582 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.tilde.town/tildetown/town/towndb"
|
|
)
|
|
|
|
func _main(args []string) error {
|
|
if len(args) < 2 {
|
|
return errors.New("need email")
|
|
}
|
|
email := args[1]
|
|
|
|
db, err := towndb.ConnectDB()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
user, err := towndb.UserForEmail(db, email)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if user == nil {
|
|
return errors.New("email does not correspond to user")
|
|
}
|
|
|
|
fmt.Print(user.Username)
|
|
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
if err := _main(os.Args); err != nil {
|
|
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|