ghostly

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 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

This section is empty.

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

func (*Ghostly) CreateFileIfNotExists

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

func (*Ghostly) DownloadFile

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

support to serve a file that must be downloaded

func (*Ghostly) Error404

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

Response for errors

func (*Ghostly) Error500

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

func (*Ghostly) ErrorForbidden

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

func (*Ghostly) ErrorStatus

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

generic func

func (*Ghostly) ErrorUnauthorized

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

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)

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) 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

Generates a 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

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

func (*Ghostly) WriteXML

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

support for xml

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

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

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