Documentation
¶
Index ¶
- Constants
- type Database
- type Encryption
- type ErrorsMap
- type Goravel
- func (g *Goravel) BuildDSN() string
- func (g *Goravel) ConnectToDatabase(dbType, dsn string) (*sql.DB, error)
- func (g *Goravel) CreateDirIfNotExists(path string) error
- func (g *Goravel) CreateFileIfNotExists(path string) error
- func (g *Goravel) CreateFolderStructure(p InitPaths) error
- func (g *Goravel) CreateLoggers() (*log.Logger, *log.Logger)
- func (g *Goravel) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error
- func (g *Goravel) Error404(w http.ResponseWriter, r *http.Request)
- func (g *Goravel) Error500(w http.ResponseWriter, r *http.Request)
- func (g *Goravel) ErrorForbidden(w http.ResponseWriter, r *http.Request)
- func (g *Goravel) ErrorStatus(w http.ResponseWriter, status int)
- func (g *Goravel) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)
- func (g *Goravel) ListenAndServe() error
- func (g *Goravel) MigrateDownAll(dsn string) error
- func (g *Goravel) MigrateForce(dsn string) error
- func (g *Goravel) MigrateSteps(n int, dsn string) error
- func (g *Goravel) MigrateUp(dsn string) error
- func (g *Goravel) New(rootPath string) error
- func (g *Goravel) NoSurf(next http.Handler) http.Handler
- func (g *Goravel) RandomString(n int) string
- func (g *Goravel) ReadCSV(qs url.Values, key string, defaultValue []string) []string
- func (g *Goravel) ReadIDParam(r *http.Request) (int64, error)
- func (g *Goravel) ReadInt(qs url.Values, key string, defaultValue int) (int, error)
- func (g *Goravel) ReadJSON(w http.ResponseWriter, r *http.Request, dst interface{}) error
- func (g *Goravel) ReadStrings(qs url.Values, key string, defaultValue string) string
- func (g *Goravel) SessionLoad(next http.Handler) http.Handler
- func (g *Goravel) Validator(data url.Values) *Validation
- func (g *Goravel) WriteJSON(w http.ResponseWriter, status int, data Response, headers ...http.Header) error
- func (g *Goravel) WriteXML(w http.ResponseWriter, status int, data interface{}, headers ...http.Header) error
- type InitPaths
- type Response
- type Server
- type Validation
- func (v *Validation) Check(ok bool, field, message string)
- func (v *Validation) HasMinLength(field string, length int, value ...string) bool
- func (v *Validation) HasRequired(requiredFields ...string)
- func (v *Validation) HasValue(field string, value ...string) bool
- func (v *Validation) IsDateISO(field string, value ...string) bool
- func (v *Validation) IsFloat(field string, value ...string) bool
- func (v *Validation) IsInt(field string, value ...string) bool
- func (v *Validation) IsValid() bool
- func (v *Validation) IsValidEmail(field string, value ...string) bool
- func (v *Validation) IsValidPassword(field string, value ...string) bool
- func (v *Validation) IsValidUrl(field string, value ...string) bool
- func (v *Validation) IsValidUsername(field string, value ...string) bool
- func (v *Validation) NoWhitespace(field string, value ...string) bool
Constants ¶
const ( // Version of Goravel Version = "1.6.0" // http://patorjk.com/software/taag/#p=display&f=Ogre&t=Goravel Banner = `` /* 314-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encryption ¶
type Encryption struct {
Key []byte
}
type Goravel ¶
type Goravel struct { AppName string GoAppURL string Debug bool // true for development mode Version string Server Server ErrorLog *log.Logger InfoLog *log.Logger RootPath string // rootPath is the path that we are in when we start the goravel app Render *render.Render Routes *chi.Mux JetViews *jet.Set Session *scs.SessionManager DB Database Cache cache.Cache EncryptionKey string Mail mailer.Mail Scheduler *cron.Cron // contains filtered or unexported fields }
func (*Goravel) ConnectToDatabase ¶
func (*Goravel) CreateDirIfNotExists ¶
CreateDirIfNotExists creates a new directory if it does not exist
func (*Goravel) CreateFileIfNotExists ¶
CreateFileIfNotExists creates a new file at path if it does not exist
func (*Goravel) CreateFolderStructure ¶
CreateFolderStructure creates necessary folders for our Goravel application
func (*Goravel) DownloadFile ¶
func (g *Goravel) DownloadFile(w http.ResponseWriter, r *http.Request, pathToFile, fileName string) error
DownloadFile helps users download files from the server
func (*Goravel) Error404 ¶
func (g *Goravel) Error404(w http.ResponseWriter, r *http.Request)
Error404 returns page not found response
func (*Goravel) Error500 ¶
func (g *Goravel) Error500(w http.ResponseWriter, r *http.Request)
Error500 returns internal server error response
func (*Goravel) ErrorForbidden ¶
func (g *Goravel) ErrorForbidden(w http.ResponseWriter, r *http.Request)
ErrorForbidden returns a forbidden status message (client is known)
func (*Goravel) ErrorStatus ¶
func (g *Goravel) ErrorStatus(w http.ResponseWriter, status int)
ErrorStatus returns a response with the supplied http status
func (*Goravel) ErrorUnauthorized ¶
func (g *Goravel) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)
ErrorUnauthorized sends an unauthorized status (client is not known)
func (*Goravel) ListenAndServe ¶
ListenAndServe starts the web server
func (*Goravel) MigrateDownAll ¶
func (*Goravel) MigrateForce ¶
MigrateForce forces the migration to the immediate last version
func (*Goravel) MigrateSteps ¶
Steps runs n steps of migrations. If n > 0, it will run n steps of "up" migrations. If n < 0, it will run n steps of "down" migrations.
func (*Goravel) RandomString ¶
RandomString generates a random string of length n from values in the const randomString
func (*Goravel) ReadCSV ¶
readCSV is a helper method on application type that reads a string value from the URL query string and then splits it into a slice on the comma character. If no matching key is found then it returns the provided default value.
func (*Goravel) ReadIDParam ¶
readIDParam reads interpolated "id" from request URL and returns it and nil. If there is an error it returns and 0 and an error.
func (*Goravel) ReadInt ¶
readInt is a helper method on application type that reads a string value from the URL query string and converts it to an integer before returning. If no matching key is found then it returns the provided default value. If the value couldn't be converted to an integer, then we record an error message in the provided Validator instance, and return the default value.
func (*Goravel) ReadJSON ¶
readJSON decodes request Body into corresponding Go type. It triages for any potential errors and returns corresponding appropriate errors.
func (*Goravel) ReadStrings ¶
readString is a helper method on application type that returns a string value from the URL query string, or the provided default value if no matching key is found.
func (*Goravel) Validator ¶
func (g *Goravel) Validator(data url.Values) *Validation
New initializes a custom Validation struct
type Validation ¶
type Validation struct { // Validation Struct will contain all the key value pairs of the url.Values // object(field name and value pairs of html Validation that was submitted by the user) Data url.Values // map[string][]string Errors ErrorsMap // map[string][]string }
Validation creates a custom Validation struct, embeds a url.Values object
func (*Validation) Check ¶
func (v *Validation) Check(ok bool, field, message string)
Check adds an error message to the validation object if the condition is not met
func (*Validation) HasMinLength ¶
func (v *Validation) HasMinLength(field string, length int, value ...string) bool
func (*Validation) HasRequired ¶
func (v *Validation) HasRequired(requiredFields ...string)
To check if any of the Validation field in POST request is empty or not
func (*Validation) HasValue ¶
func (v *Validation) HasValue(field string, value ...string) bool
To check if a Validation field in POST request is empty or not
func (*Validation) IsValid ¶
func (v *Validation) IsValid() bool
Valid returns true if there are no errors, otherwise false
func (*Validation) IsValidEmail ¶
func (v *Validation) IsValidEmail(field string, value ...string) bool
func (*Validation) IsValidPassword ¶
func (v *Validation) IsValidPassword(field string, value ...string) bool
func (*Validation) IsValidUrl ¶
func (v *Validation) IsValidUrl(field string, value ...string) bool
func (*Validation) IsValidUsername ¶
func (v *Validation) IsValidUsername(field string, value ...string) bool
func (*Validation) NoWhitespace ¶
func (v *Validation) NoWhitespace(field string, value ...string) bool