46 lines
998 B
Go
46 lines
998 B
Go
package main
|
|
|
|
import (
|
|
"github.com/go-resty/resty/v2"
|
|
)
|
|
|
|
type RegisterCommand struct {
|
|
Url string `short:"u" long:"url" description:"Url of the instance" required:"true"`
|
|
Login string `short:"l" long:"login" description:"Login" required:"true"`
|
|
Password string `short:"p" long:"password" description:"Password" required:"true"`
|
|
}
|
|
|
|
type RegisterRequest struct {
|
|
Login string `json:"login"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func (c *RegisterCommand) Execute(args []string) error {
|
|
logger.Printf("Registering on %s...\n", c.Url)
|
|
|
|
cli := resty.New().SetBaseURL(c.Url)
|
|
|
|
resp, err := cli.
|
|
R().
|
|
SetError(&ResponseError{}).
|
|
SetBody(&RegisterRequest{c.Login, c.Password}).
|
|
Post("/account/signup")
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if resp.IsError() {
|
|
logger.Println("Registering failed!")
|
|
return resp.Error().(*ResponseError)
|
|
}
|
|
|
|
logger.Println("Registering succeed!")
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
parser.AddCommand("register", "Register", "", &RegisterCommand{})
|
|
}
|