io

package module
v0.0.0-...-f683405 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 46 Imported by: 0

README

Go Report Card

IO Web Application Development Framework

IO is a powerful package for quickly writing modular web applications/services in Golang aimed both backend and frontend.

Features

  • Think once, Code less, Do more!
  • Aim both frontend and backend
  • Extremely simple to use.
  • Awesome superfast path matching and routing.
  • Modular & Extensible
  • A lot of tweaks and improvments
  • A lot of useful functions
  • A lot of UI components and integrations
  • A lot of usable/reusable apps to include and use
  • Live code reload
  • High performance
  • Superfast template engine
  • Actively maintained

Builtin Apps

  • Admin simple extensible user panel
  • Auth fully featured user/group/role/permission management set of apies
  • AdminLTE adminlte template ready to use!
  • Query dynamic multi purpose data query api
  • Settings create settings view for all of your apps

Documentation

Quick Start
  • Installation
  • Create new project
  • Examples

Todo

  • i18n
  • User Management app
  • List filter ui
  • Journal App
  • Log App
  • Swagger
  • Documentation (WIKI)
  • Sample Apps
  • Clear Libraries
  • Improve Manager
  • Keycloak login
  • Social Login
  • Websocket integration

Shoulders of Giants

IO stands on shoulder of great projects or inspired by them.

Fiber

An Express-inspired web framework written in Go


GORM

The fantastic ORM library for Golang


Jet Template Engine for Go

Jet is a template engine developed to be easy to use, powerful, dynamic, yet secure and very fast.


mapstructure

mapstructure is a Go library for decoding generic map values to structures and vice versa, while providing helpful error handling.


Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Events          = event.New()
	StatusCodePages = map[int]string{}
)
View Source
var AppMenus = []menu.Menu{}
View Source
var Arg args
View Source
var Database *gorm.DB
View Source
var DefaultPath = map[string][]string{}
View Source
var Exec string
View Source
var OS = struct {
	Name     string
	Version  string
	Kernel   string
	Username string
	Path     struct {
		Bin     []string
		Home    string
		Root    string
		Tmp     string
		AppData []string
	}
}{}
View Source
var ProcessID int
View Source
var WorkingDir string

Functions

func All

func All(path string, handlers ...func(*fiber.Ctx)) *fiber.App

All : https://fiber.wiki/application#http-methods

func Connect

