Documentation
¶
Index ¶
- type Database
- type Encryption
- 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
- type Vega
- func (v *Vega) BuildDSN() string
- func (v *Vega) CreateDirIfNotExist(path string) error
- func (v *Vega) CreateFileIfNotExists(path string) error
- func (v *Vega) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error
- func (v *Vega) Error404(w http.ResponseWriter, r *http.Request)
- func (v *Vega) Error500(w http.ResponseWriter, r *http.Request)
- func (v *Vega) ErrorForbidden(w http.ResponseWriter, r *http.Request)
- func (v *Vega) ErrorStatus(w http.ResponseWriter, status int)
- func (v *Vega) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)
- func (v *Vega) Init(p initPaths) error
- func (v *Vega) ListenAndServe()
- func (v *Vega) LoadTime(start time.Time)
- func (v *Vega) MigrateDownAll(dsn string) error
- func (v *Vega) MigrateForce(dsn string) error
- func (v *Vega) MigrateUp(dsn string) error
- func (v *Vega) New(rootPath string) error
- func (v *Vega) NoSurf(next http.Handler) http.Handler
- func (v *Vega) OpenDB(dbType, dsn string) (*sql.DB, error)
- func (v *Vega) RandomString(n int) string
- func (v *Vega) ReadJSON(w http.ResponseWriter, r *http.Request, data interface{}) error
- func (v *Vega) SessionLoad(next http.Handler) http.Handler
- func (v *Vega) Steps(n int, dsn string) error
- func (v *Vega) Validator(data url.Values) *Validation
- func (v *Vega) WriteJSON(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- func (v *Vega) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encryption ¶
type Encryption struct {
Key []byte
}
Encryption provides encryption and decryption functionality
type Validation ¶
Validation provides form validation functionality
func (*Validation) AddError ¶
func (v *Validation) AddError(key, message string)
AddError adds an error message for a field
func (*Validation) Check ¶
func (v *Validation) Check(ok bool, key, message string)
Check adds an error if the condition is false
func (*Validation) Has ¶
func (v *Validation) Has(field string, r *http.Request) bool
Has checks if a field exists in the request
func (*Validation) IsDateISO ¶
func (v *Validation) IsDateISO(field, value string)
IsDateISO validates that a value is a date in ISO format (YYYY-MM-DD)
func (*Validation) IsEmail ¶
func (v *Validation) IsEmail(field, value string)
IsEmail validates that a value is a valid email address
func (*Validation) IsFloat ¶
func (v *Validation) IsFloat(field, value string)
IsFloat validates that a value is a floating point number
func (*Validation) IsInt ¶
func (v *Validation) IsInt(field, value string)
IsInt validates that a value is an integer
func (*Validation) NoSpaces ¶
func (v *Validation) NoSpaces(field, value string)
NoSpaces validates that a value contains no whitespace
func (*Validation) Required ¶
func (v *Validation) Required(r *http.Request, fields ...string)
Required validates that fields are not empty
func (*Validation) Valid ¶
func (v *Validation) Valid() bool
Valid returns true if there are no validation errors
type Vega ¶
type Vega 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
}
Vega is the overall type for the Vega package. Members that are exported in this type are available to any application that uses it.
func (*Vega) BuildDSN ¶
BuildDSN builds the datasource name for our database, and returns it as a string
func (*Vega) CreateDirIfNotExist ¶
CreateDirIfNotExist creates a new directory if it does not exist
func (*Vega) CreateFileIfNotExists ¶
CreateFileIfNotExists creates a new file at path if it does not exist
func (*Vega) DownloadFile ¶
func (v *Vega) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error
DownloadFile downloads a file
func (*Vega) Error404 ¶
func (v *Vega) Error404(w http.ResponseWriter, r *http.Request)
Error404 returns page not found response
func (*Vega) Error500 ¶
func (v *Vega) Error500(w http.ResponseWriter, r *http.Request)
Error500 returns internal server error response
func (*Vega) ErrorForbidden ¶
func (v *Vega) ErrorForbidden(w http.ResponseWriter, r *http.Request)
ErrorForbidden returns a forbidden status message (client is known)
func (*Vega) ErrorStatus ¶
func (v *Vega) ErrorStatus(w http.ResponseWriter, status int)
ErrorStatus returns a response with the supplied http status
func (*Vega) ErrorUnauthorized ¶
func (v *Vega) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)
ErrorUnauthorized sends an unauthorized status (client is not known)
func (*Vega) LoadTime ¶
LoadTime calculates function execution time. To use, add defer v.LoadTime(time.Now()) to the function body
func (*Vega) MigrateDownAll ¶
MigrateDownAll rolls back all migrations
func (*Vega) MigrateForce ¶
MigrateForce forces the migration version
func (*Vega) New ¶
New reads the .env file, creates our application config, populates the Vega type with settings based on .env values, and creates necessary folders and files if they don't exist
func (*Vega) OpenDB ¶
OpenDB opens a connection to a sql database. dbType must be one of postgres (or pgx). TODO: add support for mysql/mariadb
func (*Vega) RandomString ¶
RandomString generates a random string length n from values in the const randomString
func (*Vega) SessionLoad ¶
SessionLoad loads and saves session data for requests
func (*Vega) Validator ¶
func (v *Vega) Validator(data url.Values) *Validation
Validator creates a new validation instance