models

package
v0.0.0-...-06cedb2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUrl

func AddUrl(data map[string]interface{}) error

AddUrl add a single url

func AddUser

func AddUser(username, password string) error

AddUser add a user record

func CheckAuth

func CheckAuth(username, password string) (bool, error)

CheckAuth checks if authentication information exists

func DeleteUrl

func DeleteUrl(shortern string) error

DeleteUrl delete a single url

func EditUser

func EditUser(id int, password string) error

EditUser modify password

func ExistAuthByUsername

func ExistAuthByUsername(username string) (bool, error)

ExistAuthByUsername check if a user exists based on username

func ExistUrlByOrigin

func ExistUrlByOrigin(origin string) (bool, error)

ExistUrlByOrigin checks if a url exists based on origin url

func ExistUrlByShortern

func ExistUrlByShortern(shorten string) (bool, error)

func Setup

func Setup()

Setup initializes the data instance.

Types

type Auth

type Auth struct {
	ID       int    `gorm:"primaryKey" json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
}

func GetUserByID

func GetUserByID(id int) (*Auth, error)

GetUserByID get user infomation by id

func GetUserByUsername

func GetUserByUsername(username string) (*Auth, error)

GetUserByUsername get user infomathion by username

type Model

type Model struct {
	CreatedAt time.Time      `gorm:"autoCreateTime" json: "created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json: "updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

type Url

type Url struct {
	ID          int    `gorm:"primaryKey" json:"id"`
	OriginUrl   string `json:"origin_url" gorm:"index"`
	ShorternUrl string `json:"shortern_url"`
	CreatedBy   int    `json:"created_by"`

	Model
}

func GetShortByOrigin

func GetShortByOrigin(origin_url string) (*Url, error)

GetShortByOrigin get a shortern url on origin_url

func GetUrl

func GetUrl(id int) (*Url, error)

GetUrl get a url based on id

func GetUrlByShort

func GetUrlByShort(short_url string) (*Url, error)

GetUrl get a url based on short_url

func GetUrls

func GetUrls(creator int) ([]*Url, error)

GetUrls get urls based on creator

Jump to

Keyboard shortcuts

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