goblet

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

README

Goblet Golang Http 框架 / Goblet Golang HTTP Framework

概述 / Overview

Goblet是一款基于Go语言开发的HTTP框架,他的第一版已经有11年的历史了,整体设计上参考了Ruby on Rails的设计理念,目标不是提供轻量化框架,而是提供一个功能丰富、易于上手的解决方案。

Goblet is a HTTP framework developed in Go language. Its first version has a history of 11 years. The overall design is inspired by Ruby on Rails, aiming not to provide a lightweight framework, but a feature-rich and easy-to-use solution.

v2版本设计目标 / v2 Design Goals

在11年后,Goblet的v2版本将重新设计,目标是提供一个更现代、更灵活和易于使用的框架。以下是v2版本的几个主要设计目标:

After 11 years, Goblet v2 will be redesigned with the goal of providing a more modern, flexible and easy-to-use framework. Here are the main design goals for v2:

  • 切换至Gorm,原来设计基于xorm,v2将切换到Gorm,这将带来更好的性能和更丰富的功能。

    • Switch to Gorm, the original design was based on xorm, v2 will switch to Gorm, which will bring better performance and richer features.
  • 引入更灵活的路由系统,支持参数化路由和中间件。

    • Introduce a more flexible routing system that supports parameterized routes and middleware.
  • 默认以JSON作为数据交换格式,并提供灵活的配置选项。原来优先Html模板,v2将改为优先JSON。

    • Use JSON as the default data exchange format and provide flexible configuration options. Originally prioritized HTML templates, v2 will prioritize JSON.
  • 从logrus切换到slog

    • Switch from logrus to slog
  • 提供完善的文档和示例,帮助开发者快速上手,也帮助AI更好地理解框架的使用。

    • Provide complete documentation and examples to help developers get started quickly and also help AI better understand the framework usage.
  • 提供更清晰的命名规范和代码结构,提高可读性和维护性。

    • Provide clearer naming conventions and code structure to improve readability and maintainability.
  • 如果可能的话,提升性能。

    • Improve performance if possible.
  • 使用标准化的form,json解析库和tag标注模式

    • Use standardized form, json parsing libraries and tag annotation patterns.

    创建一个新的项目 / Create a new project

    import "github.com/extrame/goblet"
    
    func main() {
      var server = goblet.Organize("project_name")
      server.ControlBy(&MyController{})
      server.Run()
    }
    

Documentation

Overview

Package goblet is a golang web framework

Index

Constants

View Source
const (
	DevelopEnv = config.DevelopEnv
	ProductEnv = config.ProductEnv
)
View Source
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
)
View Source
const BasicConfig = `
basic:
  env: development
  db_engine: none
`

Variables

View Source
var CookieIsMissing error = errors.New("Cookie is missing")

CookieIsMissing is returned when a cookie is missing.

View Source
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.

View Source
var LogFile *os.File
View Source
var NoSuchRecord = errors.New("no such record")
View Source
var NotImplemented = fmt.Errorf("this method is not implemented")
View Source
var (
	// SignedCookieFormat is the format string used to decide the name of the
	// signed cookie.
	SignedCookieFormat string = "%s_signed"
)
View Source
var SignedCookieIsMissing error = errors.New("Signed cookie is missing")

SignedCookieIsMissing is returned when the signed cookie is missing.

View Source
var USERCOOKIENAME = "user"

Functions

func FileWithName

func FileWithName(file io.ReadSeeker, name string) *fileWithName

FileWithName make file can by download for another name

func Interrupted

func Interrupted(reason string) error

Interrupted creates a new interrupted error with custom message, interrupted error will make goblet stop processing and return the error to client, like in any Pre function

func SafeGo

func SafeGo()

Use for defer unsafe go runtime

func StdError

func StdError(code int, msg string) error

func TestMatcher

func TestMatcher(url string, ctrls ...interface{}) (string, string, map[string]string)

func WrapError

func WrapError(code int, err error) error

Types

type AutoHide

type AutoHide byte

type Block

type Block interface {
}

Block is a group of http request

type ChangeSuffixOfConfig

type ChangeSuffixOfConfig interface {
	GetConfigSuffix() string
}

ChangeSuffixOfConfig Change the config file suffix, default is conf

type Configer

type Configer interface {
	GetConfigSource(s *Server) (io.Reader, error)
}

type Context

type Context struct {
	Server  *Server
	Request *http.Request

	DB *gorm.DB // 数据库连接
	// contains filtered or unexported fields
}

func (*Context) AddCookie

func (c *Context) AddCookie(cookie *http.Cookie) error

func (*Context) AddInfo

func (c *Context) AddInfo(key string, value interface{})

func (*Context) AddLoginId

func (c *Context) AddLoginId(id interface{}, setter ...LoginInfoSetter) string

func (*Context) AddLoginIdAs

func (c *Context) AddLoginIdAs(id interface{}, name string, setter ...LoginInfoSetter) string

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

func (c *Context) AddSignedCookie(cookie *http.Cookie) (*http.Cookie, error)

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

func (c *Context) AllowRender(renders ...string)

AllowRender Allow some temporary render

func (*Context) BasicAuth

func (c *Context) BasicAuth() (string, string, bool)

BasicAuth 返回Basic Auth

func (*Context) BlockOptionType

func (c *Context) BlockOptionType() string

/////////for renders/////////////

func (*Context) Body

func (c *Context) Body() io.ReadCloser

func (*Context) Callback

func (c *Context) Callback() string

func (*Context) DelLogin

func (c *Context) DelLogin() error

Delete the login cookie saved

func (*Context) DelLoginAs

func (c *Context) DelLoginAs(name string) error

Delete the login cookie as specified name

func (*Context) EnableCache

func (c *Context) EnableCache()

EnableCache 手工启用缓存,默认Last-Modified为当前时间,Cache-Control为一年

func (*Context) EnableCacheFrom

func (c *Context) EnableCacheFrom(lastModified time.Time, duration ...time.Duration)

EnableCache 手工启用缓存,如果不传递时间参数,则默认Last-Modified为当前时间,Cache-Control为一年 如果传递一个时间参数,则Last-Modified为该时间,Cache-Control为一年, 如果传递两个时间参数,则Last-Modified为第一个时间,Cache-Control为第二个时间和第一个时间的差值

func (*Context) EnableSse

func (c *Context) EnableSse(options ...SseOption) error

EnableSse 启用SSE连接,设置必要的响应头

func (*Context) EncryptLoginContext

func (c *Context) EncryptLoginContext(lctx *LoginContext) string

EncryptLoginContext encrypt the login context to a token

func (*Context) Env

func (c *Context) Env() string

func (*Context) Fill

func (cx *Context) Fill(v interface{}, fills ...bool) error

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) FillAs

func (cx *Context) FillAs(v interface{}, autofill bool, ct string) error

func (*Context) Form

func (c *Context) Form() url.Values

func (*Context) FormValue

func (c *Context) FormValue(key string) string

func (*Context) Format

func (c *Context) Format() string

func (*Context) FromAddr

func (c *Context) FromAddr() net.Addr

返回对端地址,请注意,如果是负载均衡过来的请求,会直接返回负载均衡地址,不会重新获取客户端地址,如果要 获取这种情况下的客户端正式IP,请调用 RemoteAddr方法

func (*Context) GetCookie

func (c *Context) GetCookie(name string) (*http.Cookie, error)

func (*Context) GetInfo

func (c *Context) GetInfo(key string) (interface{}, bool)

func (*Context) GetInfoAsInt

func (c *Context) GetInfoAsInt(key string) int

GetInfoAsInt,获取指定key的值,并转换为int类型,请注意,如果值不存在,则返回0

func (*Context) GetInfoAsString

func (c *Context) GetInfoAsString(key string) string

GetInfoAsString,获取指定key的值,并转换为string类型,请注意,如果值不存在,则返回空字符串

func (*Context) GetLoginId

func (c *Context) GetLoginId() (string, bool)

func (*Context) GetLoginIdAs

func (c *Context) GetLoginIdAs(name string) (string, bool)

func (*Context) GetLoginInfo

func (c *Context) GetLoginInfo() (*LoginContext, bool)

func (*Context) GetLoginInfoAs

func (c *Context) GetLoginInfoAs(name string) (*LoginContext, bool)

func (*Context) GetPre

func (c *Context) GetPre(key string) []reflect.Value

func (*Context) GetRender

func (cx *Context) GetRender() (render string, err error)

GetRender,返回渲染类型,该返回需要判断是否允许相关渲染类型,如果不需要判断,请使用Format函数

func (*Context) IntFormValue

func (c *Context) IntFormValue(key string) int64

func (*Context) Layout

func (c *Context) Layout() string

func (*Context) Method

func (c *Context) Method() string

返回当前的Method,json/html等

func (*Context) NotRendered

func (c *Context) NotRendered() bool

func (*Context) PathParam

func (c *Context) PathParam(key string) string

GetPathParam 获取路径参数

func (*Context) PathParams

func (c *Context) PathParams() map[string]string

PathParams 获取所有路径参数

func (*Context) PathToURL

func (c *Context) PathToURL(path string) (*url.URL, error)

func (*Context) PostForm

func (c *Context) PostForm() url.Values

func (*Context) QueryString

func (c *Context) QueryString(key string) string

func (*Context) RedirectTo

func (c *Context) RedirectTo(url string)

func (*Context) Referer

func (c *Context) Referer() string

func (*Context) RemoteAddr

func (c *Context) RemoteAddr() net.Addr

该方法返回对端连接地址,返回有两种情况,如果头部没有X-Forwarded-For,表示是直接从客户端直接连接的。 此时,返回的addr,Network()方法返回“tcp"。如果头部有X-Forwarded-For,表示是从负载均衡跳转过来的。 此时,返回的addr,Network()方法返回“ip”

func (*Context) RemoteIP

func (c *Context) RemoteIP() (net.IP, error)

func (*Context) RenderAs

func (c *Context) RenderAs(name string)

RenderAs 设置渲染的模型文件,注意和UseRender的区别,需要修改json/html等用UseRender

func (*Context) ReqMethod

func (c *Context) ReqMethod() string

返回用户请求的Method, GET/POST/HEAD等

func (*Context) Respond

func (c *Context) Respond(data interface{})

Respond 向用户返回内容,三种数据会进行特别处理: error类型:标记状态为内部错误 []byte类型:使用raw进行内容渲染,即原样输出,不进行json等格式转化 reader:使用raw进行内容渲染,即原样从输入中读取输出,不进行json等格式转化

func (*Context) RespondError

func (c *Context) RespondError(err error, context ...string)

RespondError 返回错误,如果错误为空,返回成功

func (*Context) RespondField

func (c *Context) RespondField(data interface{}, fields ...string)

func (*Context) RespondOK

func (c *Context) RespondOK()

func (*Context) RespondReader

func (c *Context) RespondReader(reader io.Reader)

func (*Context) RespondStatus

func (c *Context) RespondStatus(status int)

func (*Context) RespondWithRender

func (c *Context) RespondWithRender(data interface{}, render string)

func (*Context) RespondWithStatus

func (c *Context) RespondWithStatus(data interface{}, status int)

func (*Context) SaveFileAt

func (cx *Context) SaveFileAt(path ...string) *filerSaver

func (*Context) SetForceFormat

func (c *Context) SetForceFormat(format, layout string)

func (*Context) SetHeader

func (c *Context) SetHeader(key, value string)

func (*Context) SetLayout

func (c *Context) SetLayout(l string)

func (*Context) SetPathParam

func (c *Context) SetPathParam(key, value string)

