package module
v1.3.0 Latest Latest

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



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


Object Relation Mapper (ORM) that is database agnostic

A fully functional Database Migration system

A fully featured user authentication system that can be installed with a single command, which includes:

A password reset system

Session based authentication (for web based applications)

Token based authentication (for APIs and systems built with front ends like React and Vue)

A fully featured templating system (using both Go templates and Jet templates)

A complete caching system that supports Redis and Badger

Easy session management, with cookie, database (MySQL and Postgres), Redis stores

Simple response types for HTML, XML, JSON, and file downloads

Form validation

JSON validation

A complete mailing system which supports SMTP servers, and third party APIs including MailGun, SparkPost, and SendGrid

A command line application which allows for easy generation of emails, handlers, database models

the command line application will allow us to create a ready-to-go web application by tying a single command: ghostly new


There is coverage and CI for both Linux, Mac and Windows environments, but I make no guarantees about the bin version working on Windows. Must be Go version 1.17 or higher


As a library

go get

or if you want to use it as a bin command I will list the exact steps below:

Step 1. Make a workfolder on your Desktop and cd into it

mkdir Ghostly-App
cd Ghostly-App

Step 2. Clone the repository

git clone

Step 3. cd into directory and build the binary with the Makefile at root level of the ghostly project

cd ghostly
make build

Step 4. cd into the dist directory of the ghostly application and copy it to your Desktop

cd dist
cp ./ghostly ~/Desktop


Once above steps have been followed, you can show all ghostly command by going to your Desktop and run:


Making a new project:

./ghostly new $("PROJECT-NAME")

Then cd into your newly made Go project:


Run the project by using the makefile in your new project directory

make start

Here are the types for the Ghostly Framework

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
	config        config
	EncryptionKey string
	Cache         cache.Cache
	Scheduler     *cron.Cron
	Mail          mailer.Mail
	Server        Server

Below types are for Server and Config:

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

type config struct {
	port        string
	renderer    string
	cookie      cookieConfig
	sessionType string
	database    databaseConfig
	redis       redisConfig

For full documentation please refer to the package on: Ghostly Documentation


The full library ghostly was written by Dominic-Wassef




This section is empty.


This section is empty.


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


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