2016-05-30 16:08:09 +02:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
|
|
|
"time"
|
2016-06-22 11:45:57 +02:00
|
|
|
|
|
|
|
"github.com/kataras/iris/sessions/store"
|
|
|
|
"github.com/markbates/goth"
|
|
|
|
"github.com/valyala/fasthttp"
|
2016-05-30 16:08:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// IContext the interface for the Context
|
|
|
|
IContext interface {
|
|
|
|
IContextRenderer
|
|
|
|
IContextStorage
|
|
|
|
IContextBinder
|
|
|
|
IContextRequest
|
|
|
|
IContextResponse
|
2016-06-22 03:22:12 +02:00
|
|
|
IContextAuth
|
2016-06-14 07:45:40 +02:00
|
|
|
SendMail(string, string, ...string) error
|
|
|
|
Log(string, ...interface{})
|
2016-05-30 16:08:09 +02:00
|
|
|
Reset(*fasthttp.RequestCtx)
|
|
|
|
GetRequestCtx() *fasthttp.RequestCtx
|
|
|
|
Clone() IContext
|
|
|
|
Do()
|
|
|
|
Next()
|
|
|
|
StopExecution()
|
|
|
|
IsStopped() bool
|
|
|
|
GetHandlerName() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// IContextBinder is part of the IContext
|
|
|
|
IContextBinder interface {
|
|
|
|
ReadJSON(interface{}) error
|
|
|
|
ReadXML(interface{}) error
|
|
|
|
ReadForm(formObject interface{}) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// IContextRenderer is part of the IContext
|
|
|
|
IContextRenderer interface {
|
|
|
|
Write(string, ...interface{})
|
2016-06-14 07:45:40 +02:00
|
|
|
HTML(int, string)
|
2016-05-30 16:08:09 +02:00
|
|
|
// Data writes out the raw bytes as binary data.
|
|
|
|
Data(status int, v []byte) error
|
2016-06-14 07:45:40 +02:00
|
|
|
// RenderWithStatus builds up the response from the specified template and bindings.
|
|
|
|
RenderWithStatus(status int, name string, binding interface{}, layout ...string) error
|
|
|
|
// Render same as .RenderWithStatus but with status to iris.StatusOK (200)
|
2016-05-30 16:08:09 +02:00
|
|
|
Render(name string, binding interface{}, layout ...string) error
|
2016-06-03 05:17:40 +02:00
|
|
|
// MustRender same as .Render but returns 500 internal server http status (error) if rendering fail
|
|
|
|
MustRender(name string, binding interface{}, layout ...string)
|
2016-06-14 07:45:40 +02:00
|
|
|
// TemplateString accepts a template filename, its context data and returns the result of the parsed template (string)
|
|
|
|
// if any error returns empty string
|
|
|
|
TemplateString(name string, binding interface{}, layout ...string) string
|
2016-06-01 03:45:11 +02:00
|
|
|
// MarkdownString parses the (dynamic) markdown string and returns the converted html string
|
|
|
|
MarkdownString(markdown string) string
|
|
|
|
// Markdown parses and renders to the client a particular (dynamic) markdown string
|
|
|
|
// accepts two parameters
|
|
|
|
// first is the http status code
|
|
|
|
// second is the markdown string
|
|
|
|
Markdown(status int, markdown string)
|
2016-05-30 16:08:09 +02:00
|
|
|
// JSON marshals the given interface object and writes the JSON response.
|
|
|
|
JSON(status int, v interface{}) error
|
|
|
|
// JSONP marshals the given interface object and writes the JSON response.
|
|
|
|
JSONP(status int, callback string, v interface{}) error
|
|
|
|
// Text writes out a string as plain text.
|
|
|
|
Text(status int, v string) error
|
|
|
|
// XML marshals the given interface object and writes the XML response.
|
|
|
|
XML(status int, v interface{}) error
|
|
|
|
|
|
|
|
ExecuteTemplate(*template.Template, interface{}) error
|
|
|
|
ServeContent(io.ReadSeeker, string, time.Time, bool) error
|
|
|
|
ServeFile(string, bool) error
|
|
|
|
SendFile(filename string, destinationName string) error
|
|
|
|
Stream(func(*bufio.Writer))
|
|
|
|
StreamWriter(cb func(writer *bufio.Writer))
|
|
|
|
StreamReader(io.Reader, int)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IContextRequest is part of the IContext
|
|
|
|
IContextRequest interface {
|
|
|
|
Param(string) string
|
|
|
|
ParamInt(string) (int, error)
|
|
|
|
URLParam(string) string
|
|
|
|
URLParamInt(string) (int, error)
|
|
|
|
URLParams() map[string]string
|
|
|
|
MethodString() string
|
|
|
|
HostString() string
|
2016-06-04 22:07:19 +02:00
|
|
|
Subdomain() string
|
2016-05-30 16:08:09 +02:00
|
|
|
PathString() string
|
2016-06-14 07:45:40 +02:00
|
|
|
RequestPath(bool) string
|
2016-05-30 16:08:09 +02:00
|
|
|
RequestIP() string
|
|
|
|
RemoteAddr() string
|
|
|
|
RequestHeader(k string) string
|
|
|
|
PostFormValue(string) string
|
2016-06-14 07:45:40 +02:00
|
|
|
// PostFormMulti returns a slice of string from post request's data
|
|
|
|
PostFormMulti(string) []string
|
2016-05-30 16:08:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// IContextResponse is part of the IContext
|
|
|
|
IContextResponse interface {
|
|
|
|
// SetStatusCode sets the http status code
|
|
|
|
SetStatusCode(int)
|
|
|
|
// SetContentType sets the "Content-Type" header, receives the value
|
|
|
|
SetContentType(string)
|
|
|
|
// SetHeader sets the response headers first parameter is the key, second is the value
|
|
|
|
SetHeader(string, string)
|
|
|
|
Redirect(string, ...int)
|
2016-06-02 18:22:36 +02:00
|
|
|
RedirectTo(routeName string, args ...interface{})
|
2016-05-30 16:08:09 +02:00
|
|
|
// Errors
|
|
|
|
NotFound()
|
|
|
|
Panic()
|
|
|
|
EmitError(int)
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
// IContextStorage is part of the IContext
|
|
|
|
IContextStorage interface {
|
|
|
|
Get(string) interface{}
|
|
|
|
GetString(string) string
|
|
|
|
GetInt(string) int
|
|
|
|
Set(string, interface{})
|
|
|
|
SetCookie(*fasthttp.Cookie)
|
|
|
|
SetCookieKV(string, string)
|
|
|
|
RemoveCookie(string)
|
|
|
|
// Flash messages
|
|
|
|
GetFlash(string) string
|
|
|
|
GetFlashBytes(string) ([]byte, error)
|
|
|
|
SetFlash(string, string)
|
|
|
|
SetFlashBytes(string, []byte)
|
|
|
|
Session() store.IStore
|
|
|
|
SessionDestroy()
|
|
|
|
}
|
2016-06-22 03:22:12 +02:00
|
|
|
|
|
|
|
// IContextAuth handles the authentication/authorization
|
|
|
|
IContextAuth interface {
|
2016-06-22 15:01:31 +02:00
|
|
|
// SetOAuthUser sets the oauth user
|
|
|
|
// Internal method but exported because useful for advanced use cases
|
|
|
|
// Iris uses this method to set automatically the authenticated user.
|
|
|
|
SetOAuthUser(goth.User)
|
|
|
|
// OAuthUser returns the authenticated User
|
2016-06-22 11:45:57 +02:00
|
|
|
// See https://github.com/iris-contrib/gothic/blob/master/example/main.go to see this in action.
|
2016-06-22 15:01:31 +02:00
|
|
|
OAuthUser() goth.User
|
2016-06-22 03:22:12 +02:00
|
|
|
}
|
2016-05-30 16:08:09 +02:00
|
|
|
)
|