core

package
v0.0.0-...-c6cd1c4 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeID

func DecodeID(encodedID string) (uint64, error)

Decode a short id into a db id

func DecodeIDPadded

func DecodeIDPadded(encodedID string) (uint64, error)

Decode a short id with human friendly padding into a db id

func DecodePossibleShortID

func DecodePossibleShortID(shortID string) (uint64, error)

Try to decode a short id from user input into a db id, allowing for human friendly padding

func EncodeID

func EncodeID(id uint) string

Encode a db id into a short id

func EncodeIDPadded

func EncodeIDPadded(id uint) string

Encode a db id into a short id with human friendly padding

func HTMLTemplate

func HTMLTemplate(c *gin.Context, code int, name string, obj gin.H)

Replaces gin.Context.HTML() to add specific data into them

func IsValidShortID

func IsValidShortID(shortID string) bool

Check whether given id is a valid ShortID (with or without padding)

func NullableIsoStringToTime

func NullableIsoStringToTime(input *string) (*time.Time, error)

func TimeToHumanOr

func TimeToHumanOr(inputTime *time.Time, nilDefault string) string

Convert given time to human readable or use default string if nil

Types

type APIShort

type APIShort struct {
	ShortID    string
	TargetURL  string     `json:"targetUrl"`
	VisitCount uint       `json:"visitCount,omitempty"`
	ExpiresAt  *time.Time `json:"expiresAt,omitempty"`
	MaxUses    *uint      `json:"maxUses,omitempty"`
	OwnerID    *uint      `json:"ownerId,omitempty"`
	CreatedAt  time.Time  `json:"createdAt"`
}

func ShortToAPIShort

func ShortToAPIShort(dbShort db.Short) APIShort

type AppConfig

type AppConfig struct {
	SecretKey        Base64Decoded `env:"SECRET_KEY,notEmpty"`
	SQLitePath       string        `env:"DB_SQLITE_PATH,notEmpty"`
	RequireLogin     bool          `env:"REQUIRE_LOGIN" envDefault:"false"`
	AllowNewAccounts bool          `env:"ALLOW_NEW_ACCOUNTS" envDefault:"true"`
}

func (*AppConfig) ParseConfig

func (appConfig *AppConfig) ParseConfig() error

Load the config from OS

type Base64Decoded

type Base64Decoded []byte

func (*Base64Decoded) UnmarshalText

func (b *Base64Decoded) UnmarshalText(text []byte) error

type CreateShort

type CreateShort struct {
	TargetURL string  `form:"target-url" json:"targetUrl" binding:"required"`
	ExpiresAt *string `form:"expires-at" json:"expiresAt"`
	MaxUses   *uint   `form:"max-uses" json:"maxUses"`
}

func (*CreateShort) GenerateShort

func (s *CreateShort) GenerateShort() db.Short

type CreateUser

type CreateUser struct {
	Username        string `form:"username" json:"username" binding:"required,printascii"`
	Password        string `form:"password" json:"password" binding:"required"`
	PasswordConfirm string `form:"password-confirm" json:"passwordConfirm" binding:"required,eqcsfield=Password"`
}

type LoginUser

type LoginUser struct {
	Username string `form:"username" json:"username" binding:"required,printascii"`
	Password string `form:"password" json:"password" binding:"required"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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