How to assign a default image to a user account in GO?

0

I am creating a user login, but I want to create a user image, as a base image, when I create the created user, by this I mean for example facebook , that at At the moment you create an account, a pictogram of a man or a woman appears as a profile picture, I want to do something similar in my login, could someone guide me on how to do it? here the code that generates the user.

token, _ = APP.Jwt.GenerateToken(jwt.MapClaims{
    "iat": APP.Jwt.GenerateIAT(),
    "exp": APP.Jwt.GenerateEXP(),
    "iss": APP.Jwt.GenerateISS(),
    "aud": APP.Jwt.GenerateAUD(),
    "jti": APP.Jwt.GenerateJTI(),
    "sub": APP.Jwt.GenerateSUB(),

    "id":        u.ID.Hex(),
    "email":     u.Email,
    "phone":     u.Phonenumber,
    "username":  u.Username,
    "bio":       u.Biography,
    "age":       u.Age,
    "nickname":  u.Nickname,
    "createdAt": u.CreatedAt,
})

It should be noted that the pictogram that I use are local.

    
asked by David Villegas 12.08.2018 в 16:03
source

1 answer

0

You create your Nuevo function within the Usuario package, receiving as parameters the fields you request when creating the user. Taking for example that your fields are: "name" and "password".

package usuario

const imagenDefault string = "<Path a tu imagen>"

//Usuario estructura con la informacion de Usuario
type Usuario struct {
    Nombre     string
    Contrasena string
    Imagen     string
}

//Nuevo retorna el apuntador del objeto de un nuevo usuario
func Nuevo(nombre, contrasena string) *Usuario {
    var nuevoUsuario = &Usuario{
        Nombre:     nombre,
        Contrasena: contrasena,
        Imagen:     imagenDefault,
    }

    return nuevoUsuario
}

And to send it to call would be something like this:

package main

func main(){
    var adminUser = usuario.Nuevo("admin", "admin")
}

If you want to use Go's image package, it would be better so you do not have to depend on the direct path of your image.

  

Package image implements a basic 2-D image library.

     

The fundamental interface is called Image. An Image contains colors, which are described in the image / color package.

So you can read the image and save the byte array corresponding to your image, although that depends more on the needs and resources you have.

    
answered by 02.01.2019 в 23:13