func Connect(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Connect : https://fiber.wiki/application#http-methods

func CustomError

func CustomError(code int, path string) error

CustomError set custom page for errors

func Delete

func Delete(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Delete : https://fiber.wiki/application#http-methods

func Get

func Get(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Get : https://fiber.wiki/application#http-methods

func GetDBO

func GetDBO() *gorm.DB

GetDBO return database object instance

func GetFiber

func GetFiber() *fiber.App

GetFiber return fiber instance

func GetRegisteredApps

func GetRegisteredApps() map[string]interface{}

GetRegisteredApps return list of registered apps

func GetView

func GetView(prefix, name string) (*jet.Template, error)

GetView return view of given environment

func Group

func Group(prefix string, handlers ...func(*fiber.Ctx)) *fiber.Group

Group is used for Routes with common prefix to define a new sub-router with optional middleware.

func GuessPath

func GuessPath(file string) string

Guess path find file path from different locations

func Head(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Head : https://fiber.wiki/application#http-methods

func InterceptOSSignal

func InterceptOSSignal()

InterceptOSSignal TODO:Remove

func Options

func Options(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Options : https://fiber.wiki/application#http-methods

func Patch

func Patch(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Patch : https://fiber.wiki/application#http-methods

func Post

func Post(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Post : https://fiber.wiki/application#http-methods

func Put

func Put(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Put : https://fiber.wiki/application#http-methods

func Register

func Register(app App)

Register register app to use by IO

func RegisterView

func RegisterView(prefix, path string) *jet.Set

RegisterView register views of given path

func Run

func Run()

Run start IO Server

func Setup

func Setup()

Setup setup the IO app

func Shutdown

func Shutdown() error

Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners and then waiting indefinitely for all connections to return to idle and then shut down.

When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return nil. Make sure the program doesn't exit and waits instead for Shutdown to return.

Shutdown does not close keepalive connections so its recommended to set ReadTimeout to something else than 0.

func Static

func Static(prefix, path string)

Static append path with given prefix to static files

func Trace

func Trace(path string, handlers ...func(*fiber.Ctx)) *fiber.App

Trace : https://fiber.wiki/application#http-methods

func Use

func Use(args ...interface{}) *fiber.App

Use registers a middleware route. Middleware matches requests beginning with the provided prefix. Providing a prefix is optional, it defaults to "/"

Types

type App

type App interface {
	Register()
	Router()
	WhenReady()
	Permissions() []user.Permission
	Menus() []menu.Menu
}

type Configuration

type Configuration struct {
	App struct {
		Name       string `yaml:"name"`
		Static     string `yaml:"static"`
		SessionAge int    `yaml:"session-age"`
		Language   string `yaml:"language"`
		StrongPass int    `yaml:"strong-pass-level"`
	} `yaml:"app"`

	JWT struct {
		Secret    string        `yaml:"secret"`
		Issuer    string        `yaml:"issuer"`
		Audience  []string      `yaml:"audience"`
		Age       time.Duration `yaml:"age"`
		Subject   string        `yaml:"subject"`
		AgeString string        `yaml:"age"`
	} `yaml:"jwt"`

	Server struct {
		Host          string `yaml:"host"`
		Port          string `yaml:"port"`
		Cert          string `yaml:"cert"`
		Key           string `yaml:"key"`
		HTTPS         bool   `yaml:"https"`
		Name          string `yaml:"name"`
		MaxUploadSize string `yaml:"max-upload-size"`
		StrictRouting bool   `yaml:"strict-routing"`
		CaseSensitive bool   `yaml:"case-sensitive"`
		RequestID     bool   `yaml:"request-id"`
		Debug         bool   `yaml:"debug"`
		Recover       bool   `yaml:"recover"`
	} `yaml:"server"`

	Database struct {
		Enabled        bool          `yaml:"enabled"`
		Type           string        `yaml:"type"`
		Username       string        `yaml:"user"`
		Password       string        `yaml:"pass"`
		Server         string        `yaml:"server"`
		Cache          string        `yaml:"cache"`
		CacheSize      string        `yaml:"cache-size"`
		Debug          string        `yaml:"debug"`
		Database       string        `yaml:"database"`
		SSLMode        string        `yaml:"ssl-mode"`
		Params         string        `yaml:"params"`
		MaxOpenConns   int           `yaml:"max-open-connections"`
		MaxIdleConns   int           `yaml:"max-idle-connections"`
		ConnMaxLifTime time.Duration `yaml:"connection-max-lifetime"`
	} `yaml:"database"`

	Tweaks struct {
		Ballast       bool   `yaml:"ballast"`
		BallastSize   string `yaml:"ballast-size"`
		MaxProcessors int    `yaml:"processors"`
		PreFork       bool   `yaml:"prefork"`
	} `yaml:"tweaks"`

	RateLimit struct {
		Enabled  bool `yaml:"enabled"`
		Duration int  `yaml:"duration"`
		Requests int  `yaml:"requests"`
	} `yaml:"ratelimit"`

	CORS struct {
		Enabled          bool     `yaml:"enabled"`
		AllowOrigins     []string `yaml:"allowed-origins"`
		AllowMethods     []string `yaml:"allowed-methods"`
		AllowHeaders     []string `yaml:"allowed-headers"`
		AllowCredentials bool     `yaml:"allowed-credentials"`
		MaxAge           int      `yaml:"requests"`
	} `yaml:"cors"`
}

func GetConfig

func GetConfig() *Configuration

GetConfig return configuration instance

type Model

type Model struct {
	ID        uint       `json:"id" gorm:"primary_key"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" sql:"index"`
}

type Request

type Request struct {
	Variables fiber.Map
	Context   *fiber.Ctx
	JWT       *jwt.Payload
	User      *user.User
	Response  Response
	// contains filtered or unexported fields
}

func Upgrade

func Upgrade(ctx *fiber.Ctx) *Request

func (*Request) Accepts

func (r *Request) Accepts(offers ...string) (offer string)

Accepts checks if the specified extensions or content types are acceptable.

func (*Request) AcceptsCharsets

func (r *Request) AcceptsCharsets(offers ...string) (offer string)

AcceptsCharsets checks if the specified charset is acceptable.

func (*Request) AcceptsEncodings

func (r *Request) AcceptsEncodings(offers ...string) (offer string)

AcceptsEncodings checks if the specified encoding is acceptable.

func (*Request) AcceptsLanguages

func (r *Request) AcceptsLanguages(offers ...string) (offer string)

AcceptsLanguages checks if the specified language is acceptable.

func (*Request) Append

func (r *Request) Append(field string, values ...string)

Append the specified value to the HTTP response header field. If the header is not already set, it creates the header with the specified value.

func (*Request) Attachment

func (r *Request) Attachment(name ...string)

Attachment sets the HTTP response Content-Disposition header field to attachment.

func (*Request) BaseURL

func (r *Request) BaseURL() string

BaseURL returns (protocol + host).

func (*Request) Body

func (r *Request) Body(key ...string) string

Body contains the raw body submitted in a POST request. If a key is provided, it returns the form value

func (*Request) BodyParser

func (r *Request) BodyParser(out interface{}) error

BodyParser binds the request body to a struct. It supports decoding the following content types based on the Content-Type header: application/json, application/xml, application/x-www-form-urlencoded, multipart/form-data

func (*Request) ClearCookie

func (r *Request) ClearCookie(key ...string)

ClearCookie expires a specific cookie by key. If no key is provided it expires all cookies.

func (*Request) Cookie

func (r *Request) Cookie(cookie *fiber.Cookie)

Cookie sets a cookie by passing a cookie struct

func (*Request) Cookies

func (r *Request) Cookies(key ...string) (value string)

Cookies is used for getting a cookie value by key

func (*Request) Download

func (r *Request) Download(file string, name ...string)

Download transfers the file from path as an attachment. Typically, browsers will prompt the user for download. By default, the Content-Disposition header filename= parameter is the filepath (this typically appears in the browser dialog). Override this default with the filename parameter.

func (*Request) Error

func (r *Request) Error() error

Error contains the error information passed via the Next(err) method.

func (*Request) Flash

func (r *Request) Flash(params ...string)

func (*Request) FormFile

func (r *Request) FormFile(key string) (*multipart.FileHeader, error)

FormFile returns the first file by key from a MultipartForm.

func (*Request) FormValue

func (r *Request) FormValue(key string) (value string)

FormValue returns the first value by key from a MultipartForm.

func (*Request) Format

func (r *Request) Format(body interface{})

Format performs content-negotiation on the Accept HTTP header. It uses Accepts to select a proper format. If the header is not specified or there is no proper format, text/plain is used.

func (*Request) Fresh

func (r *Request) Fresh() bool

Fresh not implemented yet

func (*Request) Get

func (r *Request) Get(key string) (value string)

Get returns the HTTP request header specified by field. Field names are case-insensitive

func (Request) GetFlashes

func (r Request) GetFlashes() []flash

func (*Request) HasError

func (r *Request) HasError() bool

func (*Request) Hostname

func (r *Request) Hostname() string

Hostname contains the hostname derived from the Host HTTP header.

func (*Request) IP

func (r *Request) IP() string

IP returns the remote IP address of the request.

func (*Request) IPs

func (r *Request) IPs() []string

IPs returns an string slice of IP addresses specified in the X-Forwarded-For request header.

func (*Request) Is

func (r *Request) Is(extension string) (match bool)

Is returns the matching content type, if the incoming request’s Content-Type HTTP header field matches the MIME type specified by the type parameter

func (*Request) JSON

func (r *Request) JSON(json interface{}) error

JSON converts any interface or string to JSON using Jsoniter. This method also sets the content header to application/json.

func (*Request) JSONP

func (r *Request) JSONP(json interface{}, callback ...string) error

JSONP sends a JSON response with JSONP support. This method is identical to JSON, except that it opts-in to JSONP callback support. By default, the callback name is simply callback.

func (r *Request) Links(link ...string)

Links joins the links followed by the property to populate the response’s Link HTTP header field.

func (*Request) Locals

func (r *Request) Locals(key string, value ...interface{}) (val interface{})

Locals makes it possible to pass interface{} values under string keys scoped to the request and therefore available to all following routes that match the request.

func (*Request) Location

func (r *Request) Location(path string)

Location sets the response Location HTTP header to the specified path parameter.

func (*Request) Method

func (r *Request) Method(override ...string) string

Method contains a string corresponding to the HTTP method of the request: GET, POST, PUT and so on.

func (*Request) MultipartForm

func (r *Request) MultipartForm() (*multipart.Form, error)

MultipartForm parse form entries from binary. This returns a map[string][]string, so given a key the value will be a string slice.

func (*Request) Next

func (r *Request) Next(err ...error)

Next executes the next method in the stack that matches the current route. You can pass an optional error for custom error handling.

func (*Request) OriginalURL

func (r *Request) OriginalURL() string

OriginalURL contains the original request URL.

func (*Request) Params

func (r *Request) Params(key string) (value string)

Params is used to get the route parameters. Defaults to empty string "", if the param doesn't exist.

func (*Request) Path

func (r *Request) Path(override ...string) string

Path returns the path part of the request URL. Optionally, you could override the path.

func (*Request) Persist

func (r *Request) Persist()

func (*Request) Protocol

func (r *Request) Protocol() string

Protocol contains the request protocol string: http or https for TLS requests.

func (*Request) Query

func (r *Request) Query(key string) (value string)

Query returns the query string parameter in the url.

func (*Request) Range

func (r *Request) Range(size int) (rangeData fiber.Range, err error)

Range returns a struct containing the type and a slice of ranges.

func (*Request) Redirect

func (r *Request) Redirect(path string, status ...int)

Redirect to the URL derived from the specified path, with specified status. If status is not specified, status defaults to 302 Found

func (*Request) Render

func (r *Request) Render(file string, bind interface{}) error

Render a template with data and sends a text/html response. We support the following engines: html, amber, handlebars, mustache, pug

func (*Request) RenderView

func (r *Request) RenderView(input interface{}, views ...string) *bytes.Buffer

func (*Request) Route

func (r *Request) Route() *fiber.Route

Route returns the matched Route struct.

func (*Request) SaveFile

func (r *Request) SaveFile(fileheader *multipart.FileHeader, path string) error

SaveFile saves any multipart file to disk.

func (*Request) Secure

func (r *Request) Secure() bool

Secure returns a boolean property, that is true, if a TLS connection is established.

func (*Request) Send

func (r *Request) Send(bodies ...interface{})

Send sets the HTTP response body. The Send body can be of any type.

func (*Request) SendBytes

func (r *Request) SendBytes(body []byte)

SendBytes sets the HTTP response body for []byte types This means no type assertion, recommended for faster performance

func (*Request) SendFile

func (r *Request) SendFile(file string, noCompression ...bool)

SendFile transfers the file from the given path. The file is compressed by default Sets the Content-Type response HTTP header field based on the filenames extension.

func (*Request) SendHTML

func (r *Request) SendHTML(bodies ...interface{})

Send sets the HTML response body. The Send body can be of any type.

func (*Request) SendStatus

func (r *Request) SendStatus(status int)

SendStatus sets the HTTP status code and if the response body is empty, it sets the correct status message in the body.

func (*Request) SendString

func (r *Request) SendString(body string)

SendString sets the HTTP response body for string types This means no type assertion, recommended for faster performance

func (*Request) Set

func (r *Request) Set(key string, val string)

Set sets the response’s HTTP header field to the specified key, value.

func (*Request) SetCookie

func (r *Request) SetCookie(key string, val interface{}, params ...interface{})

SetCookie set cookie with given name,value and optional params (wise function)

func (*Request) SetError

func (r *Request) SetError(err interface{})

func (*Request) Stale

func (r *Request) Stale() bool

Stale is not implemented yet, pull requests are welcome!

func (*Request) Status

func (r *Request) Status(status int) *Request

Status sets the HTTP status for the response. This method is chainable.

func (*Request) Subdomains

func (r *Request) Subdomains(offset ...int) []string

Subdomains returns a string slive of subdomains in the domain name of the request. The subdomain offset, which defaults to 2, is used for determining the beginning of the subdomain segments.

func (*Request) Throw

func (r *Request) Throw(e *e.Error)

func (*Request) Type

func (r *Request) Type(ext string) *Request

Type sets the Content-Type HTTP header to the MIME type specified by the file extension.

func (*Request) URL

func (r *Request) URL() *URL

func (*Request) Var

func (r *Request) Var(key string, value interface{})

func (*Request) Vary

func (r *Request) Vary(fields ...string)

Vary adds the given header field to the Vary response header. This will append the header, if not already listed, otherwise leaves it listed in the current location.

func (*Request) View

func (r *Request) View(data interface{}, views ...string)

func (*Request) Write

func (r *Request) Write(bodies ...interface{})

Write appends any input to the HTTP body response.

func (*Request) WriteResponse

func (r *Request) WriteResponse(resp ...interface{})

func (*Request) XHR

func (r *Request) XHR() bool

XHR returns a Boolean property, that is true, if the request’s X-Requested-With header field is XMLHttpRequest, indicating that the request was issued by a client library (such as jQuery).

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Error   e.Errors    `json:"errors"`
	Data    interface{} `json:"data"`
	Code    int         `json:"code"`
}

func (Response) HasError

func (response Response) HasError() bool

type URL

type URL struct {
	Query  url.Values
	Host   string
	Scheme string
	Path   string
	Raw    string
}

func (*URL) Set

func (u *URL) Set(key string, value interface{}) *URL

func (*URL) String

func (u *URL) String() string

Directories

Path Synopsis
apps
examples
lib
T
jwt
log
ref
tools/gaper
Package gaper implements a supervisor restarts a go project when it crashes or a watched file changes
Package gaper implements a supervisor restarts a go project when it crashes or a watched file changes

Jump to

Keyboard shortcuts

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