Documentation ¶
Index ¶
- func Routes() http.Handler
- type Database
- type Encryption
- type Ghostly
- func (g *Ghostly) BuildDSN() string
- func (g *Ghostly) CreateDirIfNotExist(path string) error
- func (g *Ghostly) CreateFileIfNotExists(path string) error
- func (g *Ghostly) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error
- func (g *Ghostly) Error404(w http.ResponseWriter, r *http.Request)
- func (g *Ghostly) Error500(w http.ResponseWriter, r *http.Request)
- func (g *Ghostly) ErrorForbidden(w http.ResponseWriter, r *http.Request)
- func (g *Ghostly) ErrorStatus(w http.ResponseWriter, status int)
- func (g *Ghostly) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)
- func (g *Ghostly) Init(p initPaths) error
- func (g *Ghostly) ListenAndServe()
- func (g *Ghostly) LoadTime(start time.Time)
- func (g *Ghostly) MigrateDownAll(dsn string) error
- func (g *Ghostly) MigrateForce(dsn string) error
- func (g *Ghostly) MigrateUp(dsn string) error
- func (g *Ghostly) New(rootPath string) error
- func (g *Ghostly) NoSurf(next http.Handler) http.Handler
- func (g *Ghostly) OpenDB(dbType, dsn string) (*sql.DB, error)
- func (g *Ghostly) RandomString(n int) string
- func (g *Ghostly) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error
- func (g *Ghostly) SessionLoad(next http.Handler) http.Handler
- func (g *Ghostly) Steps(n int, dsn string) error
- func (g *Ghostly) Validator(data url.Values) *Validation
- func (g *Ghostly) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- func (g *Ghostly) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- type Server
- type Validation
- func (v *Validation) AddError(key, message string)
- func (v *Validation) Check(ok bool, key, message string)
- func (v *Validation) Has(field string, r *http.Request) bool
- func (v *Validation) IsDateISO(field, value string)
- func (v *Validation) IsEmail(field, value string)
- func (v *Validation) IsFloat(field, value string)
- func (v *Validation) IsInt(field, value string)
- func (v *Validation) NoSpaces(field, value string)
- func (v *Validation) Required(r *http.Request, fields ...string)
- func (v *Validation) Valid() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Encryption ¶
type Encryption struct {
Key []byte
}
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 ¶
BuildDSN builds the datasource name for our database, and returns it as a string
func (*Ghostly) CreateDirIfNotExist ¶
CreateDirIfNotExist creates a new directory if it does not exist
func (*Ghostly) CreateFileIfNotExists ¶
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) ListenAndServe ¶
func (g *Ghostly) ListenAndServe()
ListenAndServe starts the web server
func (*Ghostly) LoadTime ¶
LoadTime calculates function execution time. To use, add defer g.LoadTime(time.Now()) to the function body
func (*Ghostly) MigrateDownAll ¶
func (*Ghostly) MigrateForce ¶
func (*Ghostly) New ¶
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 ¶
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 ¶
RandomString generates a random string length n from values in the const randomString
type Validation ¶
func (*Validation) AddError ¶
func (v *Validation) AddError(key, message string)
func (*Validation) Check ¶
func (v *Validation) Check(ok bool, key, message string)
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) Valid ¶
func (v *Validation) Valid() bool