MicroGO

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 45 Imported by: 0

README

logo

The Go version of Django Framework

In MicroGO, I take some of the most valuable features in Django and implement similar functionality in Go.

Since Go is compiled and type-safe, web applications written in this language are typically much faster and far less error-prone than an equivalent application, Django, written in Python.

Requirements

make sure you have the following dependencies:

  1. make - utility for building and maintaining groups of programs.
  2. GoLang - the compiler that MicroGO uses.
How to use MicroGO
  1. Download or clone MicroGO repository from GitHub
  2. Run make build command in the root directory of MicroGO.

Alternative ways to install MicroGO binaries

Currently, the auto install script is only available for Linux OS fo other OS, you can manually install MicroGO binaries. See section How to use MicroGO for more information.:

  1. Download the binaries from GitHub Releases
  2. Or run the following command:
    curl -L https://raw.githubusercontent.com/cploutarchou/MicroGO/master/install.sh | bash
    
MicroGO Terminal Commands:
  • help - Show the help commands
  • version - Print application version
  • make auth - Create and runs migrations for auth tables, create models and middleware.
  • migrate - Runs all up migrations that have not been run previously
  • migrate down - Reverses the most recent migration
  • migrate reset - Runs all down migrations in reverse order, and then all up migrations
  • make migration migration_name - Create two new up and down migrations in the migrations folder
  • make handler handler_name - Create a stub handler on handlers directory
  • make model model_name - Create a new mode in the models directory
  • make key - Create a random key of 32 characters.
  • make mail - Create two starter mail templates in the mail directory.

paypal

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	DatabaseType 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 MicroGo

type MicroGo struct {
	AppName    string
	Debug      bool
	Version    string
	ErrorLog   *log.Logger
	InfoLog    *log.Logger
	WarningLog *log.Logger
	BuildLog   *log.Logger
	RootPath   string
	Routes     *chi.Mux
	Render     *render.Render
	JetView    *jet.Set
	BlocksView *blocks.Blocks

	Session       *scs.SessionManager
	DB            Database
	EncryptionKey string
	Cache         cache.Cache
	Scheduler     *cron.Cron
	Mailer        mailer.Mailer
	Server        Server
	Requests      *requests.Requests
	// contains filtered or unexported fields
}

MicroGo is the overall type for the MicroGo package. Members that are exported in this type are available to any application that uses it.

func (*MicroGo) BuildDataSourceName

func (m *MicroGo) BuildDataSourceName() string

BuildDataSourceName builds the datasource name for our database, and returns it as a string

func (*MicroGo) CreateDirIfNotExist

func (m *MicroGo) CreateDirIfNotExist(path string) error

CreateDirIfNotExist creates the necessary folder if not exist.

func (*MicroGo) CreateFileIfNotExists

func (m *MicroGo) CreateFileIfNotExists(path string) error

CreateFileIfNotExists creates the necessary files if not exist.

func (*MicroGo) CreateRandomString

func (m *MicroGo) CreateRandomString(n int) string

CreateRandomString A Random String Generator function based on n value length. From the values in the rndString const

func (*MicroGo) Error404

func (m *MicroGo) Error404(w http.ResponseWriter, r *http.Request)

Error404 : Return Not Found HTTP response .

Status Code : 404

func (*MicroGo) Error500

func (m *MicroGo) Error500(w http.ResponseWriter, r *http.Request)

Error500 : Return StatusInternal Server Error HTTP response .

Status Code : 500

func (*MicroGo) ErrorForbidden

func (m *MicroGo) ErrorForbidden(w http.ResponseWriter, r *http.Request)

ErrorForbidden : Return StatusForbidden HTTP response.

Status Code : 403

func (*MicroGo) ErrorStatus

func (m *MicroGo) ErrorStatus(w http.ResponseWriter, status int)

ErrorStatus : Construct Error HTTP response

func (*MicroGo) ErrorUnauthorized

func (m *MicroGo) ErrorUnauthorized(w http.ResponseWriter, r *http.Request)

ErrorUnauthorized : Return Unauthorized response on request error.

Status Code : 401

func (*MicroGo) ErrorUnprocessable

func (m *MicroGo) ErrorUnprocessable(w http.ResponseWriter, r *http.Request)

ErrorUnprocessable : Return Unprocessable entity HTTP response.

Status Code 422.

func (*MicroGo) Init

func (m *MicroGo) Init(p initPaths) error

Init creates the necessary folders for MicroGo application

func (*MicroGo) ListenAndServe

func (m *MicroGo) ListenAndServe()

ListenAndServe starts the application web server

func (*MicroGo) LoadSessions

func (m *MicroGo) LoadSessions(next http.Handler) http.Handler

func (*MicroGo) LoadTime

func (m *MicroGo) LoadTime(start time.Time)

func (*MicroGo) MigrateDownAll

func (m *MicroGo) MigrateDownAll(dsn string) error

func (*MicroGo) MigrateForce

func (m *MicroGo) MigrateForce(dsn string) error

func (*MicroGo) MigrateUp

func (m *MicroGo) MigrateUp(dsn string) error

func (*MicroGo) New

func (m *MicroGo) New(rootPath string) error

New reads the .env file, creates our application config, populates the MicroGo type with settings based on .env values, and creates the necessary folders and files if they don't exist on the system.

func (*MicroGo) NoSurf

func (m *MicroGo) NoSurf(next http.Handler) http.Handler

func (*MicroGo) OpenDB

func (m *MicroGo) OpenDB(driverName, dataSourceName string) (*sql.DB, error)

func (*MicroGo) ReadJson

func (m *MicroGo) ReadJson(w http.ResponseWriter, r *http.Request, data interface{}) error

func (*MicroGo) SentFile

func (m *MicroGo) SentFile(w http.ResponseWriter, r *http.Request, fileLocation, fileName string) error

SentFile : Send a file on response.

func (*MicroGo) Steps

func (m *MicroGo) Steps(n int, dsn string) error

func (*MicroGo) Validator

func (m *MicroGo) Validator(data url.Values) *Validation

func (*MicroGo) WriteJson

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

WriteJson : Create a JSON response.

func (*MicroGo) WriteXML

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

WriteXML : Create XML response.

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
terminal
cli

Jump to

Keyboard shortcuts

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