utils

package
v0.0.0-...-d01289e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorUrlEmptyUrl      = errors.New("empty url")
	ErrorUrlInvalid       = errors.New("invalid url")
	ErrorUrlSchemeInvalid = errors.New("invalid url scheme, must be http or https")
	ErrorUrlBlocked       = errors.New("invalid url")
)
View Source
var (
	LayoutDir   string = "./views/layout/"
	TemplateDir string = "./views/"
	TemplateExt string = ".html"
	ContextVar         = make(map[string]interface{})
)

Functions

func PresignArchiveResource

func PresignArchiveResource(request *ArchiveResourceRequest) string

Downloads an item from an S3 Bucket

func RandString

func RandString(n int) string

RandString generates a n-char short code for the archived link This is a pretty simple implementation and I (@batuhan) am sure there are a handful of better ways to handle this. Source: https://stackoverflow.com/a/22892986

func ValidateUrl

func ValidateUrl(urlStr string) error

Types

type ArchiveResourceRequest

type ArchiveResourceRequest struct {
	ArchiveID   string
	ArchiveSlug string
	File        string
	Download    bool
}

type ArchiveResponsePayload

type ArchiveResponsePayload struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Image       string `json:"image"`
}

func RunArchiveLambda

func RunArchiveLambda(archiveId uuid.UUID, requestUrl string) (*ArchiveResponsePayload, error)

type Config

type Config struct {
	// Env. to run in, this changed how static files are handled etc.
	Env string
	// Server address to bind
	ServerAddr string
	// Base URL to add when generating URL's (for example for redirection after archiving)
	BaseUrl string
	// Which dialect to pass to GORM (defaults to "mysql")
	DbDialect string
	// Database connection URI (defaults to "link:root@/teyitlink", see README)
	DbUri string
	// AWS S3 bucket the archive files are stored in (defaults to "teyitlink")
	BucketName string
	// Which Lambda to use for archive worker
	WorkerLambdaName string
	// Which AWS region to use
	AwsRegion string
	// the duration for which the server gracefully wait for existing connections to finish - e.g. 15s or 1m
	GracefulShutdown time.Duration
}

Config for the application

var Conf *Config

func GetConfig

func GetConfig() *Config

func InitConfig

func InitConfig() *Config

type MetaData

type MetaData struct {
	Title string
	Date  string
}

type NullableTime

type NullableTime struct {
	time.Time
}

func (NullableTime) MarshalJSON

func (t NullableTime) MarshalJSON() ([]byte, error)

type View

type View struct {
	Template *template.Template
	Layout   string
}

func NewView

func NewView(layout string, files ...string) *View

func (*View) Render

func (v *View) Render(w http.ResponseWriter, r *http.Request, data interface{}) error

Jump to

Keyboard shortcuts

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