separate type define (#975)

This commit is contained in:
田欧 2017-07-05 15:47:36 +08:00 committed by Bo-Yi Wu
parent 22fc0284e3
commit d535fcd598
6 changed files with 125 additions and 133 deletions

14
auth.go
View File

@ -13,15 +13,15 @@ import (
// AuthUserKey is the cookie name for user credential in basic auth
const AuthUserKey = "user"
type (
// Accounts defines a key/value for user/pass list of authorized logins
Accounts map[string]string
authPair struct {
// Accounts defines a key/value for user/pass list of authorized logins
type Accounts map[string]string
type authPair struct {
Value string
User string
}
authPairs []authPair
)
}
type authPairs []authPair
func (a authPairs) searchCredential(authValue string) (string, bool) {
if len(authValue) == 0 {

View File

@ -23,15 +23,13 @@ const (
ErrorTypeNu = 2
)
type (
Error struct {
type Error struct {
Err error
Type ErrorType
Meta interface{}
}
}
errorMsgs []*Error
)
type errorMsgs []*Error
var _ error = &Error{}

11
fs.go
View File

@ -9,14 +9,13 @@ import (
"os"
)
type (
onlyfilesFS struct {
type onlyfilesFS struct {
fs http.FileSystem
}
neuteredReaddirFile struct {
}
type neuteredReaddirFile struct {
http.File
}
)
}
// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
// in router.Static().

17
gin.go
View File

@ -33,17 +33,17 @@ func (c HandlersChain) Last() HandlerFunc {
return nil
}
type (
RoutesInfo []RouteInfo
RouteInfo struct {
type RouteInfo struct {
Method string
Path string
Handler string
}
}
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
// Create an instance of Engine, by using New() or Default()
Engine struct {
type RoutesInfo []RouteInfo
// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
// Create an instance of Engine, by using New() or Default()
type Engine struct {
RouterGroup
delims render.Delims
HTMLRender render.HTMLRender
@ -92,8 +92,7 @@ type (
// If UseRawPath is false (by default), the UnescapePathValues effectively is true,
// as url.Path gonna be used, which is already unescaped.
UnescapePathValues bool
}
)
}
var _ IRouter = &Engine{}

View File

@ -16,8 +16,7 @@ const (
defaultStatus = 200
)
type (
ResponseWriter interface {
type ResponseWriter interface {
http.ResponseWriter
http.Hijacker
http.Flusher
@ -38,14 +37,13 @@ type (
// Forces to write the http header (status code + headers).
WriteHeaderNow()
}
}
responseWriter struct {
type responseWriter struct {
http.ResponseWriter
size int
status int
}
)
}
var _ ResponseWriter = &responseWriter{}

View File

@ -11,13 +11,12 @@ import (
"strings"
)
type (
IRouter interface {
type IRouter interface {
IRoutes
Group(string, ...HandlerFunc) *RouterGroup
}
}
IRoutes interface {
type IRoutes interface {
Use(...HandlerFunc) IRoutes
Handle(string, string, ...HandlerFunc) IRoutes
@ -33,17 +32,16 @@ type (
StaticFile(string, string) IRoutes
Static(string, string) IRoutes
StaticFS(string, http.FileSystem) IRoutes
}
}
// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
// and an array of handlers (middleware)
RouterGroup struct {
// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
// and an array of handlers (middleware)
type RouterGroup struct {
Handlers HandlersChain
basePath string
engine *Engine
root bool
}
)
}
var _ IRouter = &RouterGroup{}