ncsfw

package module
v0.0.0-...-50a15a0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 20 Imported by: 1

README

N-CreativeSystem Web Application Framework

NCSがGolangでWeb Applicationを開発する際に使用するフレームワークです。

このWAFはGinEchoを参考にして開発しています。

標準でマルチテナントに対応したWAFを開発しています。

Documentation

Index

Constants

View Source
const (
	MIMEJSON              = binding.MIMEJSON
	MIMEHTML              = binding.MIMEHTML
	MIMEXML               = binding.MIMEXML
	MIMEXML2              = binding.MIMEXML2
	MIMEPlain             = binding.MIMEPlain
	MIMEPOSTForm          = binding.MIMEPOSTForm
	MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
	MIMEYAML              = binding.MIMEYAML
)

Variables

View Source
var (
	ErrRedirect = errors.New("redirect")
	ErrIgnore   = errors.New("ignore")
)

Functions

func AddMethods

func AddMethods(method string)

AddMethods anyMethodsに無いメソッドを追加する場合に使用

func Dir

func Dir(root string, listDirectory bool) http.FileSystem

Dir returns a http.FileSystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir() otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

Types

type AllocateContextFunc

type AllocateContextFunc func() Context

type Context

type Context interface {
	Reset(w http.ResponseWriter, r *http.Request, fullPath string, params *Params)
	Request() *http.Request
	SetRequest(*http.Request)
	Writer() ResponseWriter
	File(filePath string)
	Param(param string) string

	SetTenant(tenant models.Tenant)
	GetTenant() models.Tenant
	SetLoginUser(loginUser models.LoginUser)
	GetLoginUser() models.LoginUser
	IsSignedIn() bool
	SignedIn(isSigned bool)

	Logger() logger.Logger
	FullPath() string
	ClientIP() string

	Status(code int)
	HTML(code int, name string, obj interface{})
	JSON(code int, obj interface{})
	Redirect(code int, url string)

	BindJSON(obj interface{}) error
	BindQuery(obj interface{}) error
	BindParameter(obj interface{}) error
	MustBindWith(obj interface{}, b binding.Binding) error

	Query(key string) string
	GetHeader(key string) string
}

type EnginOption

type EnginOption interface {
	// contains filtered or unexported methods
}

func WithAllocateContext

func WithAllocateContext(fn AllocateContextFunc) EnginOption

type Engine

type Engine struct {
	RouterGroup

	TmplFunMap template.FuncMap
	HTMLRender render.HTMLRender

	TrustedPlatform     string
	AppEngine           bool
	ForwardedByClientIP bool
	RemoteIPHeaders     []string
	Logger              logger.Logger
	// contains filtered or unexported fields
}

func New

func New(opts ...EnginOption) *Engine

func (*Engine) Delims

func (e *Engine) Delims(left, right string) *Engine

func (*Engine) LoadHTMLGlob

func (e *Engine) LoadHTMLGlob(pattern string)

func (*Engine) NoMethod

func (e *Engine) NoMethod(handler HandlerFunc, middleware ...MiddlewareFunc) *Engine

func (*Engine) NoRoute

func (e *Engine) NoRoute(handler HandlerFunc, middleware ...MiddlewareFunc) *Engine

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Engine) SetHTMLTemplate

func (e *Engine) SetHTMLTemplate(templ *template.Template)

func (*Engine) Use

func (e *Engine) Use(middleware ...MiddlewareFunc) IRoutes

type HandlerFunc

type HandlerFunc func(c Context) error

type IRoutes

type IRoutes interface {
	Use(middleware ...MiddlewareFunc) IRoutes
	Handle(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Get(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Post(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Put(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Delete(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Patch(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Options(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Head(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes
	StaticFile(path, filepath string, middleware ...MiddlewareFunc) IRoutes
	Static(path, root string, middleware ...MiddlewareFunc) IRoutes
	StaticFS(path string, fs http.FileSystem, middleware ...MiddlewareFunc) IRoutes
	Group(prefix string, middleware ...MiddlewareFunc) IRoutes
}

type LocalResponseWriter

type LocalResponseWriter struct {
	// contains filtered or unexported fields
}

type Map

type Map map[string]interface{}

type MiddlewareFunc

type MiddlewareFunc func(next HandlerFunc) HandlerFunc

type Param

type Param struct {
	Key   string
	Value string
}

Param is a single URL parameter, consisting of a key and a value.

type Params

type Params []Param

Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.

func (Params) ByName

func (ps Params) ByName(name string) (va string)

ByName returns the value of the first Param which key matches the given name. If no matching Param is found, an empty string is returned.

func (Params) Get

func (ps Params) Get(name string) (string, bool)

Get returns the value of the first Param which key matches the given name and a boolean true. If no matching Param is found, an empty string is returned and a boolean false .

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher

	// Returns the HTTP response status code of the current request.
	Status() int

	// Returns the number of bytes already written into the response http body.
	// See Written()
	Size() int

	// Writes the string into the response body.
	WriteString(string) (int, error)

	// Returns true if the response body was already written.
	Written() bool

	// Forces to write the http header (status code + headers).
	WriteHeaderNow()

	// get the http.Pusher for server push
	Pusher() http.Pusher
	// contains filtered or unexported methods
}

type RouterGroup

type RouterGroup struct {
	// contains filtered or unexported fields
}

func (*RouterGroup) Any

func (r *RouterGroup) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Any anyMethodsに登録されているメソッドを登録

func (*RouterGroup) Delete

func (r *RouterGroup) Delete(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Delete DELETE

func (*RouterGroup) Get

func (r *RouterGroup) Get(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Get GET

func (*RouterGroup) Group

func (r *RouterGroup) Group(prefix string, middleware ...MiddlewareFunc) IRoutes

Group ルーターグループ

func (*RouterGroup) Handle

func (r *RouterGroup) Handle(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Handle handlerの登録

func (*RouterGroup) Head

func (r *RouterGroup) Head(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Head HEAD

func (*RouterGroup) Options

func (r *RouterGroup) Options(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Options OPTIONS

func (*RouterGroup) Patch

func (r *RouterGroup) Patch(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Patch PATCH

func (*RouterGroup) Post

func (r *RouterGroup) Post(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Post POST

func (*RouterGroup) Put

func (r *RouterGroup) Put(path string, handler HandlerFunc, middleware ...MiddlewareFunc) IRoutes

Put PUT

func (*RouterGroup) Static

func (r *RouterGroup) Static(path, root string, middleware ...MiddlewareFunc) IRoutes

Static 静的ファイルがあるディレクトリをhandlerに登録

func (*RouterGroup) StaticFS

func (r *RouterGroup) StaticFS(relativePath string, fs http.FileSystem, middleware ...MiddlewareFunc) IRoutes

StaticFS 静的ファイルを配信するhandlerを登録

func (*RouterGroup) StaticFile

func (r *RouterGroup) StaticFile(path, filepath string, middleware ...MiddlewareFunc) IRoutes

StaticFile 単一ファイルを配信するhandlerを登録

func (*RouterGroup) Use

func (r *RouterGroup) Use(middleware ...MiddlewareFunc) IRoutes

Use ルーターレベルでのミドルウェアの追加

Jump to

Keyboard shortcuts

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