Documentation
¶
Overview ¶
Package links handles links.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration utils.Configuration
Configuration redefines utils.Configuration to be used for methods within the package.
func NewAdapter ¶
func NewAdapter(configuration utils.Configuration) Configuration
NewAdapter returns a configuration to be used by the link handling functions. Check utils.Configuration to know about these fields.
func (Configuration) CreateLink ¶
func (conf Configuration) CreateLink( params utils.Parameters, ) (Link, int, string, string)
CreateLink returns a Link struct along with an HTTP code, optional information and an optional error code.
It checks using a regexp if the URL from the payload has http/https as its protocol, it then checks the expiration time, if there is none, DefaultExpiryTime will be added to now, if there's one, the time will be parsed using atp.ParseDuration and this time will be added to now. If there's a specific expiration date provided, it will be used in priority. The length provided will be checked and fixed according to min and max settings. the custom path provided will be checked if there's one, endpoints and some characters are blacklisted, if the path exceeds the length of DefaultMaxCustomLength, it will be trimmed. If there's no custom path provided, a random one will generated using either DefaultShortLength or the provided length with utils.GenStr. If there's a password provided, it will be hashed using argon2id.CreateHash. After all is done, a link entry will be created in the database using database.CreateLink. If there's an error when creating a link entry using a generated short, it will be re-generated again and again until it works.
type Link ¶
type Link struct { ExpireAt time.Time `json:"expireAt"` URL string `json:"url"` Short string `json:"short"` }
Link defines the structure of a link entry.
ExpireAt is the date at which the link will expire, URL is the original URL, Short is the shortened path.
type PassJSONLink ¶
type PassJSONLink struct { ShortenedLink string `json:"shortenedLink"` Password string `json:"password"` ExpireAt string `json:"expireAt"` URL string `json:"url"` }
Link defines the structure of a link entry that will be served to the client in json.
ShortenedLink is the full shortened link, Password is the password needed to access the url, ExpireAt is the formatted date at which the link will expire, URL is the original URL.
type SimpleJSONLink ¶
type SimpleJSONLink struct { ShortenedLink string `json:"shortenedLink"` ExpireAt string `json:"expireAt"` URL string `json:"url"` }
SimpleJSONLink defines the structure of a link entry that will be served to the client in json.
ShortenedLink is the full shortened link, ExpireAt is the formatted date at which the link will expire, URL is the original URL.