Sobes.tech
Senior

Let's start writing the structure — what do we need in this structure?

sobes.tech AI

Answer from AI

When designing a structure in Go, it is important to consider what data and behavior it will encapsulate. Typically, a struct defines fields that reflect the object's state, as well as methods to work with that state.

What you will need:

  • Fields with the necessary data types (e.g., strings, numbers, slices, other structs).
  • Tags for serialization (json, db), if the struct will be used for data exchange.
  • Methods implementing business logic or interfaces.

Example:

Type User struct {
    ID    int    `json:"id"`
    Name  string `json:"name"`
    Email string `json:"email"`
}

func (u *User) UpdateEmail(newEmail string) {
    u.Email = newEmail
}

It is important to think about which fields should be exported (with an uppercase letter) and which should not, to control access to the data.

Let's start writing the structure — what do we need… - sobes.tech