A
A
Artem Prokhorov2021-12-23 18:26:23
go
Artem Prokhorov, 2021-12-23 18:26:23

Is it possible to pass the index of a structure as a pointer to a function?

Something like this:

type Registrat struct {
  Username string `form:"username"`
  Phone    string `form:"phone"`
  Email    string `form:"email"`
  Password string `form:"password"`
  Title    string `form:"title"`
  Age      uint8  `form:"age"`
  Height   uint8  `form:"height"`
  Weight   uint8  `form:"weight"`
  Body     uint8  `form:"body"`
}

func registration(data Registrat) (*Registrat, error) {
  if !isPasswordValid(&data.Password) {
    return &data, errors.New("incorrect password")
  }

  return &data, nil
}

func isPasswordValid(password *Registrat.Password) bool {
  if len(password) < 8 || len(password) > 128 {
    return false
  }
}


Or am I doing something wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2021-12-23
@kotcich

func isPasswordValid(password string) bool {
  if len(password) < 8 || len(password) > 128 {
    return false
  }
  return true
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question