url

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdLen = 4
)

StdLen sets the initial length of the generated code

Variables

View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

StdChars contains the valid characters to use in a code

Functions

func IsURL

func IsURL(str string) bool

IsURL checks URL validity

Types

type API

type API struct {
	Service Service
}

API has the Service functions

func ProvideAPI

func ProvideAPI(s Service) API

ProvideAPI provides Service functionalities

func (*API) Create

func (api *API) Create(c *gin.Context)

Create provides Service functionalities

func (*API) FindByCode

func (api *API) FindByCode(c *gin.Context)

FindByCode calls service function to find URL by Code

type DTO

type DTO struct {
	ID          uint   `json:"id,string,omitempty"`
	Code        string `json:"code,omitempty"`
	OriginalURL string `json:"original_url"`
}

DTO has the info given by json

func ToDTO

func ToDTO(url URL) DTO

ToDTO parses URL to DTO Struct

type Repository

type Repository struct {
	DB *gorm.DB
}

Repository passes current database connection

func ProvideRepository

func ProvideRepository(DB *gorm.DB) Repository

ProvideRepository returns current repository

func (*Repository) FindByCode

func (repo *Repository) FindByCode(code string) (URL, bool)

FindByCode finds the given Code url

func (*Repository) FindByOriginalURL

func (repo *Repository) FindByOriginalURL(originalURL string) (URL, bool)

FindByOriginalURL finds the given OriginalURL url

func (*Repository) RandomCode

func (repo *Repository) RandomCode(length int) string

RandomCode returns a new random string of the provided length.

func (*Repository) RandomCodeChars

func (repo *Repository) RandomCodeChars(length int, chars []byte) string

RandomCodeChars returns a new random string of the provided length using the byte slice.

func (*Repository) Save

func (repo *Repository) Save(url URL) URL

Save saves the url model to database and publish it to redis, redis part is not ready yet

type Service

type Service struct {
	Repository Repository
}

Service has all the repository info

func ProvideService

func ProvideService(repo Repository) Service

ProvideService provide this service info

func (*Service) FindByCode

func (s *Service) FindByCode(code string) (URL, bool)

FindByCode calls the repository function FindByCode

func (*Service) Save

func (s *Service) Save(u URL) (URL, bool)

Save calls the repository function Save

type URL

type URL struct {
	gorm.Model
	Code        string `gorm:"unique;not null" json:"code"`
	OriginalURL string `gorm:"not null" json:"original_url"`
}

URL represents a database table

func ToURL

func ToURL(dto DTO) URL

ToURL parses DTO to URL Struct

Jump to

Keyboard shortcuts

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