package main import ( "github.com/go-resty/resty/v2" photosapi "gitlab.celogeek.com/photos/api/internal/photos/api" ) 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"` } 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(&photosapi.ErrorWithDetails{}). SetBody(&photosapi.SignupRequest{ Login: c.Login, Password: c.Password, }). Post("/account/signup") if err != nil { return err } if resp.IsError() { logger.Println("Registering failed!") return resp.Error().(*photosapi.ErrorWithDetails) } logger.Println("Registering succeed!") return nil } func init() { parser.AddCommand("register", "Register", "", &RegisterCommand{}) }