db

package
v0.0.0-...-3d1138b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLogin

func CheckLogin(username string, password string) bool

CheckLogin checks user and pwd and returns boolean

func CheckLoginValidator

func CheckLoginValidator(username string, password string, c echo.Context) (bool, error)

CheckLoginValidator checks user and pwd and returns boolean

func CreateUser

func CreateUser(username string, password string, firstname string, lastname string) models.User

CreateUser in database and return a struct with it

func GetUser

func GetUser(username string) models.User

GetUser as a struct

func GrabPost

func GrabPost(postURL string) models.Post

GrabPost and return it to router

func GrabPosts

func GrabPosts() []models.Post

GrabPosts and relay

func GrabPosts() []models.Post {
	db := createConn()
	defer db.Close()
	posts := []models.Post{}
	rows, err := db.Query(`SELECT * FROM posts ORDER BY posted DESC LIMIT 10 OFFSET $1`, 0)
	if err != nil {
		log.Fatal(err)
	}
	for rows.Next() {
		var row models.Post
		err := rows.Scan(&row.ID, &row.Author, &row.Posted, &row.Updated, &row.Title, &row.Content, &row.Status, &row.URL, &row.Excerpt, &row.Meta)
		if err != nil {
			log.Fatal(err)
		}
		posts = append(posts, row)
	}
	return posts
}

GrabPosts and transform to json and send

func Login

func Login(c echo.Context) error

Login with token

func NewPost

func NewPost(post models.Post) models.Post

NewPost to insert a new post into the DB

func Setup

func Setup() int

Setup the database - Check if there are any tables and create them if not

func UpdatePost

func UpdatePost(post models.Post) models.Post

UpdatePost based on input data and save in DB

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL