Esempio n. 1
0
package iris

import (
	"sync"

	"github.com/iris-contrib/errors"

	"github.com/kataras/iris/logger"
	"github.com/kataras/iris/utils"
)

var (
	// errPluginAlreadyExists returns an error with message: 'Cannot activate the same plugin again, plugin '+plugin name[+plugin description]' is already exists'
	errPluginAlreadyExists = errors.New("Cannot use the same plugin again, '%s[%s]' is already exists")
	// errPluginActivate returns an error with message: 'While trying to activate plugin '+plugin name'. Trace: +specific error'
	errPluginActivate = errors.New("While trying to activate plugin '%s'. Trace: %s")
	// errPluginRemoveNoPlugins returns an error with message: 'No plugins are registed yet, you cannot remove a plugin from an empty list!'
	errPluginRemoveNoPlugins = errors.New("No plugins are registed yet, you cannot remove a plugin from an empty list!")
	// errPluginRemoveEmptyName returns an error with message: 'Plugin with an empty name cannot be removed'
	errPluginRemoveEmptyName = errors.New("Plugin with an empty name cannot be removed")
	// errPluginRemoveNotFound returns an error with message: 'Cannot remove a plugin which doesn't exists'
	errPluginRemoveNotFound = errors.New("Cannot remove a plugin which doesn't exists")
)

type (
	// Plugin just an empty base for plugins
	// A Plugin can be added with: .Add(PreListenFunc(func(*Framework))) and so on... or
	// .Add(myPlugin{},myPlugin2{}) which myPlugin is  a struct with any of the methods below or
	// .PostListen(func(*Framework)) and so on...
	Plugin interface {
	}
Esempio n. 2
0
	StatusBadGateway:                    "Bad Gateway",
	StatusServiceUnavailable:            "Service Unavailable",
	StatusGatewayTimeout:                "Gateway Timeout",
	StatusHTTPVersionNotSupported:       "HTTP Version Not Supported",
	StatusNetworkAuthenticationRequired: "Network Authentication Required",
}

// StatusText returns a text for the HTTP status code. It returns the empty
// string if the code is unknown.
func StatusText(code int) string {
	return statusText[code]
}

// Errors introduced by server.
var (
	errServerPortAlreadyUsed = errors.New("Server can't run, port is already used")
	errServerAlreadyStarted  = errors.New("Server is already started and listening")
	errServerConfigMissing   = errors.New("Empty Config for server")
	errServerHandlerMissing  = errors.New("Handler is missing from server, can't start without handler")
	errServerIsClosed        = errors.New("Can't close the server, propably is already closed or never started")
	errServerRemoveUnix      = errors.New("Unexpected error when trying to remove unix socket file. Addr: %s | Trace: %s")
	errServerChmod           = errors.New("Cannot chmod %#o for %q: %s")
)

// Server the http server
type Server struct {
	*fasthttp.Server
	listener net.Listener
	Config   *config.Server
	tls      bool
	mu       sync.Mutex
Esempio n. 3
0
File: iris.go Progetto: Carbyn/iris
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// ----------------------------------MuxAPI implementation------------------------------
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------

type muxAPI struct {
	mux          *serveMux
	relativePath string
	middleware   Middleware
}

var (
	// errAPIContextNotFound returns an error with message: 'From .API: "Context *iris.Context could not be found..'
	errAPIContextNotFound = errors.New("From .API: Context *iris.Context could not be found.")
	// errDirectoryFileNotFound returns an error with message: 'Directory or file %s couldn't found. Trace: +error trace'
	errDirectoryFileNotFound = errors.New("Directory or file %s couldn't found. Trace: %s")
)

var _ MuxAPI = &muxAPI{}

// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
// Party can also be named as 'Join' or 'Node' or 'Group' , Party chosen because it has more fun
func Party(relativePath string, handlersFn ...HandlerFunc) MuxAPI {
	return Default.Party(relativePath, handlersFn...)
}

// Party is just a group joiner of routes which have the same prefix and share same middleware(s) also.
// Party can also be named as 'Join' or 'Node' or 'Group' , Party chosen because it has more fun
func (api *muxAPI) Party(relativePath string, handlersFn ...HandlerFunc) MuxAPI {
Esempio n. 4
0
File: run.go Progetto: calvimor/iris
import (
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"sync/atomic"

	"github.com/iris-contrib/errors"
	"github.com/kataras/cli"
	"github.com/kataras/iris/utils"
)

var (
	errInvalidArgs = errors.New("Invalid arguments [%s], type -h to get assistant")
	errInvalidExt  = errors.New("%s is not a go program")
	errUnexpected  = errors.New("Unexpected error!!! Please post an issue here: https://github.com/kataras/iris/issues")
	errBuild       = errors.New("\n Failed to build the %s iris program. Trace: %s")
	errRun         = errors.New("\n Failed to run the %s iris program. Trace: %s")
	goExt          = ".go"
)

var times uint32 = 0

func build(sourcepath string) error {
	goBuild := utils.CommandBuilder("go", "build", sourcepath)
	goBuild.Dir = workingDir
	goBuild.Stdout = os.Stdout
	goBuild.Stderr = os.Stderr
	if err := goBuild.Run(); err != nil {
Esempio n. 5
0
package utils

import (
	"github.com/iris-contrib/errors"
)

var (
	// ErrNoZip returns an error with message: 'While creating file '+filename'. It's not a zip'
	ErrNoZip = errors.New("While installing file '%s'. It's not a zip")
	// ErrFileOpen returns an error with message: 'While opening a file. Trace: +specific error'
	ErrFileOpen = errors.New("While opening a file. Trace: %s")
	// ErrFileCreate returns an error with message: 'While creating a file. Trace: +specific error'
	ErrFileCreate = errors.New("While creating a file. Trace: %s")
	// ErrFileRemove returns an error with message: 'While removing a file. Trace: +specific error'
	ErrFileRemove = errors.New("While removing a file. Trace: %s")
	// ErrFileCopy returns an error with message: 'While copying files. Trace: +specific error'
	ErrFileCopy = errors.New("While copying files. Trace: %s")
	// ErrFileDownload returns an error with message: 'While downloading from +specific url. Trace: +specific error'
	ErrFileDownload = errors.New("While downloading from %s. Trace: %s")
	// ErrDirCreate returns an error with message: 'Unable to create directory on '+root dir'. Trace: +specific error
	ErrDirCreate = errors.New("Unable to create directory on '%s'. Trace: %s")
)
Esempio n. 6
0
	// IfModifiedSince "If-Modified-Since"
	ifModifiedSince = "If-Modified-Since"
	// ContentDisposition "Content-Disposition"
	contentDisposition = "Content-Disposition"

	// stopExecutionPosition used inside the Context, is the number which shows us that the context's middleware manualy stop the execution
	stopExecutionPosition = 255
)

// this pool is used everywhere needed in the iris for example inside party-> Static
var gzipWriterPool = sync.Pool{New: func() interface{} { return &gzip.Writer{} }}

// errors

var (
	errTemplateExecute  = errors.New("Unable to execute a template. Trace: %s")
	errFlashNotFound    = errors.New("Unable to get flash message. Trace: Cookie does not exists")
	errSessionNil       = errors.New("Unable to set session, Config().Session.Provider is nil, please refer to the docs!")
	errNoForm           = errors.New("Request has no any valid form")
	errWriteJSON        = errors.New("Before JSON be written to the body, JSON Encoder returned an error. Trace: %s")
	errRenderMarshalled = errors.New("Before +type Rendering, MarshalIndent returned an error. Trace: %s")
	errReadBody         = errors.New("While trying to read %s from the request body. Trace %s")
	errServeContent     = errors.New("While trying to serve content to the client. Trace %s")
)

type (
	// Map is just a conversion for a map[string]interface{}
	Map map[string]interface{}
	// Context is resetting every time a request is coming to the server
	// it is not good practice to use this object in goroutines, for these cases use the .Clone()
	Context struct {
Esempio n. 7
0
package service

import (
	"time"

	"github.com/garyburd/redigo/redis"
	"github.com/iris-contrib/errors"
	"github.com/kataras/iris/config"
)

var (
	// ErrRedisClosed an error with message 'Redis is already closed'
	ErrRedisClosed = errors.New("Redis is already closed")
	// ErrKeyNotFound an error with message 'Key $thekey doesn't found'
	ErrKeyNotFound = errors.New("Key '%s' doesn't found")
)

// Service the Redis service, contains the config and the redis pool
type Service struct {
	// Connected is true when the Service has already connected
	Connected bool
	// Config the redis config for this redis
	Config *config.Redis
	pool   *redis.Pool
}

// PingPong sends a ping and receives a pong, if no pong received then returns false and filled error
func (r *Service) PingPong() (bool, error) {
	c := r.pool.Get()
	defer c.Close()
	msg, err := c.Do("PING")