ghostly

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: GPL-3.0 Imports: 43 Imported by: 0

README

Ghostly


Ghostly is a simple, lightweight, and fast full-stack framework for Golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Routes added in v1.2.0

func Routes() http.Handler

Routes are ghostly specific routes, which are mounted in the routes file in Ghostly applications

Types

type Database

type Database struct {
	DataType string
	Pool     *sql.DB
}

type Encryption

type Encryption struct {
	Key []byte
}

func (*Encryption) Decrypt

func (e *Encryption) Decrypt(cryptoText string) (string, error)

func (*Encryption) Encrypt

func (e *Encryption) Encrypt(text string) (string, error)

type Ghostly

type Ghostly struct {
	AppName  string
	Debug    bool
	Version  string
	ErrorLog *log.Logger
	InfoLog  *log.Logger
	RootPath string
	Routes   *chi.Mux
	Render   *render.Render
	Session  *scs.SessionManager
	DB       Database
	JetViews *jet.Set

	EncryptionKey string
	Cache         cache.Cache
	Scheduler     *cron.Cron
	Mail          mailer.Mail
	Server        Server
	// contains filtered or unexported fields
}

Ghostly is the overall type for the Ghostly package. Members that are exported in this type are available to any application that uses it.

func (*Ghostly) BuildDSN

func (g *Ghostly) BuildDSN() string

BuildDSN builds the datasource name for our database, and returns it as a string

func (*Ghostly) CreateDirIfNotExist

func (g *Ghostly) CreateDirIfNotExist(path string) error

CreateDirIfNotExist creates a new directory if it does not exist

func (*Ghostly) CreateFileIfNotExists

func (g *Ghostly) CreateFileIfNotExists(path string) error

CreateFileIfNotExists creates a new file at path if it does not exist

func (*Ghostly) DownloadFile

func (g *Ghostly) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error

DownloadFile downloads a file

func (*Ghostly) Error404

func (g *Ghostly) Error404(w http.ResponseWriter, r *http.Request)

Error404 returns page not found response

func (*Ghostly) Error500

func (g *Ghostly) Error500(w http.ResponseWriter, r *http.Request)

Error500 returns internal server error response

func (*Ghostly) ErrorForbidden

func (g *Ghostly) ErrorForbidden(w http.ResponseWriter, r *http.Request)

ErrorForbidden returns a forbidden status message (client is known)

func (*Ghostly) ErrorStatus

func (g *Ghostly) ErrorStatus(w http.ResponseWriter, status int)

ErrorStatus returns a response with the supplied http status

func (*Ghostly) ErrorUnauthorized

func (g *Ghostly) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)

ErrorUnauthorized sends an unauthorized status (client is not known)

func (*Ghostly) Init

func (g *Ghostly) Init(p initPaths) error

Init creates necessary folders for our Ghostly application

func (*Ghostly) ListenAndServe

func (g *Ghostly) ListenAndServe()

ListenAndServe starts the web server

func (*Ghostly) LoadTime

func (g *Ghostly) LoadTime(start time.Time)

LoadTime calculates function execution time. To use, add defer g.LoadTime(time.Now()) to the function body

func (*Ghostly) MigrateDownAll

func (g *Ghostly) MigrateDownAll(dsn string) error

func (*Ghostly) MigrateForce

func (g *Ghostly) MigrateForce(dsn string) error

func (*Ghostly) MigrateUp

func (g *Ghostly) MigrateUp(dsn string) error

func (*Ghostly) New

func (g *Ghostly) New(rootPath string) error

New reads the .env file, creates our application config, populates the Ghostly type with settings based on .env values, and creates necessary folders and files if they don't exist

func (*Ghostly) NoSurf added in v1.2.0

func (g *Ghostly) NoSurf(next http.Handler) http.Handler

func (*Ghostly) OpenDB

func (g *Ghostly) OpenDB(dbType, dsn string) (*sql.DB, error)

OpenDB opens a connection to a sql database. dbType must be one of postgres (or pgx). TODO: add support for mysql/mariadb

func (*Ghostly) RandomString

func (g *Ghostly) RandomString(n int) string

RandomString generates a random string length n from values in the const randomString

func (*Ghostly) ReadJSON

func (g *Ghostly) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error

func (*Ghostly) SessionLoad

func (g *Ghostly) SessionLoad(next http.Handler) http.Handler

func (*Ghostly) Steps

func (g *Ghostly) Steps(n int, dsn string) error

func (*Ghostly) Validator

func (g *Ghostly) Validator(data url.Values) *Validation

func (*Ghostly) WriteJSON added in v1.2.0

func (g *Ghostly) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error

WriteJSON writes json from arbitrary data

func (*Ghostly) WriteXML

func (g *Ghostly) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error

WriteXML writes xml from arbitrary data

type Server

type Server struct {
	ServerName string
	Port       string
	Secure     bool
	URL        string
}

type Validation

type Validation struct {
	Data   url.Values
	Errors map[string]string
}

func (*Validation) AddError

func (v *Validation) AddError(key, message string)

func (*Validation) Check

func (v *Validation) Check(ok bool, key, message string)

func (*Validation) Has

func (v *Validation) Has(field string, r *http.Request) bool

func (*Validation) IsDateISO

func (v *Validation) IsDateISO(field, value string)

func (*Validation) IsEmail

func (v *Validation) IsEmail(field, value string)

func (*Validation) IsFloat

func (v *Validation) IsFloat(field, value string)

func (*Validation) IsInt

func (v *Validation) IsInt(field, value string)

func (*Validation) NoSpaces

func (v *Validation) NoSpaces(field, value string)

func (*Validation) Required

func (v *Validation) Required(r *http.Request, fields ...string)

func (*Validation) Valid

func (v *Validation) Valid() bool

Jump to

Keyboard shortcuts

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