SetPathParam 设置路径参数

func (*Context) SetPathParams

func (c *Context) SetPathParams(params map[string]string)

func (*Context) SetSuffix

func (c *Context) SetSuffix(suf string)

func (*Context) ShowHidden

func (c *Context) ShowHidden()

func (*Context) SignedCookie

func (c *Context) SignedCookie(name string) (*http.Cookie, error)

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) SseEnd

func (c *Context) SseEnd(message ...string) (err error)

SseEnd 发送SSE结束信号并关闭连接 发送标准的"[DONE]"信号,这是SSE的通用结束约定

func (*Context) SseSend

func (c *Context) SseSend(message interface{}, action ...string) (err error)

SseSend 发送SSE消息 message: 要发送的消息内容,可以是任意类型,会被转换为字符串 action: 可选的事件类型,如果提供则作为event字段发送

func (*Context) SseSendError

func (c *Context) SseSendError(err error, action ...string) error

SseSendError 发送错误信息的SSE消息(便捷方法)

func (*Context) SseSendJSON

func (c *Context) SseSendJSON(data interface{}, action ...string) error

SseSendJSON 发送JSON格式的SSE消息(便捷方法)

func (*Context) StatusCode

func (c *Context) StatusCode() int

func (*Context) StrFormValue

func (c *Context) StrFormValue(key string) string

func (*Context) String

func (c *Context) String() string

func (*Context) Suffix

func (c *Context) Suffix() string

func (*Context) TemplatePath

func (c *Context) TemplatePath() string

func (*Context) UseRender

func (c *Context) UseRender(render string)

Reset the context renders

func (*Context) UseStandErrPage

func (c *Context) UseStandErrPage() bool

func (*Context) UserAgent

func (c *Context) UserAgent() string

UserAgent 返回用户Agent

func (*Context) Version

func (c *Context) Version() string

Version 返回用户配置的代码版本

func (*Context) WrapError

func (ctx *Context) WrapError(err error, info string) error

func (*Context) Writer

func (c *Context) Writer() http.ResponseWriter

type ControllerNeedInit

type ControllerNeedInit interface {
	Init(*Server)
}

type ControllerNeedInitAndReturnError

type ControllerNeedInitAndReturnError interface {
	Init(*Server) error
}

type CookieLoginInfoStorer

type CookieLoginInfoStorer struct{}

func (*CookieLoginInfoStorer) AddLoginAs

func (c *CookieLoginInfoStorer) AddLoginAs(ctx *Context, lctx *LoginContext) string

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)

func (*CookieLoginInfoStorer) GetToken

func (c *CookieLoginInfoStorer) GetToken(lctx *LoginContext) string

type DataNotWrapper

type DataNotWrapper interface {
	// ShouldNotWrap 是否不应该被包装
	ShouldNotWrap() bool
}

type DbPwdPlugin

type DbPwdPlugin interface {
	SetPwd(origin string) string
}

DbPwdPlugin Change the db connection password

type DefaultRenderSetter

type DefaultRenderSetter interface {
	DefaultRender() string
}

type DelimSetter

type DelimSetter interface {
	SetDelim() [2]string
}

type ErrFuncSetter

type ErrFuncSetter interface {
	RespondError(*Context, error, ...string)
}

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

func Open(path string) (f *File, err error)

Open open file in any location of server, if want to open file relate to www dir, please use OpenInPrivate

func (*File) Close

func (f *File) Close() error

func (*File) GetName

func (f *File) GetName() string

func (*File) GetSize

func (f *File) GetSize() int64

func (*File) OpenInPrivate

func (f *File) OpenInPrivate(s *Server) error

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

func (*File) SaveInPrivate

func (f *File) SaveInPrivate(dir string, s *Server) error

func (*File) SaveInPublic

func (f *File) SaveInPublic(dir string, s *Server) error

func (*File) SaveInTemp

func (f *File) SaveInTemp(dir string, s *Server) error

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

type Fn

type Fn struct {
	Name string
	Fn   interface{}
}

type FormFillFn

type FormFillFn func(content string) (interface{}, error)

type FormRequestDecoder

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

a form-enc decoder for request body

func NewFormRequestDecoder

func NewFormRequestDecoder() *FormRequestDecoder

func (*FormRequestDecoder) Unmarshal

func (d *FormRequestDecoder) Unmarshal(cx *Context, v interface{}, autofill bool) error

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 JsonRenderCodeSetter

type JsonRenderCodeSetter interface {
	RespondJsonWithSuccessCode() int
}

type JsonRenderSuccessMsgSetter

type JsonRenderSuccessMsgSetter interface {
	RespondJsonWithSuccessMsg() string
}

type JsonRequestDecoder

type JsonRequestDecoder struct{}

a JSON decoder for request body (just a wrapper to json.Unmarshal)

func (*JsonRequestDecoder) Unmarshal

func (d *JsonRequestDecoder) Unmarshal(cx *Context, v interface{}, autofill bool) (err error)

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 Layout

type Layout byte

type LocalSaver

type LocalSaver struct {
}

func (*LocalSaver) Delete

func (l *LocalSaver) Delete(path string, force bool) error

func (*LocalSaver) Save

func (l *LocalSaver) Save(path string, f io.Reader) error

type LoginContext

type LoginContext struct {
	Name     string
	Id       string
	Deadline *time.Time
	Attrs    map[string]interface{}
}

func (*LoginContext) HasAttr

func (l *LoginContext) HasAttr(key string, content interface{}) bool

func (*LoginContext) SetDeadline

func (l *LoginContext) SetDeadline(t time.Time)

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) string
	GetLoginIdAs(ctx *Context, key string) (*LoginContext, error)
	DeleteLoginAs(ctx *Context, key string) error
	GetToken(lctx *LoginContext) string
}

type MultiFormFillFn

type MultiFormFillFn func(ctx *Context, id string) (interface{}, error)

type MultiFormRequestDecoder

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

a form-enc decoder for request body

func NewMultiFormRequestDecoder

func NewMultiFormRequestDecoder() *MultiFormRequestDecoder

func (*MultiFormRequestDecoder) Unmarshal

func (d *MultiFormRequestDecoder) Unmarshal(cx *Context, v interface{}, autofill bool) error

type NewPlugin

type NewPlugin interface {
	AddCfgAndInit(server *Server) error
}

type OkFuncSetter

type OkFuncSetter interface {
	RespendOk(*Context)
}

type Option

type Option struct {
	DB string
}

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 Render

type Render byte

type RequestDecoder

type RequestDecoder interface {
	Unmarshal(cx *Context, v interface{}, autofill bool) error
}

types that impliment RequestDecoder can unmarshal the request body into an apropriate type/struct

type Response

type Response struct {
}

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 Route

type Route byte

type Saver

type Saver interface {
	Save(fullpath string, f io.Reader) error
	Delete(fullpath string, force bool) error
}

type Server

type Server struct {
	ConfigFile string

	Config config.Config

	Renders map[string]render.Render

	Name string

	DB *gorm.DB
	// contains filtered or unexported fields
}

Server 服务器类型

var DefaultServer *Server

func Organize

func Organize(name string, plugins ...interface{}) *Server

func (*Server) AddConfig

func (s *Server) AddConfig(name string, obj interface{}, tagName ...string) error

func (*Server) AddFillForTypeInForm

func (s *Server) AddFillForTypeInForm(typ string, fn FormFillFn)

func (*Server) AddFillForTypeInMultiForm

func (s *Server) AddFillForTypeInMultiForm(typ string, fn MultiFormFillFn)

func (*Server) AddFunc

func (s *Server) AddFunc(name string, fn interface{})

func (*Server) AddModel

func (s *Server) AddModel(models interface{}, syncs ...bool)

func (*Server) ControlBy

