Documentation ¶
Index ¶
- Constants
- Variables
- func IsURL(str string) bool
- type API
- type DTO
- type Repository
- func (repo *Repository) FindByCode(code string) (URL, bool)
- func (repo *Repository) FindByOriginalURL(originalURL string) (URL, bool)
- func (repo *Repository) RandomCode(length int) string
- func (repo *Repository) RandomCodeChars(length int, chars []byte) string
- func (repo *Repository) Save(url URL) URL
- type Service
- type URL
Constants ¶
const (
StdLen = 4
)
StdLen sets the initial length of the generated code
Variables ¶
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
StdChars contains the valid characters to use in a code
Functions ¶
Types ¶
type API ¶
type API struct {
Service Service
}
API has the Service functions
func (*API) FindByCode ¶
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
type Repository ¶
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 ¶
FindByCode calls the repository function FindByCode