Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface { // WithHost sets the hosts of the shortened url. // E.g. if host is `my.url“ the shortened url could be `https://my.url/eRt35df`. WithHost(host string) Config // WithMongo sets the URI for connecting to Mongo. // https://www.mongodb.com/docs/manual/reference/connection-string/ // Example: `mongodb://root:password123@198.174.21.23:27017/databasename` WithMongoUri(mongoUri string) Config // contains filtered or unexported methods }
Config is used to customize the shortener. To create a config instance use `DefaultConfig()`.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a configuration with default values. default host: `localhost:8080`. default mongo URI: `mongodb://localhost:27017`.
type ConflictError ¶
type ConflictError struct{}
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type IdNotFoundError ¶
type IdNotFoundError struct {
// contains filtered or unexported fields
}
func (*IdNotFoundError) Error ¶
func (e *IdNotFoundError) Error() string
type ShortenedURL ¶
type ShortenedURL interface {
GetUrl() string
}
type Shortener ¶
type Shortener interface { // CreateShortenedUrl creates a shortened url for `url`. CreateShortenedUrl(ctx context.Context, url string, config ...UrlConfig) (ShortenedURL, error) // GetUrlFromShortenedUrl receives a shortened url `surl` and returns the original url. // E.g.: https://short.com/abCD123 GetUrlFromShortenedUrl(ctx context.Context, surl string) (string, error) // GetUrlFromShortenedUrl receives a shortened url `id` and returns the original url. // E.g.: abCD123 GetUrlFromShortenedUrlId(ctx context.Context, id string) (string, error) }
func NewShortener ¶
NewShortener creates a new shortener. If no configuration is passed uses the default configuration (see: `DefaultConfig()`)
type UrlConfig ¶
type UrlConfig interface { // WithAlias sets a short url alias instead of generating a random one. // E.g.: if the alias is `tastypizzas` the shortened url could be https://link.com/tastypizzas WithAlias(alias string) UrlConfig // WithOverrideAlias set the override configuration. // When override is `true` it will insert a new or override an existing shortened url. // This field is ignored when there is no alias. WithOverrideAlias(override bool) UrlConfig // WithExpirationDate sets an expiration date for the shortened url. // Once the expiration date has expired the url becomes invalid or allocated for other urls. WithExpirationDate(expriationDate time.Time) UrlConfig // contains filtered or unexported methods }
UrlConfig may be used to customize the way a url is shortened. A UrlConfig instance can be created by calling `DefaultUrlConfig()`.
func DefaultUrlConfig ¶
func DefaultUrlConfig() UrlConfig
DefaultConfig returns a configuration with default values. default alias: "" (empty string). default overrideAlias: false. default expirationDate: no expiration.