func (s *Server) ControlBy(controller interface{})

ControlBy 函数用于将控制器添加到服务器中

参数: controller - 需要添加到服务器中的控制器接口

函数逻辑: 1. 通过 wrapController 函数将控制器转换为配置信息 2. 如果控制器实现了 ControllerNeedInit 接口,则将其添加到初始化控制器列表中 3. 如果控制器实现了 ControllerNeedInitAndReturnError 接口,则将其添加到新的初始化控制器列表中 4. 将配置信息添加到路由表中

func (*Server) Debug

func (s *Server) Debug(fn func())

Debug 当服务器环境为调试环境时,执行相应的匿名函数,用于编写调试环境专用的代码块

func (*Server) DelFileInPrivate

func (s *Server) DelFileInPrivate(path string, force ...bool) error

func (*Server) DelFileInPublic

func (s *Server) DelFileInPublic(path string, force ...bool) error

func (*Server) Env

func (s *Server) Env() string

func (*Server) GetDefaultRender

func (s *Server) GetDefaultRender() string

func (*Server) GetDelims

func (s *Server) GetDelims() []string

func (*Server) GetPlugin

func (s *Server) GetPlugin(key string) NewPlugin

GetPlugin 获得对应名称的插件

func (*Server) GetServerPathByCtrl

func (s *Server) GetServerPathByCtrl(ctrl interface{}) []string

func (*Server) Hash

func (s *Server) Hash(str string) string

Hash 获得一个字符串的加密版本

func (*Server) KV

func (s *Server) KV(name string) Kv

func (*Server) Organize

func (s *Server) Organize(name string, plugins []interface{})

Organize 进行服务器环境的初始化配置,初始化所有plugin,对于plugin的所有操作,在Organize之后都可以视为已经初始化

func (*Server) Pre

func (s *Server) Pre(fn interface{}, conds ...string)

func (*Server) PublicDir

func (s *Server) PublicDir() string

PublicDir 获得服务器对应的公共文件夹的地址

func (*Server) Run

func (s *Server) Run() error

Run 运营一个服务器

func (*Server) SaveInPrivate

func (s *Server) SaveInPrivate(path string, f io.Reader) error

将文件保存在私有目录,不可以使用http访问到

func (*Server) SaveInPublic

func (s *Server) SaveInPublic(path string, f io.Reader) error

将文件保存在公开目录,可以使用http访问到

func (*Server) ServeFile

func (s *Server) ServeFile(w http.ResponseWriter, r *http.Request, file string)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) SetConfigSuffix

func (s *Server) SetConfigSuffix(suffix string)

func (*Server) SetDefaultError

func (s *Server) SetDefaultError(fn func(*Context, error, ...string))

func (*Server) SetDefaultOk

func (s *Server) SetDefaultOk(fn func(*Context))

func (*Server) WwwRoot

func (s *Server) WwwRoot() string

type SilenceUrlSetter

type SilenceUrlSetter interface {
	SetSilenceUrls() map[string]bool
}

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 SseOption

type SseOption func(*Context)

func SseWithKeepAlive

func SseWithKeepAlive(timeout int) SseOption

type StandardErrorOrData

type StandardErrorOrData struct {
	Data interface{} `json:"data,omitempty"`
	Msg  string      `json:"msg"`
	Code int         `json:"code"`
}

func (*StandardErrorOrData) Error

func (s *StandardErrorOrData) Error() string

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 XmlRequestDecoder

type XmlRequestDecoder struct{}

an XML decoder for request body

func (*XmlRequestDecoder) Unmarshal

func (d *XmlRequestDecoder) Unmarshal(cx *Context, v interface{}, autofill bool) (err error)

type YamlConfiger

type YamlConfiger struct {
}

func (*YamlConfiger) GetConfigSource

func (c *YamlConfiger) GetConfigSource(s *Server) (io.Reader, error)

Directories

Path Synopsis
internal
oss

Jump to

Keyboard shortcuts

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