Documentation ¶
Overview ¶
Package goblet is a golang web framework
Index ¶
- Constants
- Variables
- func FileWithName(file *os.File, name string) *fileWithName
- func ResetDB() error
- func SafeGo()
- func TestMatcher(url string, ctrls ...interface{}) (string, string)
- type AutoHide
- type BasicBlockOption
- func (h *BasicBlockOption) AutoHidden() bool
- func (b *BasicBlockOption) ErrorRender() string
- func (h *BasicBlockOption) GetRender() []string
- func (b *BasicBlockOption) GetRouting() []string
- func (b *BasicBlockOption) Layout() string
- func (h *BasicBlockOption) SetRender(renders []string)
- func (h *BasicBlockOption) String() string
- func (b *BasicBlockOption) TemplatePath() string
- func (h *BasicBlockOption) UpdateRender(o string, ctx *Context)
- type Block
- type BlockOption
- type ChangeSuffixOfConfig
- type Configer
- type Context
- func (c *Context) AddCookie(cookie *http.Cookie) error
- func (c *Context) AddInfo(key string, value interface{})
- func (c *Context) AddLoginId(id interface{}, setter ...LoginInfoSetter)
- func (c *Context) AddLoginIdAs(id interface{}, name string, setter ...LoginInfoSetter)
- func (c *Context) AddRespond(datas ...interface{})
- func (c *Context) AddSignedCookie(cookie *http.Cookie) (*http.Cookie, error)
- func (c *Context) AllowRender(renders ...string)
- func (c *Context) BasicAuth() (string, string, bool)
- func (c *Context) BlockOptionType() string
- func (c *Context) Body() io.ReadCloser
- func (c *Context) Callback() string
- func (c *Context) DelLogin() error
- func (c *Context) DelLoginAs(name string) error
- func (c *Context) EnableCache()
- func (c *Context) EnableCacheFrom(lastModified time.Time, duration ...time.Duration)
- func (cx *Context) Fill(v interface{}, fills ...bool) error
- func (cx *Context) FillAs(v interface{}, autofill bool, ct string) error
- func (c *Context) Form() url.Values
- func (c *Context) FormValue(key string) string
- func (c *Context) Format() string
- func (c *Context) FromAddr() net.Addr
- func (c *Context) GetCookie(name string) (*http.Cookie, error)
- func (c *Context) GetInfo(key string) (interface{}, bool)
- func (c *Context) GetLoginId() (string, bool)
- func (c *Context) GetLoginIdAs(name string) (string, bool)
- func (c *Context) GetLoginInfo() (*LoginContext, bool)
- func (c *Context) GetLoginInfoAs(name string) (*LoginContext, bool)
- func (cx *Context) GetRender() (render string, err error)
- func (c *Context) IntFormValue(key string) int64
- func (c *Context) Layout() string
- func (c *Context) Method() string
- func (c *Context) PathToURL(path string) (*url.URL, error)
- func (c *Context) PostForm() url.Values
- func (c *Context) QueryString(key string) string
- func (c *Context) RedirectTo(url string)
- func (c *Context) Referer() string
- func (c *Context) RemoteAddr() net.Addr
- func (c *Context) RemoteIP() (net.IP, error)
- func (c *Context) RenderAs(name string)
- func (c *Context) ReqHeader() http.Header
- func (c *Context) ReqHost() string
- func (c *Context) ReqMethod() string
- func (c *Context) ReqURL() *url.URL
- func (c *Context) ResetDB() error
- func (c *Context) Respond(data interface{})
- func (c *Context) RespondError(err error, context ...string)
- func (c *Context) RespondField(data interface{}, fields ...string)
- func (c *Context) RespondOK()
- func (c *Context) RespondReader(reader io.Reader)
- func (c *Context) RespondStatus(status int)
- func (c *Context) RespondWithRender(data interface{}, render string)
- func (c *Context) RespondWithStatus(data interface{}, status int)
- func (c *Context) RestRedirectToRead(id interface{})
- func (cx *Context) SaveFileAt(path ...string) *filerSaver
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetLayout(l string)
- func (c *Context) ShowHidden()
- func (c *Context) SignedCookie(name string) (*http.Cookie, error)
- func (c *Context) StatusCode() int
- func (c *Context) StrFormValue(key string) string
- func (c *Context) String() string
- func (c *Context) Suffix() string
- func (c *Context) TemplatePath() string
- func (c *Context) UseRender(render string)
- func (c *Context) UseStandErrPage() bool
- func (c *Context) UserAgent() string
- func (c *Context) Version() string
- func (ctx *Context) WrapError(err error, info string) error
- func (c *Context) Writer() http.ResponseWriter
- type ControllerNeedInit
- type ControllerNeedInitAndReturnError
- type CookieLoginInfoStorer
- type DbPwdPlugin
- type DefaultRenderSetter
- type DelimSetter
- type ErrFuncSetter
- type ErrorRender
- type File
- func (f *File) Close() error
- func (f *File) GetName() string
- func (f *File) GetSize() int64
- func (f *File) OpenInPrivate(s *Server) error
- func (f *File) Read(p []byte) (n int, err error)
- func (f *File) ReadAt(p []byte, off int64) (n int, err error)
- func (f *File) SaveInPrivate(dir string, s *Server) error
- func (f *File) SaveInPublic(dir string, s *Server) error
- func (f *File) SaveInTemp(dir string, s *Server) error
- func (f *File) Seek(offset int64, whence int) (int64, error)
- type FileGetter
- type Fn
- type FormFillFn
- type FormRequestDecoder
- type GroupController
- type HtmlBlockOption
- type JsonRequestDecoder
- type Kv
- type KvDriver
- type Layout
- type LocalSaver
- type LoginContext
- type LoginInfoSetter
- type LoginInfoStorer
- type MultiFormFillFn
- type MultiFormRequestDecoder
- type NewPlugin
- type OkFuncSetter
- type Option
- type RemoteAddr
- type Render
- type RequestDecoder
- type Response
- type RestBlockOption
- type RestController
- type Route
- type Saver
- type Server
- func (s *Server) AddConfig(name string, obj interface{}) error
- func (s *Server) AddFillForTypeInForm(typ string, fn FormFillFn)
- func (s *Server) AddFillForTypeInMultiForm(typ string, fn MultiFormFillFn)
- func (s *Server) AddFunc(name string, fn interface{})
- func (s *Server) AddModel(models interface{}, syncs ...bool)
- func (s *Server) ControlBy(block interface{})
- func (s *Server) Debug(fn func())
- func (s *Server) DelFileInPrivate(path string, force ...bool) error
- func (s *Server) DelFileInPublic(path string, force ...bool) error
- func (s *Server) Env() string
- func (s *Server) GetDelims() []string
- func (s *Server) GetPlugin(key string) NewPlugin
- func (s *Server) GetServerPathByCtrl(ctrl interface{}) []string
- func (s *Server) Hash(str string) string
- func (s *Server) KV(name string) Kv
- func (s *Server) Organize(name string, plugins []interface{})
- func (s *Server) Pre(fn interface{}, conds ...string)
- func (s *Server) PublicDir() string
- func (s *Server) Run() error
- func (s *Server) SaveInPrivate(path string, f io.Reader) error
- func (s *Server) SaveInPublic(path string, f io.Reader) error
- func (s *Server) ServeFile(w http.ResponseWriter, r *http.Request, file string)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetConfigSuffix(suffix string)
- func (s *Server) SetDefaultError(fn func(*Context, error, ...string))
- func (s *Server) SetDefaultOk(fn func(*Context))
- func (s *Server) WwwRoot() string
- type SilenceUrlSetter
- type SingleController
- type StringConfiger
- type XmlRequestDecoder
- type YamlConfiger
Constants ¶
const ( REST_READ = "read" REST_READMANY = "readmany" REST_DELETE = "delete" REST_EDIT = "edit" REST_NEW = "new" REST_CREATE = "create" REST_UPDATE = "update" REST_UPDATEMANY = "updatemany" REST_DELETEMANY = "deletemany" )
const ( DevelopEnv = config.DevelopEnv ProductEnv = config.ProductEnv )
const ( SAVEFILE_SUCCESS = iota SAVEFILE_STATE_DIR_ERROR = iota SAVEFILE_CREATE_DIR_ERROR = iota SAVEFILE_FORMFILE_ERROR = iota SAVEFILE_RENAME_ERROR_BY_USER = iota SAVEFILE_COPY_ERROR = iota )
const BasicConfig = `
basic:
env: development
db_engine: none
`
Variables ¶
var CookieIsMissing error = errors.New("Cookie is missing")
CookieIsMissing is returned when a cookie is missing.
var CookieNotValid error = errors.New("Cookie and signed cookie do not match")
CookieNotValid is returned when the cookie and its signed counterpart do not match.
I.e. the cookie value has been tampered with.
var DB *xorm.Engine
var Interrupted = errors.New("interrupted error")
var LogFile *os.File
var NoSuchRecord = errors.New("no such record")
var NotImplemented = fmt.Errorf("this method is not implemented")
var ( // SignedCookieFormat is the format string used to decide the name of the // signed cookie. SignedCookieFormat string = "%s_signed" )
var SignedCookieIsMissing error = errors.New("Signed cookie is missing")
SignedCookieIsMissing is returned when the signed cookie is missing.
var USERCOOKIENAME = "user"
Functions ¶
func FileWithName ¶
FileWithName make file can by download for another name
func TestMatcher ¶
Types ¶
type BasicBlockOption ¶
type BasicBlockOption struct {
// contains filtered or unexported fields
}
func (*BasicBlockOption) AutoHidden ¶
func (h *BasicBlockOption) AutoHidden() bool
func (*BasicBlockOption) ErrorRender ¶
func (b *BasicBlockOption) ErrorRender() string
func (*BasicBlockOption) GetRender ¶
func (h *BasicBlockOption) GetRender() []string
func (*BasicBlockOption) GetRouting ¶
func (b *BasicBlockOption) GetRouting() []string
func (*BasicBlockOption) Layout ¶
func (b *BasicBlockOption) Layout() string
func (*BasicBlockOption) SetRender ¶
func (h *BasicBlockOption) SetRender(renders []string)
func (*BasicBlockOption) String ¶
func (h *BasicBlockOption) String() string
func (*BasicBlockOption) TemplatePath ¶
func (b *BasicBlockOption) TemplatePath() string
func (*BasicBlockOption) UpdateRender ¶
func (h *BasicBlockOption) UpdateRender(o string, ctx *Context)
type BlockOption ¶
type BlockOption interface { UpdateRender(string, *Context) GetRouting() []string MatchSuffix(string) bool //Get the render by user require, if required render is not allow, pass RenderNotAllowed GetRender() (render []string) //Reset the allowed renders SetRender([]string) //Call the function in object and Parse data, this function used before //the render prepared. So you can change function and render in here Parse(*Context) error Layout() string TemplatePath() string ErrorRender() string AutoHidden() bool //Get the type of block String() string }
type ChangeSuffixOfConfig ¶
type ChangeSuffixOfConfig interface {
GetConfigSuffix() string
}
ChangeSuffixOfConfig Change the config file suffix, default is conf
type Context ¶
type Context struct { Server *Server // contains filtered or unexported fields }
func (*Context) AddLoginId ¶
func (c *Context) AddLoginId(id interface{}, setter ...LoginInfoSetter)
func (*Context) AddLoginIdAs ¶
func (c *Context) AddLoginIdAs(id interface{}, name string, setter ...LoginInfoSetter)
func (*Context) AddRespond ¶
func (c *Context) AddRespond(datas ...interface{})
Respond with multi data, data will tread as a key-value map for example: AddRespond("key1","value1",key2","value2") You can use AddRespond multi time in controller
func (*Context) AddSignedCookie ¶
AddSignedCookie adds the specified cookie to the response and also adds an additional 'signed' cookie that is used to validate the cookies value when SignedCookie is called.
func (*Context) AllowRender ¶
AllowRender Allow some temporary render
func (*Context) BlockOptionType ¶
/////////for renders/////////////
func (*Context) Body ¶
func (c *Context) Body() io.ReadCloser
func (*Context) DelLoginAs ¶
Delete the login cookie as specified name
func (*Context) EnableCache ¶
func (c *Context) EnableCache()
EnableCache 手工启用缓存,默认Last-Modified为当前时间,Cache-Control为一年
func (*Context) EnableCacheFrom ¶
EnableCache 手工启用缓存,如果不传递时间参数,则默认Last-Modified为当前时间,Cache-Control为一年 如果传递一个时间参数,则Last-Modified为该时间,Cache-Control为一年, 如果传递两个时间参数,则Last-Modified为第一个时间,Cache-Control为第二个时间和第一个时间的差值
func (*Context) Fill ¶
goweb.Context Helper function to fill a variable with the contents of the request body. The body will be decoded based on the content-type and an apropriate RequestDecoder automatically selected If you want to use md5 function for the specified field, please add md5 tag for it. AND the md5 tag must be the last one of the tags, so if you have no other tag, please add ',' before md5
func (*Context) FromAddr ¶
返回对端地址,请注意,如果是负载均衡过来的请求,会直接返回负载均衡地址,不会重新获取客户端地址,如果要 获取这种情况下的客户端正式IP,请调用 RemoteAddr方法
func (*Context) GetLoginId ¶
func (*Context) GetLoginInfo ¶
func (c *Context) GetLoginInfo() (*LoginContext, bool)
func (*Context) GetLoginInfoAs ¶
func (c *Context) GetLoginInfoAs(name string) (*LoginContext, bool)
func (*Context) IntFormValue ¶
func (*Context) QueryString ¶
func (*Context) RedirectTo ¶
func (*Context) RemoteAddr ¶
该方法返回对端连接地址,返回有两种情况,如果头部没有X-Forwarded-For,表示是直接从客户端直接连接的。 此时,返回的addr,Network()方法返回“tcp"。如果头部有X-Forwarded-For,表示是从负载均衡跳转过来的。 此时,返回的addr,Network()方法返回“ip”
func (*Context) Respond ¶
func (c *Context) Respond(data interface{})
Respond 向用户返回内容,三种数据会进行特别处理: error类型:标记状态为内部错误 []byte类型:使用raw进行内容渲染,即原样输出,不进行json等格式转化 reader:使用raw进行内容渲染,即原样从输入中读取输出,不进行json等格式转化
func (*Context) RespondError ¶
RespondError 返回错误,如果错误为空,返回成功
func (*Context) RespondField ¶
func (*Context) RespondReader ¶
func (*Context) RespondStatus ¶
func (*Context) RespondWithRender ¶
func (*Context) RespondWithStatus ¶
func (*Context) RestRedirectToRead ¶
func (c *Context) RestRedirectToRead(id interface{})
func (*Context) SaveFileAt ¶
func (*Context) ShowHidden ¶
func (c *Context) ShowHidden()
func (*Context) SignedCookie ¶
Gets the cookie specified by name and validates that its value has not been tampered with by checking the signed cookie too. Will return CookieNotValid error if it has been tampered with, otherwise, it will return the actual cookie.
func (*Context) StatusCode ¶
func (*Context) StrFormValue ¶
func (*Context) TemplatePath ¶
func (*Context) UseStandErrPage ¶
func (*Context) Writer ¶
func (c *Context) Writer() http.ResponseWriter
type ControllerNeedInit ¶
type ControllerNeedInit interface {
Init(*Server)
}
type CookieLoginInfoStorer ¶
type CookieLoginInfoStorer struct{}
func (*CookieLoginInfoStorer) AddLoginAs ¶
func (c *CookieLoginInfoStorer) AddLoginAs(ctx *Context, lctx *LoginContext)
func (*CookieLoginInfoStorer) DeleteLoginAs ¶
func (c *CookieLoginInfoStorer) DeleteLoginAs(ctx *Context, key string) error
func (*CookieLoginInfoStorer) GetLoginIdAs ¶
func (c *CookieLoginInfoStorer) GetLoginIdAs(ctx *Context, key string) (*LoginContext, error)
type DbPwdPlugin ¶
DbPwdPlugin Change the db connection password
type DefaultRenderSetter ¶
type DefaultRenderSetter interface {
DefaultRender() string
}
type DelimSetter ¶
type DelimSetter interface {
SetDelim() [2]string
}
type ErrFuncSetter ¶
type ErrorRender ¶
type ErrorRender byte
type File ¶
type File struct { //Name the filename uploaded with file Name string //Path the filepath after saved in server Path string Header textproto.MIMEHeader `json:"-"` Size int64 // contains filtered or unexported fields }
File the input file type, if you want to response a file, just response(*os.File)
func Open ¶
Open open file in any location of server, if want to open file relate to www dir, please use OpenInPrivate
func (*File) OpenInPrivate ¶
type FileGetter ¶
type FormFillFn ¶
type GroupController ¶
type GroupController byte
Controller which match full path and path with any suffix, eg. a GroupController with name Test will match /test and /test/1 and /test/a/b/c
type HtmlBlockOption ¶
type HtmlBlockOption struct {
BasicBlockOption
}
func (*HtmlBlockOption) MatchSuffix ¶
func (h *HtmlBlockOption) MatchSuffix(suffix string) bool
func (*HtmlBlockOption) Parse ¶
func (h *HtmlBlockOption) Parse(c *Context) error
func (*HtmlBlockOption) String ¶
func (h *HtmlBlockOption) String() string
type JsonRequestDecoder ¶
type JsonRequestDecoder struct{}
a JSON decoder for request body (just a wrapper to json.Unmarshal)
type Kv ¶
type Kv interface { Get(name string, pointer interface{}) error Set(name string, pointer interface{}) error Del(name string) error Keys() []string }
用于获取数值的接口
type KvDriver ¶
type KvDriver interface {
Collection(string) Kv //specified the table name and return the collection
}
用户指定KV驱动的接口
type LocalSaver ¶
type LocalSaver struct { }
type LoginContext ¶
func (*LoginContext) HasAttr ¶
func (l *LoginContext) HasAttr(key string, content interface{}) bool
type LoginInfoSetter ¶
type LoginInfoSetter func(*LoginContext)
func WithAttribute ¶
func WithAttribute(key string, value interface{}) LoginInfoSetter
func WithDuration ¶
func WithDuration(t time.Duration) LoginInfoSetter
type LoginInfoStorer ¶
type LoginInfoStorer interface { AddLoginAs(ctx *Context, lctx *LoginContext) GetLoginIdAs(ctx *Context, key string) (*LoginContext, error) DeleteLoginAs(ctx *Context, key string) error }
type MultiFormFillFn ¶
type MultiFormRequestDecoder ¶
type MultiFormRequestDecoder struct{}
a form-enc decoder for request body
type OkFuncSetter ¶
type OkFuncSetter interface {
RespendOk(*Context)
}
type RemoteAddr ¶
type RemoteAddr struct {
// contains filtered or unexported fields
}
func (*RemoteAddr) Network ¶
func (r *RemoteAddr) Network() string
func (*RemoteAddr) String ¶
func (r *RemoteAddr) String() string
type RequestDecoder ¶
types that impliment RequestDecoder can unmarshal the request body into an apropriate type/struct
type RestBlockOption ¶
type RestBlockOption struct {
BasicBlockOption
}
func (*RestBlockOption) MatchSuffix ¶
func (r *RestBlockOption) MatchSuffix(suffix string) bool
func (*RestBlockOption) Parse ¶
func (r *RestBlockOption) Parse(c *Context) error
func (*RestBlockOption) String ¶
func (h *RestBlockOption) String() string
func (*RestBlockOption) UpdateRender ¶
func (r *RestBlockOption) UpdateRender(obj string, ctx *Context)
type RestController ¶
type RestController byte
Controller which match full path according to RESTful rules, eg. a RestController with name Test will match /test and /test/1
type Server ¶
type Server struct { ConfigFile string Basic config.Basic Cache config.Cache Log config.Log Db config.Db Renders map[string]render.Render Name string // contains filtered or unexported fields }
Server 服务器类型
var DefaultServer *Server
func (*Server) AddFillForTypeInForm ¶
func (s *Server) AddFillForTypeInForm(typ string, fn FormFillFn)
func (*Server) AddFillForTypeInMultiForm ¶
func (s *Server) AddFillForTypeInMultiForm(typ string, fn MultiFormFillFn)
func (*Server) ControlBy ¶
func (s *Server) ControlBy(block interface{})
ControlBy Use Member of struct of type goblet.Router to redefine the path
func (*Server) Debug ¶
func (s *Server) Debug(fn func())
Debug 当服务器环境为调试环境时,执行相应的匿名函数,用于编写调试环境专用的代码块
func (*Server) DelFileInPrivate ¶
func (*Server) GetServerPathByCtrl ¶
func (*Server) SaveInPrivate ¶
将文件保存在私有目录,不可以使用http访问到
func (*Server) SaveInPublic ¶
将文件保存在公开目录,可以使用http访问到
func (*Server) SetConfigSuffix ¶
func (*Server) SetDefaultError ¶
func (*Server) SetDefaultOk ¶
type SilenceUrlSetter ¶
type SingleController ¶
type SingleController byte
Controller which only match full path eg. a SingleController with name Test will just match /test, not /test/1
type StringConfiger ¶
type StringConfiger struct {
Content string
}
StringConfiger is a configer that read config from a string
func (*StringConfiger) GetConfigSource ¶
func (c *StringConfiger) GetConfigSource(s *Server) (io.Reader, error)
type YamlConfiger ¶
type YamlConfiger struct { }
func (*YamlConfiger) GetConfigSource ¶
func (c *YamlConfiger) GetConfigSource(s *Server) (io.Reader, error)
Source Files ¶
- block.go
- blockoption.go
- config.go
- configer.go
- const.go
- context.go
- context_login.go
- cookie.go
- db.go
- error.go
- file.go
- file_for_response.go
- file_manager.go
- fill.go
- func.go
- hide.go
- kv.go
- log.go
- login_info.go
- matcher.go
- null_writer.go
- option.go
- organizer.go
- plugin.go
- response.go
- router.go
- safego.go
- server.go
- utils.go