Example #1
0
func Show(c *gin.Context) {
	userId := c.Param("user_id")

	db, err := sqlx.Connect("postgres", "dbname=initial sslmode=disable")
	if err != nil {
		log.Fatalln(err)
	}

	userSelected := user.User{}
	sql := fmt.Sprintf("SELECT * FROM users WHERE id=%s LIMIT 1", userId)
	db.Get(&userSelected.Attributes, sql)
	userSelected.Setup()

	c.JSON(200, user.UserResource{userSelected})
}
Example #2
0
func Index(c *gin.Context) {
	db, err := sqlx.Connect("postgres", "dbname=initial sslmode=disable")
	if err != nil {
		log.Fatalln(err)
	}

	attributes := []user.UserAttributes{}
	db.Select(&attributes, "SELECT * FROM users")

	users := make([]user.User, len(attributes))

	for index, element := range attributes {
		createdUser := user.User{Attributes: element}
		createdUser.Setup()
		users[index] = createdUser
	}

	c.JSON(200, users)
}